{"format":"brushup-mindmap-v1","id":"ds-07-search","title":"查找【王道】","structure":"logic-right","theme":"auto","root":{"id":"ad49c60927aa2aee1f9729404d","topic":"第七章 查找","expanded":true,"children":[{"id":"a52aa17d36d8c5ac18cf1965fc","topic":"查找的基本概念","expanded":true,"children":[{"id":"d0ea73d6-83c3-4070-b388-36c95f6b9eb5","topic":"在哪里找？","expanded":true,"children":[{"id":"1127ed75-b27f-4cf2-83d5-0610a4278eae","topic":"查找表：是由同一类型的数据元素（或记录）构成的集合（数据元素之间关系松散，应用灵活方便）","expanded":true}]},{"id":"6a230629-04aa-4a8c-8016-18aaf8c27f40","topic":"什么是查找？","expanded":true,"style":{"borderColor":"#FF9F00","branchColor":"#EA8ABA"},"children":[{"id":"db64512e-5156-4ca5-845a-fad6825286c5","topic":"查找：根据给定值，在查找表中确定一个其关键字等于给定值的数据元素（或记录）（查找成功/查找不成功）","expanded":true},{"id":"8cd610ba-3ba9-42a1-afa1-1d028da022d0","topic":"关键字","expanded":true,"children":[{"id":"1e9bcf58-a2c0-4b1d-91ae-1c3ee347caaf","topic":"用来标识一个数据元素（或记录）的某个数据项的值","expanded":true},{"id":"64690fb9-7c2c-4c56-a9fa-24f08037564a","topic":"主关键字：可唯一标识一个记录的关键字","expanded":true},{"id":"4408d03e-4ca5-4e96-aa4a-6bdad89c1bcd","topic":"次关键字：用以识别若干记录的关键字","expanded":true}]}]},{"id":"e8d8e954-382a-4af4-90c3-b772468a6977","topic":"查找表咋么分类？","expanded":true,"children":[{"id":"51a02c3e-9a3a-4b07-9383-f856ff7bee0c","topic":"静态查找表：仅作查询（检索）操作的查找表","expanded":true,"children":[{"id":"dec58a04-37e1-4194-bba9-df0aa59b1cf8","topic":"查询：某个“特定”数据元素是否在查找表中","expanded":true},{"id":"856f244b-0568-4a31-b1aa-efa62ac675c0","topic":"检索：某个“特定”数据元素的各种属性","expanded":true}]},{"id":"8e7e47fd-cbed-455b-8718-b7defb11ef57","topic":"动态查找表：作插入和删除操作的查找表","expanded":true,"children":[{"id":"7786599e-63ca-4316-b0b4-b79b6afff60d","topic":"在查找表中查找，若查询结果不在查找表中，则插入一个数据元素","expanded":true},{"id":"5d2ddfe1-cdcf-4bfc-9873-aefafea72bcb","topic":"从查找表中删除其查询结果在表中的某个数据元素","expanded":true}]}]},{"id":"cd8e206a-4157-4e5c-a740-58f0de3ed3c6","topic":"如何评价查找算法？","expanded":true,"style":{"borderColor":"#FF9F00","branchColor":"#EA8ABA"},"children":[{"id":"7674df8e-1ee8-4c1e-a23f-f216a1571f5a","topic":"平均查找长度ASL","expanded":true,"children":[{"id":"cffca2fc-68a6-4f43-9684-80fc25d7c029","topic":"","expanded":true,"children":[{"id":"cb0371de-76eb-490c-9aae-7f0b4d8b886b","topic":"n：记录个数；pi：查找第i个记录的概率（通常为1/n）；ci：找到第i个记录所需的比较次数","expanded":true}],"formula":{"tex":"ASL = \\sum_{i=1}^{n} p_i c_i \\quad \\text{（关键字比较次数的期望值）}","displayMode":true,"mathml":"<span class=\"katex\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics><mrow><mi>A</mi><mi>S</mi><mi>L</mi><mo>=</mo><munderover><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>n</mi></munderover><msub><mi>p</mi><mi>i</mi></msub><msub><mi>c</mi><mi>i</mi></msub><mspace width=\"1em\"/><mtext>（关键字比较次数的期望值）</mtext></mrow><annotation encoding=\"application/x-tex\">ASL = \\sum_{i=1}^{n} p_i c_i \\quad \\text{（关键字比较次数的期望值）}</annotation></semantics></math></span>"}}]}]},{"id":"10120d8d-5ce7-419a-8611-bc164641fce3","topic":"查找过程中研究什么？","expanded":true,"children":[{"id":"8473ebfc-0cdf-42f2-afda-aef7d7581ba2","topic":"研究查找表的各种组织方法及其查找过程的实施（构造查找表时，人为添加约束关系，并设计与之匹配的查找方法，从而提高查找表的查询效率）","expanded":true}]}]},{"id":"689a2800c0c8d941a2878b5c9f","topic":"线性表的查找","expanded":true,"style":{"borderColor":"#E32C2D"},"children":[{"id":"a3dcca0b-eab3-491b-9333-fe7eb0c09e68","topic":"顺序查找（线性查找）","expanded":true,"children":[{"id":"bca9adbf-2080-4739-8dd2-46a5ee2988d2","topic":"概念","expanded":true,"children":[{"id":"f70e7baf-9c91-4238-a54c-4e38ffc240a4","topic":"顺序查找顺序表或线性链表表示的静态查找表","expanded":true,"children":[{"id":"5c7f64f4-82a1-4c24-8a4a-5eb194bffd0a","topic":"表内元素无序","expanded":true}]}]},{"id":"566c63ee-7771-43fb-96f5-ef9adc49d2e0","topic":"过程","expanded":true,"children":[{"id":"f3588733-fd97-45b3-a157-245885805481","topic":"从线性表的一端开始，逐个检查关键字是否满足条件","expanded":true},{"id":"4cc1901b-3dba-4a64-9178-2676b89b2def","topic":"若满足则查找成功，返回元素位置","expanded":true,"children":[{"id":"4f722dac-d083-40cd-a017-ad0cf6737f33","topic":"若已经查到表的另一端，且还没有找到符合条件的元素，则返回查找失败的信息","expanded":true}]}]},{"id":"edb11801-9029-41d0-b9c5-25d2e32de387","topic":"优化","expanded":true,"children":[{"id":"eb0f1f15-17de-4438-8d97-6695bd591b12","topic":"哨兵","expanded":true,"children":[{"id":"b7b5f434-22bc-4d0b-afbb-2ccc9dbfc3d4","topic":"将待查关键字存入表头，从后向前比较，可免去查找过程中每步都要检查是否查找完毕，效率可提高一倍","expanded":true}]},{"id":"6cdc467a-68c0-4352-ad3e-41d4ee3fa033","topic":"按查找频率高低存储","expanded":true,"children":[{"id":"54ae38d8-9197-4c7b-af35-37027de8fa7c","topic":"若无法测定，按概率动态调整记录顺序（访问频度域）","expanded":true}]}]},{"id":"16a7c6f8-61bc-4837-abbd-99c6652f8113","topic":"平均查找长度","expanded":true,"children":[{"id":"e1547ce0-601a-4c4e-aa80-33c26c30e438","topic":"成功（Pi=1/n）","expanded":true,"children":[{"id":"e034c912-166f-4804-9c1d-75ac542f872f","topic":"","expanded":true,"formula":{"tex":"ASL_{\\text{成功}} = \\frac{1 + 2 + 3 + \\dots + n}{n} = \\frac{n + 1}{2}","displayMode":true,"mathml":"<span class=\"katex\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics><mrow><mi>A</mi><mi>S</mi><msub><mi>L</mi><mtext>成功</mtext></msub><mo>=</mo><mfrac><mrow><mn>1</mn><mo>+</mo><mn>2</mn><mo>+</mo><mn>3</mn><mo>+</mo><mo>⋯</mo><mo>+</mo><mi>n</mi></mrow><mi>n</mi></mfrac><mo>=</mo><mfrac><mrow><mi>n</mi><mo>+</mo><mn>1</mn></mrow><mn>2</mn></mfrac></mrow><annotation encoding=\"application/x-tex\">ASL_{\\text{成功}} = \\frac{1 + 2 + 3 + \\dots + n}{n} = \\frac{n + 1}{2}</annotation></semantics></math></span>"}}]},{"id":"b0ad5ccf-9100-465e-af57-5f18eea8d7d8","topic":"失败（Pi=1/n）","expanded":true,"children":[{"id":"c416efff-3109-461f-8664-fc1d16fb28c2","topic":"","expanded":true,"formula":{"tex":"ASL_{\\text{失败}} = n + 1","displayMode":true,"mathml":"<span class=\"katex\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics><mrow><mi>A</mi><mi>S</mi><msub><mi>L</mi><mtext>失败</mtext></msub><mo>=</mo><mi>n</mi><mo>+</mo><mn>1</mn></mrow><annotation encoding=\"application/x-tex\">ASL_{\\text{失败}} = n + 1</annotation></semantics></math></span>"}}]}]}]},{"id":"0cec4fdd-ac0e-4a6f-a89d-cbdfec1f4aba","topic":"折半查找（二分/对分查找）","expanded":true,"style":{"branchColor":"#15831C"},"children":[{"id":"4a02a1c5-946f-489d-9d0d-25c53bea1d03","topic":"概念","expanded":true,"children":[{"id":"b279580d-0e5a-4ced-92f1-53c999556863","topic":"每次将待查记录所在区间缩小一半","expanded":true,"children":[{"id":"19f37a7c-038b-4afa-bf78-7aaedf3b4bc3","topic":"有序的顺序表","expanded":true}]}]},{"id":"0f16cb1e-5e9b-4cf8-ac66-fa6497e9cfc7","topic":"Binary_Search 代码实现","expanded":true,"children":[{"id":"51ba28c8-f254-449e-828e-0ccb005fff6a","topic":"在[low, high]之间找目标关键字，将给定key值与表中中间位置mid比较，若相等则查找成功","expanded":true},{"id":"4b4291f4-65a6-4ff9-a9ff-37945c8107f7","topic":"不等，则根据mid所指元素与key值大小比较，调整low或high，缩小边界范围，不断重复","expanded":true},{"id":"5d33d4d5-bbf1-4544-81ee-065c70b04828","topic":"若low>high，则查找失败","expanded":true}],"code":{"lang":"c","code":"//折半查找\nint Binary_Search(SSTable L,ElemType key){\n    int low=0,high=L.TableLen-1,mid;\n    while(low<=high){\n        mid=(low+high)/2;               //取中间位置\n        if(L.elem[mid]==key)\n            return  mid;                //查找成功则返回所在位置\n        else if(L.elem[mid]>key)\n            high=mid-1;                 //从前半部分继续查找\n        else\n            low=mid+1;                  //从后半部分继续查找\n    }\n    return  -1;                         //查找失败，返回-1\n}","title":"Binary_Search","tokens":[[{"text":"//折半查找","darkColor":"#908B7E"}],[{"text":"int","darkColor":"#74CBC4"},{"text":" ","darkColor":"#DEDBD2"},{"text":"Binary_Search","darkColor":"#6EC0DF"},{"text":"(","darkColor":"#BAB5A8"},{"text":"SSTable ","darkColor":"#DEDBD2"},{"text":"L","darkColor":"#D5C5AA"},{"text":",","darkColor":"#BAB5A8"},{"text":"ElemType ","darkColor":"#DEDBD2"},{"text":"key","darkColor":"#D5C5AA"},{"text":"){","darkColor":"#BAB5A8"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"int","darkColor":"#74CBC4"},{"text":" low","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":"0","darkColor":"#E2B159"},{"text":",","darkColor":"#BAB5A8"},{"text":"high","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":"L","darkColor":"#EEECE6"},{"text":".","darkColor":"#BAB5A8"},{"text":"TableLen","darkColor":"#EEECE6"},{"text":"-","darkColor":"#BAB5A8"},{"text":"1","darkColor":"#E2B159"},{"text":",","darkColor":"#BAB5A8"},{"text":"mid","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"while","darkColor":"#8EA4E2"},{"text":"(","darkColor":"#BAB5A8"},{"text":"low","darkColor":"#DEDBD2"},{"text":"<=","darkColor":"#BAB5A8"},{"text":"high","darkColor":"#DEDBD2"},{"text":"){","darkColor":"#BAB5A8"}],[{"text":"        mid","darkColor":"#DEDBD2"},{"text":"=(","darkColor":"#BAB5A8"},{"text":"low","darkColor":"#DEDBD2"},{"text":"+","darkColor":"#BAB5A8"},{"text":"high","darkColor":"#DEDBD2"},{"text":")/","darkColor":"#BAB5A8"},{"text":"2","darkColor":"#E2B159"},{"text":";","darkColor":"#BAB5A8"},{"text":"               //取中间位置","darkColor":"#908B7E"}],[{"text":"        ","darkColor":"#DEDBD2"},{"text":"if","darkColor":"#8EA4E2"},{"text":"(","darkColor":"#BAB5A8"},{"text":"L","darkColor":"#EEECE6"},{"text":".","darkColor":"#BAB5A8"},{"text":"elem","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"mid","darkColor":"#DEDBD2"},{"text":"]==","darkColor":"#BAB5A8"},{"text":"key","darkColor":"#DEDBD2"},{"text":")","darkColor":"#BAB5A8"}],[{"text":"            ","darkColor":"#DEDBD2"},{"text":"return","darkColor":"#8EA4E2"},{"text":"  mid","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"},{"text":"                //查找成功则返回所在位置","darkColor":"#908B7E"}],[{"text":"        ","darkColor":"#DEDBD2"},{"text":"else","darkColor":"#8EA4E2"},{"text":" ","darkColor":"#DEDBD2"},{"text":"if","darkColor":"#8EA4E2"},{"text":"(","darkColor":"#BAB5A8"},{"text":"L","darkColor":"#EEECE6"},{"text":".","darkColor":"#BAB5A8"},{"text":"elem","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"mid","darkColor":"#DEDBD2"},{"text":"]>","darkColor":"#BAB5A8"},{"text":"key","darkColor":"#DEDBD2"},{"text":")","darkColor":"#BAB5A8"}],[{"text":"            high","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":"mid","darkColor":"#DEDBD2"},{"text":"-","darkColor":"#BAB5A8"},{"text":"1","darkColor":"#E2B159"},{"text":";","darkColor":"#BAB5A8"},{"text":"                 //从前半部分继续查找","darkColor":"#908B7E"}],[{"text":"        ","darkColor":"#DEDBD2"},{"text":"else","darkColor":"#8EA4E2"}],[{"text":"            low","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":"mid","darkColor":"#DEDBD2"},{"text":"+","darkColor":"#BAB5A8"},{"text":"1","darkColor":"#E2B159"},{"text":";","darkColor":"#BAB5A8"},{"text":"                  //从后半部分继续查找","darkColor":"#908B7E"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"}","darkColor":"#BAB5A8"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"return","darkColor":"#8EA4E2"},{"text":"  ","darkColor":"#DEDBD2"},{"text":"-","darkColor":"#BAB5A8"},{"text":"1","darkColor":"#E2B159"},{"text":";","darkColor":"#BAB5A8"},{"text":"                         //查找失败，返回-1","darkColor":"#908B7E"}],[{"text":"}","darkColor":"#BAB5A8"}]]}},{"id":"63b0b29d-5a91-4b42-98d4-694359bb24f2","topic":"判定树","expanded":true,"children":[{"id":"7df44588-3ad8-4f43-a6e1-21eaf1c36c57","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-43080ce8f324fb.png","width":560.81,"height":205.46},"children":[{"id":"ab4b36ec-0c60-4a1f-9751-104a807617e7","topic":"圆形结点为记录，值为关键字；叶结点表示查找不成功的情况","expanded":true},{"id":"a30a23d5-40fe-4412-885b-a7647d770aa6","topic":"特性","expanded":true,"children":[{"id":"f2a001de-e427-4178-bdca-95504ed21021","topic":"判定树是平衡的二叉排序树（只有最下面一层不满）","expanded":true,"style":{"borderColor":"#EB4D3D"}},{"id":"45bc2b31-de5c-4d06-a766-5a9a460a77cd","topic":"若查找表有n个关键字，则失败结点有n+1个","expanded":true},{"id":"45be728a-5965-4454-8c69-62d18552fc94","topic":"树高h = ⌈log2(n+1)⌉（不包含失败结点）","expanded":true,"style":{"borderColor":"#EB4D3D"}}]},{"id":"a0512fbe-a259-457d-a8cb-7af5782fedbd","topic":"查找成功平均长度","expanded":true,"children":[{"id":"84bfe656-96c0-4c8f-a216-e6db3029d2fb","topic":"","expanded":true,"formula":{"tex":"\\begin{aligned} \\mathrm{ASL} &= \\frac{1}{n}\\sum_{i=1}^{n} l_i = \\frac{1}{n}(1\\times 1 + 2\\times 2 + \\cdots + h\\times 2^{h-1}) \\\\ &= \\frac{n+1}{n}\\log_2(n+1) - 1 \\approx \\log_2(n+1) - 1 \\end{aligned}","displayMode":true,"mathml":"<span class=\"katex\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics><mtable rowspacing=\"0.25em\" columnalign=\"right left\" columnspacing=\"0em\"><mtr><mtd><mstyle scriptlevel=\"0\" displaystyle=\"true\"><mrow><mi mathvariant=\"normal\">A</mi><mi mathvariant=\"normal\">S</mi><mi mathvariant=\"normal\">L</mi></mrow></mstyle></mtd><mtd><mstyle scriptlevel=\"0\" displaystyle=\"true\"><mrow><mrow></mrow><mo>=</mo><mfrac><mn>1</mn><mi>n</mi></mfrac><munderover><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>n</mi></munderover><msub><mi>l</mi><mi>i</mi></msub><mo>=</mo><mfrac><mn>1</mn><mi>n</mi></mfrac><mo stretchy=\"false\">(</mo><mn>1</mn><mo>×</mo><mn>1</mn><mo>+</mo><mn>2</mn><mo>×</mo><mn>2</mn><mo>+</mo><mo>⋯</mo><mo>+</mo><mi>h</mi><mo>×</mo><msup><mn>2</mn><mrow><mi>h</mi><mo>−</mo><mn>1</mn></mrow></msup><mo stretchy=\"false\">)</mo></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel=\"0\" displaystyle=\"true\"><mrow></mrow></mstyle></mtd><mtd><mstyle scriptlevel=\"0\" displaystyle=\"true\"><mrow><mrow></mrow><mo>=</mo><mfrac><mrow><mi>n</mi><mo>+</mo><mn>1</mn></mrow><mi>n</mi></mfrac><msub><mrow><mi>log</mi><mo>⁡</mo></mrow><mn>2</mn></msub><mo stretchy=\"false\">(</mo><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy=\"false\">)</mo><mo>−</mo><mn>1</mn><mo>≈</mo><msub><mrow><mi>log</mi><mo>⁡</mo></mrow><mn>2</mn></msub><mo stretchy=\"false\">(</mo><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy=\"false\">)</mo><mo>−</mo><mn>1</mn></mrow></mstyle></mtd></mtr></mtable><annotation encoding=\"application/x-tex\">\\begin{aligned} \\mathrm{ASL} &amp;= \\frac{1}{n}\\sum_{i=1}^{n} l_i = \\frac{1}{n}(1\\times 1 + 2\\times 2 + \\cdots + h\\times 2^{h-1}) \\\\ &amp;= \\frac{n+1}{n}\\log_2(n+1) - 1 \\approx \\log_2(n+1) - 1 \\end{aligned}</annotation></semantics></math></span>"}},{"id":"d8b999b6-35eb-4427-bb60-f5a9fd9444e3","topic":"ASL <= h","expanded":true}]},{"id":"ef85d432-ccb3-46e4-b097-d35739f0808d","topic":"时间复杂度：O(log2n)","expanded":true}]}]},{"id":"f23e322a-9690-45f5-8a25-3e8caf9a4a85","topic":"仅适合于顺序存储结构，不适合于链式存储结构，且关键字有序","expanded":true}]},{"id":"8c3398db-68eb-4e68-b20a-999588b04ecc","topic":"分块查找（索引顺序查找）","expanded":true,"children":[{"id":"aa86da02-d3be-456b-bc64-d9e90a814e4d","topic":"概念","expanded":true,"children":[{"id":"a5a754c4-a6a0-4c7b-919b-76d922d3694f","topic":"吸取了顺序查找和折半查找的优点，既有动态结构（若为动态查找表，优先使用链式存储），又适用于快速查找","expanded":true}]},{"id":"5cae05c8-5cc6-40a6-a46a-53f4469c551c","topic":"过程","expanded":true,"children":[{"id":"92590982-57ca-49e8-8b9a-716cf00235ff","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-59b3d50ea91da2.png","width":1586,"height":676},"children":[{"id":"9fc1426b-35e8-4c5a-8f1b-def559a1f877","topic":"将查找表分为若干子块，块内的元素可以无序，但块间有序，一个块的最大关键字小于下一个块中所有记录的关键字","expanded":true,"style":{"borderColor":"#EB4D3D"}},{"id":"c49ad8e7-7132-4d8a-8f9e-549778e30d9a","topic":"再建立一个索引表，索引表中的每个元素含有各块的最大关键字和各块中第一个元素的地址，索引表按关键字排序","expanded":true},{"id":"63ceacf2-6236-4099-9f92-440f05426b6d","topic":"查找过程：在索引表中确定记录所在块，在块内顺序查找","expanded":true}]}]},{"id":"e4c81c83-27d2-46c2-a195-f29a6514d61f","topic":"查找成功长度","expanded":true,"children":[{"id":"ad143e72-736d-4aab-8a99-a3a77090a1c4","topic":"将长度为n的查找表均匀地分为b块，每块有s个记录","expanded":true,"children":[{"id":"21505f5a-7e08-4e70-ad22-aeb0d7bc7d7b","topic":"ASL = Lb（对索引表查找的ASL） + Ls（对块内查找的ASL）","expanded":true}]},{"id":"57586962-8de9-4b3d-aad4-146fb3591035","topic":"若块内和索引表都用顺序查找，则按顺序查找公式","expanded":true,"children":[{"id":"ae66dd65-2ba3-46e8-be27-a04b6a4bcaef","topic":"ASL = Lb + Ls = (b+1)/2 + (s+1)/2","expanded":true,"style":{"borderColor":"#EB4D3D"},"children":[{"id":"305e1071-f2cb-42dd-9262-c7249da2549e","topic":"可根据b和s的关系化简，若用折半查找，则用折半的公式替换h = ⌈log2(n+1)⌉","expanded":true}]}]}]}]},{"id":"4a76ace3-2deb-441d-ba8c-80cec2784270","topic":"比较","expanded":true,"style":{"branchColor":"#15831C"},"children":[{"id":"8c97b73b-3be8-45a7-badd-394783139ae6","topic":"对比维度","expanded":true,"children":[{"id":"26ddb9a5-afe4-4efe-b834-3b1df7dea807","topic":"顺序查找","expanded":true,"children":[{"id":"3d52c8e2-d7eb-40bc-9f00-7d12a3928fb6","topic":"折半查找","expanded":true,"children":[{"id":"32e024cf-ec40-4bc8-828d-df8ea0031d4f","topic":"分块查找","expanded":true}]}]}]},{"id":"58fc7477-253b-4761-81a1-1193fcb6b808","topic":"ASL","expanded":true,"children":[{"id":"20b53e7e-1b0f-4b48-93a5-1e55cae5d5a4","topic":"最大","expanded":true,"children":[{"id":"5c3bc9c7-39d8-4d52-a0dd-6190f57e2b22","topic":"最小","expanded":true,"children":[{"id":"dda025c0-56cd-4f1f-ad8a-df80b62ecbb5","topic":"中间","expanded":true}]}]}]},{"id":"a4e9e4a2-ccf2-4288-b66a-7325bde0fc7c","topic":"表结构","expanded":true,"children":[{"id":"858ed378-55b1-4b6f-866a-5930f6a6bf91","topic":"有序/无序表","expanded":true,"children":[{"id":"7c000344-4e81-4178-b540-3299687769df","topic":"有序表","expanded":true,"children":[{"id":"2939926f-21c5-4e9d-9c9e-d9b9a980cd05","topic":"分块有序","expanded":true}]}]}]},{"id":"06d7556b-2229-4e75-9c46-8526d530931a","topic":"存储结构","expanded":true,"children":[{"id":"885c4da3-e827-42cd-913e-f4f07ed61fb4","topic":"顺序/线性链表","expanded":true,"children":[{"id":"d8c2cefa-43db-4559-8e7b-1f2d46356761","topic":"顺序表","expanded":true,"children":[{"id":"af71957e-fa76-425a-97d5-bc9caa631f2d","topic":"顺序/线性链表","expanded":true}]}]}]}]}]},{"id":"116a0a5ab2c992100b4188ee7b","topic":"树表的查找","expanded":true,"style":{"borderColor":"#E32C2D"},"children":[{"id":"722d14e0-26d2-4ba9-aded-1b1d4a3a2218","topic":"当表插入、删除操作频繁时，为维护表的有序性，需要移动很多记录，改用动态查找表（几种特殊的树）","expanded":true},{"id":"f1eacc0e-90ff-4e25-b4dc-b55151ccebbc","topic":"二叉排序树 BST","expanded":true,"style":{"branchColor":"#BA69C8"},"children":[{"id":"5ddb769b-71ef-44fe-b730-d5e810b19e14","topic":"二叉排序树的定义","expanded":true,"children":[{"id":"1bc9a0ae-2890-4d51-9698-0e5eee34780f","topic":"特性","expanded":true,"children":[{"id":"6c358e61-239c-4131-b238-1d8b2cd34100","topic":"左子树结点值（若左子树非空） < 根结点值 < 右子树结点值（若右子树非空）","expanded":true},{"id":"5a070f52-a735-467c-b342-687f67dc733b","topic":"其左右子树本树又各是一棵二叉排序树","expanded":true}]},{"id":"667d5f83-ace8-4a4b-94dc-79ba9a5f1cc1","topic":"性质","expanded":true,"children":[{"id":"6f778198-870c-4269-beb6-b17be16ceb71","topic":"中序遍历非空的二叉排序树所得到的数据元素序列是一个按关键字排序的递增有序序列","expanded":true}]}]},{"id":"efde1c85-20a2-4866-bf0a-469aa1f5fb53","topic":"二叉排序树的查找","expanded":true,"children":[{"id":"2641f91f-9275-4a28-a34d-6927b67ebc96","topic":"从根结点开始，沿某分支逐层向下比较的过程，若二叉排序树非空，先将给定值与根结点关键字比较","expanded":true,"children":[{"id":"d51dca9c-0c7e-4f62-9c91-577c209edc09","topic":"若相等则成功","expanded":true},{"id":"0ba43607-791f-45bb-829e-bb96e86e5e61","topic":"若小于根结点关键字，则在左子树上查找；若大于根结点关键字，则在右子树上查找（可递归实现）","expanded":true}]}]},{"id":"46265ae5-4695-4690-bfac-437d8246d81b","topic":"二叉排序树的插入","expanded":true,"children":[{"id":"957c2489-bc32-44e1-a79c-ff10dff0bf87","topic":"过程","expanded":true,"children":[{"id":"a47cf2b4-b90d-4431-b80c-74d4d6de4767","topic":"若关键字小于根结点值，插入左子树","expanded":true},{"id":"3980eb81-938a-49ce-b43c-0b256307990e","topic":"若关键字大于根结点值，插入右子树","expanded":true}]},{"id":"3521129c-a7ac-441a-ab89-264f8e51f3e1","topic":"生成","expanded":true,"children":[{"id":"7d0ffb5f-31dd-4329-948d-629c65d8b576","topic":"按关键字序列依次插入","expanded":true},{"id":"d0233072-eb74-4067-88c0-39dbd0d42f7b","topic":"不同插入次序的序列生成不同形态的二叉排序树","expanded":true}]}]},{"id":"a1280626-9119-4d40-a86f-82f3cbde274b","topic":"二叉排序树的删除","expanded":true,"children":[{"id":"fd9bd64b-8f06-466a-9245-4508677d5ec5","topic":"若被删除的结点是叶结点，直接删","expanded":true},{"id":"ff4adebf-1804-4b8b-9559-244c110aead1","topic":"若结点只有一棵左子树或右子树，让子树成为该结点的父结点的子树，代替该结点","expanded":true},{"id":"0d89fabc-2e1c-4f81-b7aa-f263da005b1f","topic":"若结点有左、右两棵子树","expanded":true,"children":[{"id":"a631a36b-3d28-45af-a47b-f2ff459b21b4","topic":"以其中序前驱值替换之（值替换），然后再删除该前驱结点（前驱是左子树中最大的结点）","expanded":true},{"id":"a5647a9e-e7fb-4a82-9ac4-06951a026143","topic":"也可以用其后继替换之，然后再删除后继结点（后继是右子树中最小的结点）","expanded":true}]}]},{"id":"e4bd814b-996f-4524-a9b0-ca44812e5c2e","topic":"二叉排序树的查找效率分析","expanded":true,"children":[{"id":"db2d3742-c01a-4144-a8bb-ca404dbad904","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-b247607e52834d.png","width":232.1,"height":188.73},"children":[{"id":"042bb7f2-9ee7-4095-82e5-f6248da355e2","topic":"查找成功的平均查找长度ASL = (1*1 + 2*2 + 3*4 + 4 * 1) / 8 = 2.625","expanded":true},{"id":"fc739f68-416a-4799-9bbb-2e2d5407f297","topic":"查找失败的平均查找长度ASL = (3*7 + 4*2) / 9 =3.22","expanded":true},{"id":"e641c4d8-0a7f-4568-b075-4614d4ad90a5","topic":"查找效率主要取决于树的高度","expanded":true,"children":[{"id":"6122baac-ce82-4c96-8d98-cf0c5ed9115a","topic":"若二叉排序树为平衡二叉树，平均执行时间为O(log2n)","expanded":true},{"id":"29b26eb8-a5fb-44b9-bd74-39a1ee089058","topic":"若二叉排序树只有左/右孩子单支树，平均查找时间为O(n)","expanded":true}]}]}]}]},{"id":"781ab19d-1d85-4012-9722-34bb1ee66993","topic":"平衡二叉树 AVL","expanded":true,"children":[{"id":"0f57d959-eace-4a3d-8a5a-161daf1533dc","topic":"概念","expanded":true,"children":[{"id":"0ce2eb1b-a720-43b7-bd43-dbffd204ea1e","topic":"特性","expanded":true,"children":[{"id":"00880fc3-ef80-4ad9-baad-40e0770df9b8","topic":"是二叉排序树，具有二叉排序树性质","expanded":true},{"id":"c51f9655-7374-4369-ae76-511e2fb45152","topic":"左子树与右子树的高度之差的绝对值小于等于1","expanded":true},{"id":"d51256f4-2bcd-46c9-b9bd-375d9615733c","topic":"左子树和右子树也是平衡二叉排序树","expanded":true}]},{"id":"d2993825-d4eb-409b-9b69-7b796939684e","topic":"平衡因子=结点左子树的高度-结点右子树的高度","expanded":true,"children":[{"id":"c741bba4-f5ef-422e-862b-9540ccd3a769","topic":"故平衡二叉树中，平衡因子只能是 -1、0，1","expanded":true}]}]},{"id":"7d6b48ef-857b-441e-9ff8-95c2ce88a918","topic":"平衡调整","expanded":true,"children":[{"id":"685a16f5-bcff-4e0a-ab6d-9d36f2d551bd","topic":"当平衡二叉树插入（删除）一个结点时","expanded":true,"children":[{"id":"dea3b2e9-52e8-46c0-8daa-e26c9c46dcbb","topic":"首先检查其插入路径上的结点是否因此次操作导致不平衡","expanded":true},{"id":"7916eef7-b111-45f5-a1f9-1d2b9e623392","topic":"若不止一个失衡结点时，从最小失衡子树的根结点开始平衡，直到所有结点都满足平衡二叉树特性","expanded":true}]},{"id":"c0961ea6-be83-45d4-828b-66d374c6fec6","topic":"LL 右单旋","expanded":true,"children":[{"id":"d2a54c3a-2b69-4ae5-9742-987d8408e5c7","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-7a7510f865e4ea.png","width":494.77,"height":125.43}}]},{"id":"901ca64e-32ff-4a1d-98d3-d46f6309cded","topic":"RR 左单旋","expanded":true,"children":[{"id":"18037e75-227e-45da-a0d5-d25158aea344","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-2b1795895d2eb5.png","width":493.14,"height":131.36}}]},{"id":"64922c6a-2dbb-452b-8058-3978bd559ac7","topic":"LR 先左后右双旋转","expanded":true,"children":[{"id":"7be7ddc4-e53b-46b6-8976-8302813f10b3","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-6f4c3f58073f81.png","width":493.67,"height":154.27}}]},{"id":"52e1fa24-156c-41ad-99b8-83958681787e","topic":"RL 先右后左双旋转","expanded":true,"children":[{"id":"14b34dae-c4e6-40eb-9696-3c2249df40ec","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-d87f7fea4086cb.png","width":498.12,"height":154.73}}]},{"id":"7a2961f8-9228-4c4d-8fca-2207eabc23ce","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-db7d65f3e843a4.png","width":272.91,"height":126.22},"children":[{"id":"0a69136d-017e-4afa-9f49-e35b1d04a165","topic":"如果记不住王道四种情况，遵循以下两个原则，代入到前四个情况理解一下，可能就懂了","expanded":true},{"id":"ea8b5389-a68c-441f-8374-11e6ec4e9ab1","topic":"原则一：降低高度","expanded":true,"children":[{"id":"7292a7c8-fabc-404f-ae46-011c2ffa9493","topic":"原则二：找出三个结点，保持二叉排序树性质","expanded":true}]}]}]},{"id":"7e4a2d9f-a952-4f87-93d5-8dcaedf22ceb","topic":"平均查找长度，O(log2n)","expanded":true}]},{"id":"8e2d6afa-f4e5-4cb7-a162-552ba27861e8","topic":"红黑树","expanded":true,"style":{"branchColor":"#BA69C8"},"children":[{"id":"219bcb03-87dc-401a-a35c-d2ca8204a5d6","topic":"红黑树的概念","expanded":true,"children":[{"id":"2f243685-119e-4a08-af3a-f572daf530e7","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-e350381cf61aa7.png","width":439.4,"height":227.14},"children":[{"id":"b276753f-bca6-4343-a45b-a60dd9031f73","topic":"定义","expanded":true,"children":[{"id":"9b41afd1-24c0-4b9a-b42d-9361216fd3ba","topic":"红黑树是二叉排序树（左子树结点值 < 根结点值 < 右子树结点值）","expanded":true},{"id":"09d0dac6-a29c-4004-ab86-a71dc36d8fe8","topic":"根结点是黑色的（每个结点不是黑，就是红）","expanded":true},{"id":"e554ddea-08eb-4b6b-8211-dadf68111e2f","topic":"叶结点（外部结点/NULL结点/失败结点）均是黑色","expanded":true},{"id":"5edca05d-ed3e-407c-ac6c-b3c2e3b164c7","topic":"不存在两个相邻的红结点（即红结点的父结点和孩子结点均是黑色）","expanded":true},{"id":"2c54f2f9-3fca-4bf0-800a-f22bc7e6fe7c","topic":"对每个结点，从该结点到任一叶结点的简单路径上，所含黑结点的数目相同","expanded":true}]},{"id":"0f14d910-5523-430f-9a57-9f940dc62675","topic":"口诀","expanded":true,"children":[{"id":"3136e653-48e9-4c90-8655-993deead2a5e","topic":"左根右，根叶黑；不红红，黑路同","expanded":true}]},{"id":"2d778959-5148-4a8c-8f1b-99972f919ccb","topic":"性质","expanded":true,"children":[{"id":"e7d898fa-58a9-4d21-b2c0-44f49d90dd5d","topic":"根到叶结点最长路径不大于最短路径（全黑）2倍","expanded":true},{"id":"a03c7cd8-e9a9-4907-a6c1-f4939f141bd5","topic":"n个结点高度h<=2log2(n+1)","expanded":true}]},{"id":"a36421cb-2a21-4e9f-9002-66e82a933ce7","topic":"黑高bh","expanded":true,"children":[{"id":"3a642686-a645-4e17-bddf-5a2384282f1d","topic":"从某结点出发（不包含该结点）到达任一空叶结点路径上黑色结点数","expanded":true},{"id":"809b8aa0-a1e7-431d-9f44-53156fc42449","topic":"结论：若根结点黑高为h，内部结点数（关键字）最少有2^h-1个","expanded":true}]}]}]},{"id":"684bd691-c837-4730-aae0-016b92a35935","topic":"红黑树的插入（删除）","expanded":true,"children":[{"id":"5d3f09ee-6623-4a05-baa4-5d05d8c137ed","topic":"考前看一看，记不住","expanded":true}]},{"id":"a7af913d-04c1-4f45-bad0-ceb3894b8d64","topic":"红黑树的性能分析","expanded":true,"children":[{"id":"95f37cdc-8992-4d10-8a98-7ec816465fb1","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-008ff444279f54.png","width":417.84,"height":147.23}}]}]},{"id":"7394c448-f42a-41c0-8e15-3389cd23cf3d","topic":"B树","expanded":true,"children":[{"id":"9aa19840-f7d9-4c72-8de1-149ff33378cf","topic":"概述","expanded":true,"children":[{"id":"03772f8f-3b3f-41cb-9074-ccf43f6bd313","topic":"概念","expanded":true,"children":[{"id":"833fb189-d4b6-433c-b7c1-9bac364c7bd2","topic":"又称多路平衡查找树，B树中所有结点的孩子个数的最大值称为B树的阶，用m表示","expanded":true}]},{"id":"d7e68186-9710-4e02-964c-bf3ed4161e27","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-44175d98791c4a.png","width":505.93,"height":152.78},"children":[{"id":"1ee88b33-9a9d-4264-9329-269f5a51a758","topic":"特点","expanded":true,"children":[{"id":"ef5a629a-2235-4996-be0f-79a0254f3d41","topic":"树中每个结点至多有m棵子树，至多有m-1个关键字","expanded":true},{"id":"bf05f7a2-e13d-465b-beb6-ee70eb002675","topic":"关键字个数：⌈m/2⌉-1<=n<=m-1（根结点：1<=n<=m-1）","expanded":true},{"id":"6b433d35-7285-416d-90d3-041a43eaa951","topic":"子树个数：⌈m/2⌉ <= n <= m（根结点：2 <= n <= m）","expanded":true,"style":{"borderColor":"#EB4D3D"}},{"id":"61816306-a703-4200-9274-d82fc128fafd","topic":"所有的叶结点都出现在同一层次上，且不带信息","expanded":true},{"id":"6fc1648b-94a5-468e-b968-ee0e8b0c0f50","topic":"B树是所有结点的平衡因子均为0的多路平衡查找树","expanded":true}]},{"id":"3523dc3b-2e3a-426b-89ba-f6109bb5993d","topic":"性质","expanded":true,"children":[{"id":"4326481c-ed6f-42bc-a1f6-45349f073816","topic":"结点的孩子个数 = 该结点关键字个数 + 1","expanded":true},{"id":"484046a0-f532-430c-989e-2cba7acc4b0f","topic":"对任一结点，其所有子树高度都相同","expanded":true},{"id":"60a5d86b-1591-418e-804c-72ee486113ae","topic":"关键字的值：子树0<关键字1<子树1<关键字2<子树2<.....（类比二叉排序树 左<中<右）","expanded":true}]},{"id":"f1829a22-1a0b-46e0-98d7-169118d55cdf","topic":"n个关键字的m阶B树，应有n+1个叶结点（叶结点即查找失败情况）","expanded":true,"style":{"borderColor":"#EB4D3D"}}]},{"id":"7da5cac5-3855-4df5-b091-794b71336174","topic":"B树的高度（磁盘存取次数）","expanded":true,"children":[{"id":"4a1f725e-44f7-489d-b3d0-289599b023fc","topic":"对任意一颗包含n个关键字、高度为h、阶数为m的B树","expanded":true},{"id":"7add6539-5b52-45a6-874a-e1a7fc3b8884","topic":"h > logm (n+1)","expanded":true}]}]},{"id":"a3579124-ea4d-44e0-828d-8d24017bf8c6","topic":"B树的操作","expanded":true,"children":[{"id":"208b8999-566e-42c1-867a-843a2ec17b13","topic":"查找","expanded":true,"children":[{"id":"9729c675-89c1-47b4-8e1e-590ce79ad413","topic":"在B树上查找到某个结点后，先在有序表中进行查找","expanded":true},{"id":"5aed7dd3-5dda-48ce-a945-8110a7e7c85f","topic":"若找到则查找成功，否则按照对应的指针信息到所指的子树中去查找","expanded":true},{"id":"20fb4cce-19bc-401d-97fa-76177fea5c24","topic":"查找到叶结点时（对应指针为空指针），则说明树中没有对应的关键字，查找失败","expanded":true}]},{"id":"f6d01b00-55c1-402e-84d6-f31a63a1fda6","topic":"插入","expanded":true,"children":[{"id":"279d502d-4003-4775-aa98-b1592f61efcc","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-1955091f0b657e.png","width":240.11,"height":107.68},"children":[{"id":"60de93f6-9385-4c0b-8031-47cb55a8784d","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-0ec54b5e54776a.png","width":335.32,"height":103.9},"children":[{"id":"ed66fe48-99e3-40f4-bfb8-112e94448a31","topic":"定位：利用查找算法，找出插入该关键字的最底层中的某个非叶结点","expanded":true},{"id":"259a842a-19d7-412d-bfda-5b3479909af4","topic":"在插入后，若结点关键字个数大于等于m，则从中间位置（⌈m/2⌉）将关键字分为两部分\n左部分留在原结点、右部分放到新的结点、中间位置（⌈m/2⌉）的结点插入原结点的父结点","expanded":true}]}]}]},{"id":"8b8790c8-7342-44a7-a569-e7007e204e6f","topic":"删除","expanded":true,"children":[{"id":"a8f9ad2c-cbae-4844-b951-5179b4112573","topic":"非终端结点关键字","expanded":true,"children":[{"id":"ae969ac0-e235-4208-9b03-f05f0af67295","topic":"用其直接前驱（左子树“最右下”元素）或直接后继（右子树“最左下”元素）替代其位置，化为对“终端结点”的删除","expanded":true}]},{"id":"caf6236a-fdf7-405a-8fca-0e4e45882214","topic":"终端结点关键字","expanded":true,"children":[{"id":"f6e7f2e9-a697-43b8-8b44-4a83ce4d3f48","topic":"删除后结点关键字个数未低于下限，无需处理","expanded":true},{"id":"b54f7d24-901e-43f4-bcee-69d98a317e21","topic":"低于下限","expanded":true,"children":[{"id":"37997b64-47d5-44c2-8502-749b9acdd9f7","topic":"左兄弟够借，则用当前结点的前驱、前驱的前驱依次顶替空缺","expanded":true},{"id":"f20e6651-eeb3-4593-a75d-93f128ecd0e7","topic":"右兄弟够借，则用当前结点的后继、后继的后继依次顶替空缺","expanded":true},{"id":"b20809ee-f240-4771-9463-11fddd9efa47","topic":"左右兄弟都不够借，需要将父结点内关键字、左右兄弟进行合并，合并后导致父结点关键字数量-1，可能需要继续合并","expanded":true}]}]}]}]}]},{"id":"09db85f4-3a81-45d1-84f7-6003e3828e11","topic":"B+树","expanded":true,"style":{"branchColor":"#BA69C8"},"children":[{"id":"5b12476f-d8e2-4055-a0b6-8378fece7858","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-41e43f3fa7d143.png","width":507.76,"height":190.19},"children":[{"id":"ab8ff5a5-7534-4e1e-bbbe-5b5b5dfa6cd7","topic":"m阶B+树","expanded":true,"children":[{"id":"1d353851-7ca1-478d-8a19-115203d97154","topic":"每个分支结点最多m棵子树","expanded":true},{"id":"21becb2f-0a29-4e90-af75-0c2bcef49e43","topic":"非叶根结点最少有2棵子树，其他每个结点分支：⌈m/2⌉ <= n <= m","expanded":true},{"id":"d7423ae7-032e-47bb-89d0-33155a2b3964","topic":"结点的子树与关键字个数相等","expanded":true},{"id":"278a7ed6-c166-4ed2-aac4-511aabd73cef","topic":"所有叶结点包含全部关键字及指向相应记录的指针，叶结点中将关键字按大小顺序排序，并且相邻叶结点按大小顺序相互链接起来","expanded":true},{"id":"cf1b699a-10ad-4136-bf2f-a42084547f59","topic":"所有分支结点（可视为索引的索引）中仅包含它的各个结点（即下一级的索引块）中关键字的最大值及指向其子结点的指针","expanded":true}]}]}]},{"id":"45ddd7e3-fea1-40ad-a876-0b5ed3a8728f","topic":"B树与B+树的异同","expanded":true,"children":[{"id":"b4704079-3fae-4d0d-bce1-12a37db1de3f","topic":"差异","expanded":true,"children":[{"id":"1e38665a-163c-4b52-8b16-4c5ad533c82c","topic":"m阶B树","expanded":true,"children":[{"id":"fdd0ae3b-8272-464b-bbda-b3382a777987","topic":"m阶B+树","expanded":true}]},{"id":"fcf32731-dc04-4712-8e2a-538bd3fc6618","topic":"关键字个数：⌈m/2⌉-1<=n<=m-1（根结点：1<=n<=m-1）","expanded":true,"children":[{"id":"1ca25de5-31ed-4f70-88b7-e975f3a89a30","topic":"关键字个数：⌈m/2⌉ <= n <= m（根结点：1 <= n <= m）","expanded":true}]},{"id":"2d950aa8-cda3-49f7-af9c-0f9b03636b97","topic":"n个关键字，n+1棵子树","expanded":true,"children":[{"id":"f2522373-dfb8-472a-9798-4674dd91f413","topic":"n个关键字，n棵子树","expanded":true}]},{"id":"b7d6d431-79eb-4e1c-9589-5bce740547f0","topic":"结点包含记录信息","expanded":true,"children":[{"id":"707d9875-864c-45d8-98c9-65f1c13151d7","topic":"仅最下层叶子结点包含记录信息（访问磁盘次数少）","expanded":true}]},{"id":"5c751f92-e0d1-419c-962c-d3ef4ae6da45","topic":"不支持顺序查找\n查找成功可能在任何一层，速度不稳定","expanded":true,"children":[{"id":"c3bb78ec-6bdc-48c4-9d30-d946f41d46bb","topic":"支持顺序查找\n成功失败都在最后一层，速度稳定","expanded":true}]}]},{"id":"5363826c-9555-47c8-b896-d2eabc5e9233","topic":"相同","expanded":true,"children":[{"id":"932472ee-c153-4b3d-8121-1fed54b2b2a5","topic":"任何结点子树一样高（绝对平衡）","expanded":true}]}]}]},{"id":"c72904dd0af8e8d98143c91c37","topic":"散列表的查找","expanded":true,"style":{"borderColor":"#E32C2D"},"children":[{"id":"8aec9e29-ceb7-4df4-a8b7-3ec955e28e76","topic":"散列表概述","expanded":true,"children":[{"id":"3e76a0cf-6316-4f0b-9fdd-647523517e76","topic":"基本思想","expanded":true,"children":[{"id":"8c0b7e8a-db03-4b36-8055-24e17ee2024b","topic":"记录的存储位置与关键字之间存在对应关系","expanded":true,"children":[{"id":"bcef6d9e-ef41-4822-8b57-36d4262571d2","topic":"对应关系------hash函数（散列函数）","expanded":true}]}]},{"id":"8cf78908-427b-4334-b7e5-5b3ca04f74b8","topic":"概念","expanded":true,"children":[{"id":"d90b352d-7a8a-4a5b-a5d7-99dcc10add05","topic":"散列方法","expanded":true,"children":[{"id":"9dee4889-0813-4f34-9385-09103575a180","topic":"选取某个函数，依该函数按关键字计算元素的存储位置，并按此存放","expanded":true},{"id":"9a9a5a8e-716e-4366-8ca5-b28757581f32","topic":"查找时，由同一个函数对给定值k计算地址，将k与地址单元中元素关键码进行比较，确定查找是否成功","expanded":true}]},{"id":"5dca46ae-4066-42a6-be02-da8a20da78e2","topic":"散列函数","expanded":true,"children":[{"id":"355895cf-bf14-4ab2-8b07-78e2b4b16302","topic":"把查找表中的关键字映射成该关键字对应的地址的函数，记为Hash(key) = Addr(这里的地址可以是数组下标，索引或内存地址等)","expanded":true}]},{"id":"d334cf2b-c58b-46a6-a0b6-860bd9d145a2","topic":"散列表","expanded":true,"children":[{"id":"0add1108-9e8d-4d35-b4e0-3f460d966497","topic":"根据关键字而直接进行访问的数据结构，散列表建立了关键字和存储地址之间的一种直接映射关系","expanded":true}]},{"id":"4f4e854e-6079-413e-96da-5ca5effbdfa5","topic":"冲突","expanded":true,"children":[{"id":"6335a34f-ba53-487c-940a-e84bbc6e80d5","topic":"不同的关键码映射到同一个散列地址 key1 != key2，但H(key1) = H(key2)","expanded":true}]},{"id":"0c9b59e7-d1ca-4930-8b2b-2fab151361b2","topic":"同义词","expanded":true,"children":[{"id":"a9d10753-4387-409c-b1d6-149060bfed48","topic":"具有相同函数值的多个关键字","expanded":true}]}]},{"id":"608431d8-c4fd-4c9e-9419-e651ba993a6e","topic":"性能","expanded":true,"children":[{"id":"57931c63-ac13-4bd0-ad42-c39b0b1dc3fb","topic":"查找效率高，可达到 O(1) 、空间效率低","expanded":true}]},{"id":"fdd96e0b-7924-4428-9d5f-67fc9724ea80","topic":"使用散列表要解决好两个问题","expanded":true,"children":[{"id":"fb919f3b-9f4c-4c6b-8966-aeda0c58ad12","topic":"构造好散列函数","expanded":true,"children":[{"id":"73261eda-cd5f-46be-b33a-6363c4e9bbb6","topic":"所选函数尽可能简单，提高转换速度","expanded":true},{"id":"9b81f102-2e3d-440a-9a1a-2d509a671e09","topic":"所选函数对关键码计算出的地址，应在散列地址集中致均匀分布，以减少空间浪费","expanded":true}]},{"id":"a5fb2b71-74e7-4a5d-bda7-1a66b8e1fd48","topic":"制定一个好的解决冲突的方案","expanded":true}]}]},{"id":"a7c69706-3348-4f9c-b139-24dd1bd87ac6","topic":"散列函数的构造方法","expanded":true,"style":{"branchColor":"#EA8ABA"},"children":[{"id":"9e56aebb-9f42-44af-8cd7-157eb25d936e","topic":"考虑的因素","expanded":true,"children":[{"id":"8cd63373-5b1c-40df-b77e-50b256f1cd61","topic":"执行速度（即计算散列函数所需时间）、关键字的长度、散列表的大小、关键字的分布情况、查找频率","expanded":true}]},{"id":"1cf871bd-5752-44f4-94b1-0540fbf7f2d5","topic":"要求","expanded":true,"children":[{"id":"db408fd3-60ed-47d2-8635-d4ecd86d4569","topic":"n个数据仅占用n个地址，虽然散列查找是以空间换时间，但希望散列的地址空间尽量少","expanded":true},{"id":"cc1ce214-c751-40d9-813a-82f9ad54de11","topic":"无论用什么方法存储，目的都是尽量均匀地存放元素，以避免冲突","expanded":true}]},{"id":"e1d5d274-4e6b-4451-a308-216d89d95d90","topic":"散列函数","expanded":true,"children":[{"id":"d9ec41d2-f0e9-49f4-af2f-7ba4272e94dc","topic":"直接定址法","expanded":true,"children":[{"id":"944ced9c-398b-40f8-b797-fd8477370950","topic":"概述","expanded":true,"children":[{"id":"eb00a693-2d61-4355-94b5-c7fa8c268230","topic":"直接取关键字的某个线性函数值为散列函数","expanded":true}]},{"id":"beda4a43-fa8c-46c9-8029-f985e88e2f5c","topic":"散列函数","expanded":true,"children":[{"id":"9d34b4d2-36a6-4655-9e9a-f7a802439245","topic":"H(key) = key 或 H(key) = a*key + b，a和b为常数","expanded":true}]},{"id":"6061382e-f782-49cc-9ac5-9932f50b0820","topic":"特点","expanded":true,"children":[{"id":"ee4a9ea1-0ae8-4678-a586-e3d7fbc64f26","topic":"计算最简单，不会产生冲突","expanded":true,"children":[{"id":"d3fcc529-8cbe-4d2a-9f7a-53e692595ea7","topic":"适合关键字分布连续的情况（若不连续，则存储空间浪费很多）","expanded":true}]}]}]},{"id":"5e06ebe9-4a65-4915-bf4c-5db125f91c1f","topic":"除留余数法","expanded":true,"children":[{"id":"cc91a3f5-aba7-4f97-8aa8-2200c8f3c89d","topic":"概述","expanded":true,"children":[{"id":"64db71d5-34e2-40a5-b12d-e1827b530c01","topic":"假定散列表表长为m，取一个不大于m但最接近或等于m的质数p，利用以下公式把关键字转换为散列地址","expanded":true}]},{"id":"35fa13ef-2324-45a1-8b88-15bff8ed75b1","topic":"散列函数","expanded":true,"children":[{"id":"9f2c0168-440e-4830-a1ed-983cb2eb96d9","topic":"H(key) = key % p","expanded":true}]},{"id":"2639a2c1-06ea-44a2-988b-2afc58ebd084","topic":"特点","expanded":true,"children":[{"id":"133c3d70-a993-4ddf-a4cd-f9342d61a19b","topic":"关键在p的选取，使得每个关键字通过该函数转换后等概率映射到散列空间的任一地址，减少冲突","expanded":true}]}]},{"id":"e8923c33-80bc-4a7b-859e-deccac72385d","topic":"数字分析法","expanded":true,"children":[{"id":"b3a88caf-3ca3-4ba4-baaa-12026a65ce1a","topic":"概述","expanded":true,"children":[{"id":"cde75ee8-ae7e-46d6-b916-db55829ae2da","topic":"设关键字是r进制数，而r个数码在各位上出现的频率不一定相同，可能在某些位上分布均匀，某种数码出现机会均等。选取数码分布较为均匀的若干位作为散列地址","expanded":true}]},{"id":"d3011813-04b6-472d-9645-e13e04308102","topic":"特点","expanded":true,"children":[{"id":"fe414daf-412b-41ff-94c6-18f44a4ee3f0","topic":"适合于已知的关键字集合，若更换了关键字，则需要重新构造新的散列函数","expanded":true}]}]},{"id":"4fea8458-23eb-4aab-80ea-91fa4ed54e50","topic":"平方取中法","expanded":true,"children":[{"id":"d9c1dcca-6b02-4860-8972-4754b1c6144a","topic":"概述","expanded":true,"children":[{"id":"dca30663-aa5b-436b-ac27-b926ed6f987e","topic":"取关键字的平方值的中间几位作为散列地址","expanded":true}]},{"id":"734c9621-abc4-4f84-b1cf-3ec2896740f4","topic":"特点","expanded":true,"children":[{"id":"63320bde-7cdb-40a7-8baa-ee39c1cf050f","topic":"适合于关键字的每位取值都不够均匀或均小于散列地址所需位数","expanded":true}]}]}]}]},{"id":"dd026571-398a-4543-83c8-19a9c86ec1d5","topic":"冲突解决的方法","expanded":true,"children":[{"id":"32276583-49ce-471d-b101-90d22eccd49a","topic":"开放定址法","expanded":true,"children":[{"id":"de1a9b55-d64e-496d-b712-83e96f91555f","topic":"概念","expanded":true,"children":[{"id":"7a93533c-4c48-42e1-bb3c-cbf71b622bf6","topic":"指可存放新表项的空闲地址，即向它的同义词开发，又向其非同义词开发（删除元素时，用标记表示）","expanded":true}]},{"id":"a1c6d28c-0123-431f-8e5a-1910cdaf7752","topic":"数学递推公式","expanded":true,"children":[{"id":"f7320cd2-3727-4825-9fa9-70506a32d800","topic":"Hi = (H(key) + di) % m","expanded":true,"children":[{"id":"4f7fceda-d6e3-4686-bfe5-9174703b878c","topic":"di即为增量序列","expanded":true}]},{"id":"62333d55-9d51-44b6-833b-2d8f5a3802aa","topic":"增量d的取值","expanded":true,"children":[{"id":"5ede58da-1c85-4b9f-af3f-5bb5081eceb2","topic":"线性探测法","expanded":true,"children":[{"id":"2a176577-1281-4ac2-a589-4c0b76933f72","topic":"di = 0, 1, 2, ... , m-1","expanded":true,"children":[{"id":"4db9b016-c151-41ff-8f92-6564a99733f9","topic":"发生冲突时，顺序表查看表中下一个元素，直到有空闲单元","expanded":true}]},{"id":"5754dec9-e8fe-405c-8b20-9d6fb53130b9","topic":"会出现聚集现象，降低查询效率","expanded":true}]},{"id":"6f526366-95e9-4289-a5bb-58efc7dfcfc1","topic":"平方探测法","expanded":true,"children":[{"id":"64caf690-3c5d-474d-94cf-a8647446aab9","topic":"di = 0² , +1² ,  -1² , +2² , -2² , ... , +k² , -k²","expanded":true},{"id":"3fd2d159-e7f6-43cf-b70d-288ce6a2c513","topic":"不会出现聚集现象，不能探测所有单元，但至少能探测一半","expanded":true}]},{"id":"3f42b1e8-fb71-4385-b2b9-d81526966e26","topic":"再散列法","expanded":true,"children":[{"id":"1605f7b7-c2ef-4caf-8997-3329114c33eb","topic":"公式变为：Hi = (H(key) + i×Hash2(key)) % m","expanded":true,"children":[{"id":"30758982-8699-4b7e-865f-e6d99c670759","topic":"di=Hash2(key)，i为冲突次数，作为公式中再散列系数，别漏了","expanded":true}]}]},{"id":"927cb5be-087e-40c7-a1e4-b7605796db55","topic":"伪随机序列法","expanded":true,"children":[{"id":"98fe8f30-6560-49e0-a335-77d136bd0dd1","topic":"di = 伪随机数序列","expanded":true}]}]}]}]},{"id":"104a7c9e-db64-4426-a17f-439d19c4f0fa","topic":"拉链法","expanded":true,"children":[{"id":"73673e40-3e2d-4f2a-af77-642a96180b7f","topic":"概述","expanded":true,"children":[{"id":"512068f8-5478-4565-acf2-a26ab9ec297b","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-97fb037512f8f5.png","width":266.38,"height":187.79},"children":[{"id":"d28b24a7-90af-4724-8a91-eac3d1a1e1fc","topic":"为了避免冲突，把所有的同义词存储在一个线性链表（由散列地址唯一标识）中","expanded":true}]}]},{"id":"1a165b9d-35ea-43aa-8c21-168828f71e71","topic":"优点","expanded":true,"children":[{"id":"f0269c53-1f4d-4a98-9381-1ad601df60bc","topic":"非同义词不会冲突，无“聚集”现象","expanded":true},{"id":"4b6b1879-cc2b-440a-8f2d-0ad97f7d0714","topic":"链表上结点空间动态申请，更适合于表长不确定的情况（经常插入删除）","expanded":true}]}]}]},{"id":"bfdae14e-03f3-45be-adca-0bfc4995f359","topic":"散列的查找及性能分析","expanded":true,"style":{"branchColor":"#EA8ABA"},"children":[{"id":"2b783c3e-a83e-424f-a391-d3c71fb133f3","topic":"查找过程","expanded":true,"children":[{"id":"e9463e80-78e3-46fe-9cca-b001a6a50d0d","topic":"检测由散列函数形成的地址上是否有记录，若无记录则失败；\n若有记录比较关键字值，若相等则查找成功，否则散列函数更新增量值，重复执行","expanded":true},{"id":"bcdaf728-3178-46e3-8b50-a2481f5c0e03","topic":"补充：求查找失败的ASL时","expanded":true,"children":[{"id":"a35e8f76-0f7f-41f9-8f78-4d16674b10b6","topic":"失败位置也计数；若H(key) = k%7，则失败要算0,1,2,3,4,5,6","expanded":true}]}]},{"id":"69805e2e-a742-46f9-95a6-111168f508f3","topic":"散列表查找效率取决于三个因素","expanded":true,"children":[{"id":"77352b37-45fb-4191-9476-39d28feead94","topic":"散列函数","expanded":true},{"id":"d7d2b2f1-035f-41a3-b6b0-3d65575dd333","topic":"处理冲突的方法","expanded":true},{"id":"1814a9c2-8b60-49a8-8c37-dbb203f72af9","topic":"装填因子","expanded":true,"children":[{"id":"db526d6b-0b76-4de1-8b2a-9458f4847a6d","topic":"装填因子为描述一个表装满程度，越大越容易冲突","expanded":true},{"id":"909cc068-13e4-4870-9e83-24bf99c75da3","topic":"装填因子α = 表中记录数n/散列表长度m","expanded":true},{"id":"19a16b3a-c8d5-4322-a120-74d20d1b2659","topic":"装填因子与 ASL","expanded":true,"children":[{"id":"3b082702-fb4e-42d6-8cab-4954093062e2","topic":"平均查找长度依赖于散列表的装填因子","expanded":true,"style":{"borderColor":"#EB4D3D"}}],"formula":{"tex":"\\begin{aligned} \\mathrm{ASL} &\\approx 1 + \\frac{\\alpha}{2} & \\text{（拉链法）} \\\\ \\mathrm{ASL} &\\approx \\frac{1}{2}\\left(1 + \\frac{1}{1 - \\alpha}\\right) & \\text{（线性探测法）} \\\\ \\mathrm{ASL} &\\approx -\\frac{1}{\\alpha}\\ln(1 - \\alpha) & \\text{（随机探测法）} \\end{aligned}","displayMode":true,"mathml":"<span class=\"katex\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics><mtable rowspacing=\"0.25em\" columnalign=\"right left right\" columnspacing=\"0em 1em\"><mtr><mtd><mstyle scriptlevel=\"0\" displaystyle=\"true\"><mrow><mi mathvariant=\"normal\">A</mi><mi mathvariant=\"normal\">S</mi><mi mathvariant=\"normal\">L</mi></mrow></mstyle></mtd><mtd><mstyle scriptlevel=\"0\" displaystyle=\"true\"><mrow><mrow></mrow><mo>≈</mo><mn>1</mn><mo>+</mo><mfrac><mi>α</mi><mn>2</mn></mfrac></mrow></mstyle></mtd><mtd><mstyle scriptlevel=\"0\" displaystyle=\"true\"><mtext>（拉链法）</mtext></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel=\"0\" displaystyle=\"true\"><mrow><mi mathvariant=\"normal\">A</mi><mi mathvariant=\"normal\">S</mi><mi mathvariant=\"normal\">L</mi></mrow></mstyle></mtd><mtd><mstyle scriptlevel=\"0\" displaystyle=\"true\"><mrow><mrow></mrow><mo>≈</mo><mfrac><mn>1</mn><mn>2</mn></mfrac><mrow><mo fence=\"true\">(</mo><mn>1</mn><mo>+</mo><mfrac><mn>1</mn><mrow><mn>1</mn><mo>−</mo><mi>α</mi></mrow></mfrac><mo fence=\"true\">)</mo></mrow></mrow></mstyle></mtd><mtd><mstyle scriptlevel=\"0\" displaystyle=\"true\"><mtext>（线性探测法）</mtext></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel=\"0\" displaystyle=\"true\"><mrow><mi mathvariant=\"normal\">A</mi><mi mathvariant=\"normal\">S</mi><mi mathvariant=\"normal\">L</mi></mrow></mstyle></mtd><mtd><mstyle scriptlevel=\"0\" displaystyle=\"true\"><mrow><mrow></mrow><mo>≈</mo><mo>−</mo><mfrac><mn>1</mn><mi>α</mi></mfrac><mi>ln</mi><mo>⁡</mo><mo stretchy=\"false\">(</mo><mn>1</mn><mo>−</mo><mi>α</mi><mo stretchy=\"false\">)</mo></mrow></mstyle></mtd><mtd><mstyle scriptlevel=\"0\" displaystyle=\"true\"><mtext>（随机探测法）</mtext></mstyle></mtd></mtr></mtable><annotation encoding=\"application/x-tex\">\\begin{aligned} \\mathrm{ASL} &amp;\\approx 1 + \\frac{\\alpha}{2} &amp; \\text{（拉链法）} \\\\ \\mathrm{ASL} &amp;\\approx \\frac{1}{2}\\left(1 + \\frac{1}{1 - \\alpha}\\right) &amp; \\text{（线性探测法）} \\\\ \\mathrm{ASL} &amp;\\approx -\\frac{1}{\\alpha}\\ln(1 - \\alpha) &amp; \\text{（随机探测法）} \\end{aligned}</annotation></semantics></math></span>"}}]}]},{"id":"a3f20875-4751-42d5-b0ce-969400ce8645","topic":"补充","expanded":true,"children":[{"id":"0c08cae6-a7c7-458c-8802-6d19a5746ffe","topic":"散列表技术具有很好的平均性能，优于一些传统的技术","expanded":true},{"id":"956c720a-e86f-4627-b981-b7afe5236d1c","topic":"链地址法优于开放定址法","expanded":true},{"id":"54063eaa-49b8-48e7-b223-c956ac4a5fad","topic":"除留余数法作散列函数优于其它类型函数","expanded":true}]}]}]}]}}