{"format":"brushup-mindmap-v1","id":"ds-00-sheet4","title":"第五章 树","structure":"timeline-h","theme":"auto","root":{"id":"49aac89ae8d945cf985329e7f1","topic":"第五章 树","expanded":true,"children":[{"id":"ecf97e0d6418ab080b0bdb3f79","topic":"基本概念","expanded":true,"children":[{"id":"3f8be8de6719ec774a582be356","topic":"基本术语","expanded":true,"children":[{"id":"0f19fed0f079b5b91d49eb93eb","topic":"节点关系","expanded":true,"style":{"background":"#8EDDF9"},"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-312a46666fcaf6.png","width":228,"height":187},"children":[{"id":"5ccab6e704592b73ba3368bbde","topic":"祖先 & 子孙","expanded":true,"style":{"background":"#8EDDF9"}},{"id":"bb492c9eb63a66de2d0d7addbe","topic":"双亲 & 孩子","expanded":true,"style":{"background":"#8EDDF9"}},{"id":"e70aa0cd5609fd01e6815b77bc","topic":"兄弟","expanded":true,"style":{"background":"#8EDDF9"}},{"id":"1b8ab49d7138211acdc4780d2b","topic":"分支结点/非终端节点","expanded":true,"style":{"background":"#8EDDF9"},"children":[{"id":"8d5b8ab2c469e202fdacb82a5b","topic":"度 > 0","expanded":true}]},{"id":"d03b1eb604fabc4b1829f9910c","topic":"叶子结点/终端节点","expanded":true,"style":{"background":"#8EDDF9"},"children":[{"id":"65cb25c7cfdb3f3a0b253a9def","topic":"度 = 0","expanded":true}]}]},{"id":"85a931fe5a0aeba77d77e9f7c1","topic":"属性","expanded":true,"style":{"background":"#8EDDF9"},"children":[{"id":"e3ab70e75d39a90456cd5b6d57","topic":"结点的层次","expanded":true,"style":{"background":"#8EDDF9"},"children":[{"id":"743aa14b4a2ae66bb7836a641d","topic":"从根节点（第一层）开始，越往下层数+1","expanded":true}]},{"id":"0aea5fa8eb3b1edd62069b5a41","topic":"结点的高度","expanded":true,"style":{"background":"#8EDDF9"},"children":[{"id":"711825fa785a414633fb2b7f6d","topic":"叶子高度为0，自底向上","expanded":true}]},{"id":"08d20111-4e92-449d-9058-78ca4a5459db","topic":"结点的深度","expanded":true,"style":{"background":"#8EDDF9"},"children":[{"id":"4ae25b4c-b845-4919-aed6-1575bbc77063","topic":"根节点深度为0，自顶向下","expanded":true}]},{"id":"620b12334df9c42b4ec26beecb","topic":"树的高度/深度","expanded":true,"style":{"background":"#8EDDF9"},"children":[{"id":"430ad03029f9ee3b90d3d806e1","topic":"结点的层次的最大值","expanded":true}]},{"id":"a73b7ca63dcbce3127831b6601","topic":"树的路径长度","expanded":true,"style":{"background":"#8EDDF9"},"children":[{"id":"710802b18a39001b39b1fb07ec","topic":"从根节点开始到每个结点的路径长度之和","expanded":true,"children":[{"id":"b1127d20-efe4-4b77-b8a9-80030a75237c","topic":"结点总数的二叉树，完全二叉树的路径长度最小","expanded":true}]}]},{"id":"357ae075a94a5831a112987752","topic":"结点的度","expanded":true,"style":{"background":"#8EDDF9"},"children":[{"id":"9ce92761cd8bcb10ce5fcb9772","topic":"结点拥有的孩子数目","expanded":true}]},{"id":"0deb8086e8a8bffa4160496161","topic":"树的度","expanded":true,"style":{"background":"#8EDDF9"},"children":[{"id":"9e5a39aefe88f56cce7fab2d78","topic":"树中所有结点的度的最大值","expanded":true}]}]},{"id":"f8fba25e00f9b62f5d170b88c7","topic":"路径","expanded":true,"style":{"background":"#8EDE99"},"children":[{"id":"d5db770f15fb199c6070c9d36a","topic":"两结点之间的路径 (vector<Node>)","expanded":true,"style":{"background":"#8EDE99"},"children":[{"id":"532b606b09182d83abccf9a5a4","topic":"路径是由第一个结点到第二个结点的路径，从上到下的","expanded":true},{"id":"66088d54d40a09232c892821c1","topic":"路径是两个节点之间经过的结点序列构成的","expanded":true}]},{"id":"1a6a61f6d43b8e5ae79b8b8eeb","topic":"两结点之间的路径长度 (int)","expanded":true,"style":{"background":"#8EDE99"},"children":[{"id":"c599d94c16a9ba86946e691253","topic":"路径上边的个数","expanded":true}]}]},{"id":"e8a8f007b4d91c7af642cab42a","topic":"有序树和无序树","expanded":true,"children":[{"id":"926a8bdca97b0ad1c3542be461","topic":"有序树：","expanded":true,"children":[{"id":"e1992d15795b33f859442b9510","topic":"每个结点的孩子节点顺序是固定的，不可换","expanded":true},{"id":"fe86c230-f394-4714-9cc9-c36e5b6ab33e","topic":"比如：struct是Node* left, Node* right","expanded":true}]},{"id":"f0583a610d1b1a7cf15efb744b","topic":"无序树：","expanded":true,"children":[{"id":"11796dbf918824994e223814fe","topic":"每个结点的孩子节点顺序可以改变","expanded":true},{"id":"9b4e0542-66d7-469c-8ad9-41c7b2b3c2bd","topic":"比如：struct是vector/set<Node*>","expanded":true}]}]}]},{"id":"a1ca8570ce3b6a6431df19c2e8","topic":"森林","expanded":true,"children":[{"id":"654e1ce7-dd46-4241-8f2c-8f6cc1fcc59f","topic":"多个互不相交的树的【集合】","expanded":true}]},{"id":"944806914fbbbfe9f85bbbe85c","topic":"考点","expanded":true,"children":[{"id":"f0b98456318b9efe0b898942d3","topic":"算结点数和高度、度的关系","expanded":true}]},{"id":"d98840d386db7a00bfd0b97f2b","topic":"m叉数的性质","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-312a46666fcaf6.png","width":228,"height":187},"children":[{"id":"0f8a3ac66cb9b9d4452b2b404c","topic":"树中节点数 = 所有节点的度数之和 + 1","expanded":true,"icons":["priority:1"],"style":{"background":"#FDD834"},"children":[{"id":"eacb4c68faca10a244540be381","topic":"除了根节点，其他节点都是某个节点的孩子","expanded":true},{"id":"b428136f7a48672c196ee8dca3","topic":"如果树的节点为n个，则所有结点度为 n-1","expanded":true},{"id":"5fdbc58b4f1b3101bc66dbed7a","topic":"也即：具有n个节点的树的边数为 n-1","expanded":true,"style":{"background":"#FDD834"}}]},{"id":"6839f89c3d79c39ea233ba4c82","topic":"度为m的树的第i层上至多有","expanded":true,"icons":["priority:2"],"style":{"background":"#FDD834"},"children":[{"id":"255b3a789c09de730e0c8868bf","topic":"","expanded":true,"children":[{"id":"f81bb07f-fc25-44cf-9cbc-2941822423f7","topic":"（想象成满m叉树）","expanded":true}],"formula":{"tex":"m^{i-1} \\text{ 个节点}","displayMode":true,"mathml":"<span class=\"katex\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics><mrow><msup><mi>m</mi><mrow><mi>i</mi><mo>−</mo><mn>1</mn></mrow></msup><mtext> 个节点</mtext></mrow><annotation encoding=\"application/x-tex\">m^{i-1} \\text{ 个节点}</annotation></semantics></math></span>"}}]},{"id":"5c3861a36048922a26599a142c","topic":"高度为h的m叉树最多有","expanded":true,"icons":["priority:3"],"style":{"background":"#FDD834"},"children":[{"id":"324adfa31b9b72439195899bdb","topic":"","expanded":true,"children":[{"id":"3a7e731d-586f-4981-b537-a9836e8fd260","topic":"（想象成满m叉树）","expanded":true}],"formula":{"tex":"1 + m + m^2 + \\dots + m^{h-1} = \\frac{1 - m^h}{1 - m} \\text{ 个节点}","displayMode":true,"mathml":"<span class=\"katex\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics><mrow><mn>1</mn><mo>+</mo><mi>m</mi><mo>+</mo><msup><mi>m</mi><mn>2</mn></msup><mo>+</mo><mo>⋯</mo><mo>+</mo><msup><mi>m</mi><mrow><mi>h</mi><mo>−</mo><mn>1</mn></mrow></msup><mo>=</mo><mfrac><mrow><mn>1</mn><mo>−</mo><msup><mi>m</mi><mi>h</mi></msup></mrow><mrow><mn>1</mn><mo>−</mo><mi>m</mi></mrow></mfrac><mtext> 个节点</mtext></mrow><annotation encoding=\"application/x-tex\">1 + m + m^2 + \\dots + m^{h-1} = \\frac{1 - m^h}{1 - m} \\text{ 个节点}</annotation></semantics></math></span>"}}]},{"id":"e5bbf96809599a552295c8e461","topic":"具有n个节点的m叉树的最小高度","expanded":true,"icons":["priority:4"],"style":{"background":"#FDD834"},"children":[{"id":"3dcb934159481947d11ed87007","topic":"反解上面的h","expanded":true,"children":[{"id":"7f7b7d8cf3b8633019a3a964df","topic":"","expanded":true,"formula":{"tex":"\\log_m(n(m - 1) + 1)","displayMode":true,"mathml":"<span class=\"katex\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics><mrow><msub><mrow><mi>log</mi><mo>⁡</mo></mrow><mi>m</mi></msub><mo stretchy=\"false\">(</mo><mi>n</mi><mo stretchy=\"false\">(</mo><mi>m</mi><mo>−</mo><mn>1</mn><mo stretchy=\"false\">)</mo><mo>+</mo><mn>1</mn><mo stretchy=\"false\">)</mo></mrow><annotation encoding=\"application/x-tex\">\\log_m(n(m - 1) + 1)</annotation></semantics></math></span>"}}]}]},{"id":"d85bb877-12c0-408a-a4e3-b290addb0906","topic":"举特例","expanded":true,"icons":["emoji:💬"],"style":{"borderStyle":"dashed","borderColor":"#F59E0B"}}]},{"id":"bf064195-f78d-41da-aaa7-550b63e5a69d","topic":"考频：低","expanded":true,"style":{"background":"#8EDDF9"},"children":[{"id":"c8f693c3-bed2-4b69-9a59-561c3789ff8e","topic":"10","expanded":true}]}]},{"id":"cf49d1889a5bc02ac7746aed62","topic":"二叉树","expanded":true,"children":[{"id":"98093d59-6cea-4640-9306-5f138ea1f7f0","topic":"考频：中","expanded":true,"style":{"background":"#FDD834"},"children":[{"id":"57d62665-65f7-4aad-a089-ec3728f4fd81","topic":"09、11、18、20、22大","expanded":true}]},{"id":"82ef8b4f-2fd0-45ee-afae-5e1c5f0050dd","topic":"逻辑结构","expanded":true,"children":[{"id":"d659e98741a8e67c38e7b9406f","topic":"有序树，每个结点至多只有两棵子树","expanded":true}]},{"id":"fd8bebc6ee38d3c40f0e6bcb25","topic":"特殊的二叉树","expanded":true,"children":[{"id":"d2f9aaf0b99a17fbf19e8a06ca","topic":"满二叉树","expanded":true,"children":[{"id":"427a5ae7518bd2279426eb34da","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-c60ccc5170222a.png","width":282,"height":151}}]},{"id":"5b680966114af9b73e2e193ec9","topic":"完全二叉树","expanded":true,"children":[{"id":"bfaa3f297898fd913aa35a6fbc","topic":"和满二叉树的结点编号一样","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-3fa0cf5398143b.png","width":269,"height":144},"children":[{"id":"c6f15fa7-2cd3-4888-b2ed-076ddee26f51","topic":"三角形缺右下角","expanded":true}]}]},{"id":"ef7afcc6d538f5c4e897e99bc4","topic":"二叉排序树","expanded":true,"children":[{"id":"5f14a9fd-252b-4ad0-9516-8a0553ac0abf","topic":"二叉树中的每个结点的值一定比左孩子的大，一定比右孩子的值小","expanded":true}]},{"id":"e8a84d9973393a6c7ab6180c71","topic":"平衡二叉树","expanded":true,"children":[{"id":"1dda6c2cc08aae32aded9ba397","topic":"树上任意一个结点的左右子树\n的深度之差不超过1","expanded":true,"style":{"background":"#FF9595"},"children":[{"id":"d6995cf0542b2ebf8d43b9a959","topic":"会有更高效的排序搜索效率","expanded":true,"style":{"background":"#FF9595"}}]}]}]},{"id":"2cd945860758dc8b06d608349d","topic":"二叉树的常考性质","expanded":true,"icons":["emoji:🤔"],"children":[{"id":"f50a1b6ac449e1ccb2902a9fb0","topic":"非空二叉树中度为0、1、2的\n结点个数分别为n0, n1, n2 故","expanded":true,"children":[{"id":"4eb877c111e913a86565f85728","topic":"总结点数为三种之和","expanded":true,"style":{"background":"#8EDE99"},"children":[{"id":"d73be53eed990ec87511f98077","topic":"n = n0 + n1 + n2","expanded":true,"style":{"background":"#8EDDF9"}}]},{"id":"f3ca00232549c1797739986b48","topic":"总结点 = 总度数 + 1","expanded":true,"style":{"background":"#8EDE99"},"children":[{"id":"793a80e8b23858e4ab61cbb55f","topic":"n = 2*n2 + n1 + 1","expanded":true,"style":{"background":"#8EDDF9"},"children":[{"id":"6e326ea4-a83a-4cb7-902e-4df4cae27b08","topic":"n个节点，总度数n-1","expanded":true}]}]},{"id":"e0fa9af68559c58d54825b413a","topic":"可推出：\n叶子节点数 = 度为2的节点数 + 1","expanded":true,"style":{"background":"#8EDE99"},"children":[{"id":"fa2899ec849bd340f2ef897644","topic":"n0 = n2 + 1","expanded":true,"style":{"color":"#111111","background":"#8EDDF9"}}]}]},{"id":"5848d65fb3b908a8509b8b3acd","topic":"完全二叉树","expanded":true,"children":[{"id":"f7f9a122e318c4d4e884390dcc","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-8a03d70c026f45.png","width":503,"height":146},"children":[{"id":"705e01c3-59fc-4d9d-b326-e852c4ab4255","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-d4c06d85708b94.png","width":235,"height":397}},{"id":"0772d122-1500-496f-b022-ffe610f17065","topic":"22年算法题（一半）","expanded":true,"icons":["emoji:💬"],"style":{"borderStyle":"dashed","borderColor":"#F59E0B"}}]}]}]},{"id":"8d59f3f2d28bf45d738bfa4349","topic":"二叉树的存储结构","expanded":true,"children":[{"id":"079aee548b3a0c3af73e6be0a2","topic":"顺序存储","expanded":true,"children":[{"id":"656b4f49b4296a348fbfe9dac0","topic":"存储方式","expanded":true,"children":[{"id":"f738acfebfaa6a1479e5580c0f","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-1d3ebfa2ff4f30.png","width":411,"height":179}}]},{"id":"529b4a333f7b568dfe02fac0b8","topic":"最佳适配完全二叉树","expanded":true},{"id":"0d78d360ce9bc6a42429486f63","topic":"非完全二叉树","expanded":true,"children":[{"id":"bbeba24d37c990dd1d950b2418","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-41fd539b92ea9f.png","width":601,"height":252}}]}]},{"id":"c4f8ca237ec83e0a3af2cb6e61","topic":"链式存储","expanded":true,"children":[{"id":"e329f16993f984910149c8e09e","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-7b22a0ad0006bb.png","width":476,"height":301}}]}]}]},{"id":"bc06a06c-4131-4958-a6b5-f09b50a76fc2","topic":"遍历、线索二叉树","expanded":true,"children":[{"id":"a123c587-cdc2-44b4-b9f3-48e143a9f0ce","topic":"二叉树的遍历","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-312a46666fcaf6.png","width":228,"height":187},"children":[{"id":"fb80f243-8b0e-4f93-a1b0-df2c1db86e3b","topic":"先序、中序、后序","expanded":true,"children":[{"id":"16825b5a-a7c6-48ec-951b-e727abc7b6b4","topic":"递归遍历","expanded":true},{"id":"0169cee1-276e-4b3e-953c-2214e31d6ddb","topic":"非递归","expanded":true}]},{"id":"2c903a2d-872d-48a7-b88e-d8302893f804","topic":"层次遍历","expanded":true,"children":[{"id":"c23e518b-5761-4dfc-8f06-9ba3154f6463","topic":"数据结构——二叉树先序、中序、后序及层次四种遍历（C语言版）_中序遍历_正弦定理的博客-CSDN博客","expanded":true,"hyperlink":"https://blog.csdn.net/chinesekobe/article/details/110874773"}]},{"id":"d1859ed1-d7da-4e71-a2fc-b5905235566f","topic":"知道遍历结果，能否推出树的结构？","expanded":true,"children":[{"id":"ac06d948-d808-45f9-bd4b-0f0bfc3104e4","topic":"先+中","expanded":true},{"id":"213cbda5-dbad-447b-b459-2e8ab19400c5","topic":"中+后","expanded":true},{"id":"dcc392af-fd70-4420-9cc5-6958cfa5e02c","topic":"先+后","expanded":true},{"id":"4c767d83-efae-483f-aeb2-f43e759b35e2","topic":"层+中","expanded":true}]}]},{"id":"7589d4065ee85a3999d92b65ff","topic":"线索二叉树","expanded":true,"children":[{"id":"6d1ac9bb24e8175d7190eb8591","topic":"逻辑、物理结构定死了","expanded":true,"style":{"background":"#FF9595"}},{"id":"43a888ef55d9fd42b44708c805","topic":"考点：1. 基本概念","expanded":true,"children":[{"id":"56e9da824b79bd327a693b45ca","topic":"每个二叉树都有有很多结点的指针空了，无法利用","expanded":true,"children":[{"id":"7de9462704eb9ffee9e71aad07","topic":"给二叉树的每个结点再分别设置左右两个tag标记","expanded":true,"children":[{"id":"54291c5b71a86f277048aaaf31","topic":"tag=0 表明左右指针是结点的孩子","expanded":true},{"id":"634b9a3b4958c2d6363f5ab1df","topic":"tag=1 表明左右指针是结点的前驱/后继","expanded":true}]},{"id":"fc6f566a-1fd5-423d-b9d8-4478658a9b5b","topic":"n个结点、n-1个边，n+1个空指针","expanded":true,"icons":["emoji:💬"],"style":{"borderStyle":"dashed","borderColor":"#F59E0B"}}]},{"id":"1838b9c39d399aff47569854bd","topic":"代码：","expanded":true,"children":[{"id":"099899be5cf84d7a7acc198a37","topic":"ThreadNode 定义","expanded":true,"code":{"lang":"c","code":"typedef struct ThreadNode {\n    ElemType data;                 //数据元素\n    struct ThreadNode *lchild, *rchild; //左、右孩子指针\n    int ltag, rtag;                //左、右线索标志\n}ThreadNode,*ThreadTree;","title":"ThreadNode","tokens":[[{"text":"typedef","darkColor":"#8EA4E2"},{"text":" ","darkColor":"#DEDBD2"},{"text":"struct","darkColor":"#8EA4E2"},{"text":" ThreadNode ","darkColor":"#DEDBD2"},{"text":"{","darkColor":"#BAB5A8"}],[{"text":"    ElemType data","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"},{"text":"                 //数据元素","darkColor":"#908B7E"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"struct","darkColor":"#8EA4E2"},{"text":" ThreadNode ","darkColor":"#DEDBD2"},{"text":"*","darkColor":"#BAB5A8"},{"text":"lchild","darkColor":"#DEDBD2"},{"text":",","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"*","darkColor":"#BAB5A8"},{"text":"rchild","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"},{"text":" //左、右孩子指针","darkColor":"#908B7E"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"int","darkColor":"#74CBC4"},{"text":" ltag","darkColor":"#DEDBD2"},{"text":",","darkColor":"#BAB5A8"},{"text":" rtag","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"},{"text":"                //左、右线索标志","darkColor":"#908B7E"}],[{"text":"}","darkColor":"#BAB5A8"},{"text":"ThreadNode","darkColor":"#DEDBD2"},{"text":",*","darkColor":"#BAB5A8"},{"text":"ThreadTree","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"}]]}}]}]},{"id":"a61b724eb9b8741afadfa825f7","topic":"2. 构造","expanded":true,"children":[{"id":"89c85e68f149a8142c397b73ee","topic":"在树的遍历中，设置前后两个结点指针，来进行前驱/后继的连接","expanded":true}]},{"id":"d56ae45541e9f68d2c4449313b","topic":"3. 代码查找前驱后继","expanded":true,"style":{"background":"#8EDE99"},"children":[{"id":"b169bf33bd6b1c3b8af53926dc","topic":"先序线索二叉树","expanded":true,"style":{"background":"#EEEEEE"},"children":[{"id":"fa78ac87115b5bdda182186262","topic":"前驱不好找","expanded":true,"style":{"background":"#EEEEEE"}},{"id":"1358dacef1b9de3cf586eafc6b","topic":"后继好找","expanded":true,"style":{"background":"#EEEEEE"}}]},{"id":"12ca5026d3792fd9ce6439e0b7","topic":"中序线索二叉树","expanded":true,"style":{"background":"#8EDE99"},"children":[{"id":"e76bfd076d3b84e22e5f6be8aa","topic":"前驱好找","expanded":true,"style":{"background":"#8EDE99"}},{"id":"2e9b43eacf2b2016e8045a4165","topic":"后继好找","expanded":true,"style":{"background":"#8EDE99"}}]},{"id":"0299923c4b6b29cea75ae87d28","topic":"后序线索二叉树","expanded":true,"children":[{"id":"f469b2c2630a5c291900596c6f","topic":"前驱好找","expanded":true},{"id":"9c881db05b4925c869a1eb9f35","topic":"后继不好找","expanded":true,"style":{"background":"#FF9595"},"children":[{"id":"5869d3934758f8142f2bcaae48","topic":"1. 如果为根节点","expanded":true,"style":{"background":"#FF9595"},"children":[{"id":"d91aa839921900ea0c18eb7fea","topic":"后继为NULL","expanded":true}]},{"id":"e4694f50a8c9f648352efa2292","topic":"2. 如果为双亲的右孩子 or 双亲的左孩子+双亲无右孩子","expanded":true,"style":{"background":"#FF9595"},"children":[{"id":"5d6b6d2fcfe9e7ded3fa88b547","topic":"后继是双亲（rtag = 1 时的rchild）","expanded":true}]},{"id":"43cb280cc23be1cee5e1696680","topic":"3. 其他情况","expanded":true,"style":{"background":"#FF9595"},"children":[{"id":"2d1a6ab5b53bc43242cfea4191","topic":"需要找到双亲右子树的第一个被遍历的节点","expanded":true,"children":[{"id":"e7f9d2adf2fbef21bc2f395ba9","topic":"无法用过指针找到","expanded":true}]}]}]}]},{"id":"0efe53ee-eab3-42b3-85a9-9464c4ff5d1e","topic":"难、没考过","expanded":true,"icons":["emoji:💬"],"style":{"borderStyle":"dashed","borderColor":"#F59E0B"}}]}]},{"id":"801b370299c807a4a85efa857c","topic":"一些树的引申题目：","expanded":true,"children":[{"id":"18a94516eb08195f028e2925e3","topic":"1. 已知两节点MN，M是N的祖先，如何找从M到N的路径：","expanded":true,"children":[{"id":"9e6be930a37a9f3e652899230d","topic":"通过【后序遍历 + 辅助栈】的办法就可以找到路径","expanded":true}]},{"id":"a92816f6f2e9bc3121cd3a2da0","topic":"2. 在二叉树的前中后序遍历中，叶子结点的访问顺序","expanded":true,"children":[{"id":"43089d16bb19d5a0032be8beea","topic":"完全相同，因为叶子结点一定不是根节点，一定是子树的访问又一定是先左后右的","expanded":true}]}]},{"id":"d168e361-d818-4e04-bfaa-7561baf09193","topic":"考频：超高","expanded":true,"style":{"background":"#9C27B0"},"children":[{"id":"2f8339e3-f26a-4ecd-b707-e82dd815e84f","topic":"09-15、17*2、22、14大、17大、22大","expanded":true}]}]},{"id":"5f599383fd4b0efb04554af2d0","topic":"树与森林","expanded":true,"children":[{"id":"bbcb6537-5d8b-415e-8aac-ab6b98f235f5","topic":"考频：高","expanded":true,"style":{"background":"#FF9595"},"children":[{"id":"48100f65-9c15-462e-9576-151ba312aaa0","topic":"09、11、14、16、19、20、21、22、16大","expanded":true}]},{"id":"5688129a81baef257e04abc9b2","topic":"树的存储结构","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-a19273f21a384b.png","width":261,"height":220},"children":[{"id":"decba1dccc7bc987c345b98b30","topic":"普通的树的概念","expanded":true,"children":[{"id":"5b8a6d47cb9a99eadfd2197d7d","topic":"每个结点可以有n个孩子，只有一个双亲","expanded":true}]},{"id":"aa3aa6d19bba24b0a554f84aae","topic":"双亲表示法","expanded":true,"children":[{"id":"0cc86f4b8daab6895d24396aa0","topic":"图示","expanded":true,"children":[{"id":"118972b42c9bad6daf6da848c0","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-566dff7c62e247.png","width":333,"height":250}}]},{"id":"8c3b717fdf6b39aec486581af2","topic":"顺序存储","expanded":true,"children":[{"id":"43ebb995a2ba82513408485b8f","topic":"使用静态链表来存储亲子关系","expanded":true},{"id":"ab88cf22d7286b0319949a5177","topic":"代码","expanded":true,"children":[{"id":"bafaeeca33680d3fceab4b5bbe","topic":"双亲表示法代码实现","expanded":true,"code":{"lang":"c","code":"//双亲表示法的存储结构描述如下:\n#define MAX_TREE_SIZE 100       //树中最多结点数\ntypedef struct {                //树的结点定义\n    ElemType data;              //数据元素\n    int parent;                 //双亲位置域\n}PTNode;\ntypedef struct {                //树的类型定义\n    PTNode nodes[MAX_TREE_SIZE];//双亲表示\n    int n;                      //结点数\n}PTree;","title":"PTNode / PTree","tokens":[[{"text":"//双亲表示法的存储结构描述如下:","darkColor":"#908B7E"}],[{"text":"#define ","darkColor":"#C699E0"},{"text":"MAX_TREE_SIZE","darkColor":"#6EC0DF"},{"text":" ","darkColor":"#C699E0"},{"text":"100","darkColor":"#E2B159"},{"text":"       //树中最多结点数","darkColor":"#908B7E"}],[{"text":"typedef","darkColor":"#8EA4E2"},{"text":" ","darkColor":"#C699E0"},{"text":"struct","darkColor":"#8EA4E2"},{"text":" ","darkColor":"#C699E0"},{"text":"{","darkColor":"#BAB5A8"},{"text":"                //树的结点定义","darkColor":"#908B7E"}],[{"text":"    ElemType data","darkColor":"#C699E0"},{"text":";","darkColor":"#BAB5A8"},{"text":"              //数据元素","darkColor":"#908B7E"}],[{"text":"    ","darkColor":"#C699E0"},{"text":"int","darkColor":"#74CBC4"},{"text":" parent","darkColor":"#C699E0"},{"text":";","darkColor":"#BAB5A8"},{"text":"                 //双亲位置域","darkColor":"#908B7E"}],[{"text":"}","darkColor":"#BAB5A8"},{"text":"PTNode","darkColor":"#C699E0"},{"text":";","darkColor":"#BAB5A8"}],[{"text":"typedef","darkColor":"#8EA4E2"},{"text":" ","darkColor":"#DEDBD2"},{"text":"struct","darkColor":"#8EA4E2"},{"text":" ","darkColor":"#DEDBD2"},{"text":"{","darkColor":"#BAB5A8"},{"text":"                //树的类型定义","darkColor":"#908B7E"}],[{"text":"    PTNode ","darkColor":"#DEDBD2"},{"text":"nodes","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"MAX_TREE_SIZE","darkColor":"#DEDBD2"},{"text":"];","darkColor":"#BAB5A8"},{"text":"//双亲表示","darkColor":"#908B7E"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"int","darkColor":"#74CBC4"},{"text":" n","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"},{"text":"                      //结点数","darkColor":"#908B7E"}],[{"text":"}","darkColor":"#BAB5A8"},{"text":"PTree","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"}]]}}]}]},{"id":"12c95aab5db8d363fa15283aa7","topic":"链式存储","expanded":true,"children":[{"id":"da1b651e339a04fd530ecb94e7","topic":"在结点中设置指针来存储链接关系","expanded":true}]}]},{"id":"dce93beb603a34e506747ae87a","topic":"孩子表示法","expanded":true,"children":[{"id":"e0785f933a1874610afd1aee83","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-142a0b3fe315a8.png","width":278,"height":236},"children":[{"id":"de187ba13bfadde0be497a888e","topic":"就是图的邻接链表存储","expanded":true}]}]},{"id":"ba2b2f6224aa3c583deb2b36a5","topic":"孩子兄弟表示法","expanded":true,"children":[{"id":"a99b780b3f98314383855af166","topic":"设置兄弟指针左走是孩子，右走是兄弟","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-061721f677a278.png","width":235,"height":280},"children":[{"id":"7e789bb25a38afd5d359baee0b","topic":"代码","expanded":true,"code":{"lang":"c","code":"typedef struct CSNode {\n    ElemType data;                       //数据域\n    struct CSNode *firstchild,*nextsibling; //第一个孩子和右兄弟指针\n}CSNode,*CSTree;","title":"CSNode","tokens":[[{"text":"typedef","darkColor":"#8EA4E2"},{"text":" ","darkColor":"#DEDBD2"},{"text":"struct","darkColor":"#8EA4E2"},{"text":" CSNode ","darkColor":"#DEDBD2"},{"text":"{","darkColor":"#BAB5A8"}],[{"text":"    ElemType data","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"},{"text":"                       //数据域","darkColor":"#908B7E"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"struct","darkColor":"#8EA4E2"},{"text":" CSNode ","darkColor":"#DEDBD2"},{"text":"*","darkColor":"#BAB5A8"},{"text":"firstchild","darkColor":"#DEDBD2"},{"text":",*","darkColor":"#BAB5A8"},{"text":"nextsibling","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"},{"text":" //第一个孩子和右兄弟指针","darkColor":"#908B7E"}],[{"text":"}","darkColor":"#BAB5A8"},{"text":"CSNode","darkColor":"#DEDBD2"},{"text":",*","darkColor":"#BAB5A8"},{"text":"CSTree","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"}]]}}]}]},{"id":"b8f9c9b1531a23105cce8ad590","topic":"也就是连通无环图","expanded":true,"icons":["emoji:💬"],"style":{"borderStyle":"dashed","borderColor":"#F59E0B"}}]},{"id":"e70ba4feedf8300666bf9992dd","topic":"树的遍历","expanded":true,"children":[{"id":"648b69ec3a88c9b0a0cd8a7e8f","topic":"先根","expanded":true,"children":[{"id":"431aaa3652b88d0f3290a9dc21","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-ed4f67ae9272c5.png","width":452,"height":294}}]},{"id":"f17940c51d6acb9e4d8d0b2ab3","topic":"后根","expanded":true,"children":[{"id":"a5ab3b13cf1b05f37fd29b5736","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-7156617d192ebe.png","width":458,"height":298}}]},{"id":"7219f58a9fdab622dee69b766c","topic":"层次","expanded":true,"children":[{"id":"6f4b334a52080e8a3ef269e3eb","topic":"BFS+使用队列进行辅助","expanded":true}]}]},{"id":"bcda52183c997825e36799eabc","topic":"森林","expanded":true,"children":[{"id":"f03aef15d15837cca0b24a2ba9","topic":"森林就是很多颗树并排在一起","expanded":true,"children":[{"id":"d70a05784d2b6fee0c4a5bf66a","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-124631e1523fd4.png","width":376,"height":227}}]},{"id":"e70a382eaaf880a05ee8a967e0","topic":"把多个树的根节点作为兄弟节点，进行【孩子兄弟表示法】连接","expanded":true}]},{"id":"81c815a0396807fb54174bb309","topic":"森林的遍历","expanded":true,"children":[{"id":"f1aa53d6daa829f071ed981208","topic":"先序","expanded":true,"children":[{"id":"c3ba1ef6a9e87096e56a281efa","topic":"效果等同于对这颗二叉树进行先序遍历","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-2307efff6b358e.png","width":406,"height":209}}]},{"id":"96eaf936277864f75fd4e88172","topic":"后序","expanded":true,"children":[{"id":"d179e1bb2b8b1ff9b5687a273e","topic":"效果等同于对这颗二叉树进行中序遍历","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-0b0fcf1832297c.png","width":412,"height":212}}]}]}]},{"id":"2f7961da6be82af4965819db7e","topic":"二叉数的应用","expanded":true,"children":[{"id":"d098b450e43b64228bcbc8addf","topic":"二叉排序树\n（BST）","expanded":true,"children":[{"id":"d8ea0c11eb2bb5982f69b9c511","topic":"每个结点：左节点值 < 根节点值 < 右节点值","expanded":true},{"id":"2e04a4c2-75d3-447a-87fe-e4048d09acb0","topic":"作用：","expanded":true,"children":[{"id":"951df645-a340-4919-84ef-ea7063413c96","topic":"用来进行搜索，”排序“体现在建树的过程","expanded":true}]},{"id":"c469e15bcd681402d2e39bff00","topic":"算法：","expanded":true,"children":[{"id":"d4082165ba18034af170fa9e3b","topic":"搜索","expanded":true,"children":[{"id":"023a1871b1a8cf7aa12cabb09e","topic":"进行比较，确定向左 or 向右","expanded":true}]},{"id":"d0780e8d9c98c7c8dce2e96771","topic":"插入","expanded":true,"children":[{"id":"2c9880d01a1a5003b054b9c554","topic":"如果树为空，则直接插入","expanded":true},{"id":"310b652df4fbd550836ff9e8b6","topic":"树不为空","expanded":true,"children":[{"id":"b60b6aeb104a9091ae98e85cd5","topic":"和结点值进行比较，如果比它小，就插到左边","expanded":true},{"id":"595bd1fd041b7aa4994eebd559","topic":"如果比它大，就插到右边","expanded":true},{"id":"47aa928f31aabfccd74949f322","topic":"插入时如果发现对应边的结点不为NULL，则继续比较","expanded":true}]}]},{"id":"a72a214614c9265609bbd8f25d","topic":"构造","expanded":true,"children":[{"id":"7b4bcfd697bb2b35d7aa8819ec","topic":"从零开始一个一个插","expanded":true}]},{"id":"c03a4065a8f913c8c7a91ba87b","topic":"删除","expanded":true,"children":[{"id":"dc980ce336887a124f9b1a59cd","topic":"如果是叶子结点，直接删","expanded":true},{"id":"552a28b2fe49a58d83c92aa986","topic":"如果只有单子树，则把子树移动上来","expanded":true},{"id":"fe5ad24de0daccc55df7a9d134","topic":"既有左子树又有右子树","expanded":true,"children":[{"id":"42693d4ed9b97ea4fa1c4b020e","topic":"用直接前驱","expanded":true,"children":[{"id":"853b19877d5af5a2e39558fecb","topic":"左子树的最右","expanded":true}]},{"id":"ed399b05c3aaaca7068a684531","topic":"用直接后继","expanded":true,"children":[{"id":"702bd95b14b8a656aab80b8f72","topic":"右子树的最左","expanded":true}]}]}]}]},{"id":"b7d979dc7589c6b666ee791a4d","topic":"ASL","expanded":true,"children":[{"id":"8f9a4184fec901e0e562089d23","topic":"平均查找长度","expanded":true,"children":[{"id":"86d80534c3e9035326defb398a","topic":"查找次数一定不会超过高度，所以BST越矮越好","expanded":true},{"id":"01fa0d770d98465da5113b2685","topic":"查找成功","expanded":true,"children":[{"id":"f1691de1499bc7c96346d820e8","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-c6b2a4ef9a273c.png","width":458,"height":218}}]},{"id":"4c9bfedecf09a5c656a04ad234","topic":"查找失败","expanded":true,"children":[{"id":"487a471797ba585fc1514bddbf","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-c4fb0f0c3f1a77.png","width":461.87,"height":223.4},"children":[{"id":"8e8aad50b29838a482a4e81722","topic":"失败节点视为等概率，不要钻牛角尖","expanded":true}]}]}]}]}]},{"id":"b9f872fc2c7aac77a52559ab35","topic":"平衡二叉树 \n（AVL）","expanded":true,"children":[{"id":"57c969cdbb1913f72f395ac8a0","topic":"定义：树上面任意一个节点的左右子树的高度差不超过1","expanded":true,"children":[{"id":"bc29aafb1148cf3d882a69d23d","topic":"即左子树高 - 右子树高 = -1, 0, 1","expanded":true}]},{"id":"8c7aef06097bc3c20a24091008","topic":"节点数据结构","expanded":true,"children":[{"id":"dd186956838aa2f7fd878af8a2","topic":"AVLNode 定义","expanded":true,"code":{"lang":"c","code":"//平衡二叉树的结点\ntypedef struct AVLNode {\n    int key;        //数据域\n    int balance;    //平衡因子\n    struct AVLNode *lchild,*rchild;\n}AVLNode,*AVLTree;","title":"AVLNode","tokens":[[{"text":"//平衡二叉树的结点","darkColor":"#908B7E"}],[{"text":"typedef","darkColor":"#8EA4E2"},{"text":" ","darkColor":"#DEDBD2"},{"text":"struct","darkColor":"#8EA4E2"},{"text":" AVLNode ","darkColor":"#DEDBD2"},{"text":"{","darkColor":"#BAB5A8"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"int","darkColor":"#74CBC4"},{"text":" key","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"},{"text":"        //数据域","darkColor":"#908B7E"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"int","darkColor":"#74CBC4"},{"text":" balance","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"},{"text":"    //平衡因子","darkColor":"#908B7E"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"struct","darkColor":"#8EA4E2"},{"text":" AVLNode ","darkColor":"#DEDBD2"},{"text":"*","darkColor":"#BAB5A8"},{"text":"lchild","darkColor":"#DEDBD2"},{"text":",*","darkColor":"#BAB5A8"},{"text":"rchild","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"}],[{"text":"}","darkColor":"#BAB5A8"},{"text":"AVLNode","darkColor":"#DEDBD2"},{"text":",*","darkColor":"#BAB5A8"},{"text":"AVLTree","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"}]]}}]},{"id":"3a5a2f27b3ca77d5206698b551","topic":"插入","expanded":true,"children":[{"id":"822b1b3bdb985c31acbe0956d7","topic":"插入一个节点过后，调整最小的不平衡子树","expanded":true},{"id":"3c7b1378b119da393e755a20fb","topic":"四种不同的调整","expanded":true,"style":{"background":"#FF9595"},"children":[{"id":"a27a1e4dc3ea8dec99ae480fac","topic":"LL","expanded":true,"style":{"background":"#FF9595"},"children":[{"id":"11c9b42bd4387c39adc1899298","topic":"右旋，BL < B(※) < BR < A < AR","expanded":true,"style":{"background":"#FF9595"},"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-91acd6bca52fd4.png","width":662,"height":332},"children":[{"id":"3169f57f4149ad3bb47d98e4f6","topic":"代码实现就是改几个指针","expanded":true}]}]},{"id":"31785e4ca6184f48aa41b8a94c","topic":"RR","expanded":true,"style":{"background":"#FF9595"},"children":[{"id":"bc39878998cb1b242c6ebb97f5","topic":"左旋，AL < A < BL < B(※) < BR","expanded":true,"style":{"background":"#FF9595"},"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-74bbaf935f83a2.png","width":656,"height":311},"children":[{"id":"f27ba0548fe8bb1e732fcbad01","topic":"代码实现就是改几个指针","expanded":true}]}]},{"id":"735a90a54c493d785ceb095004","topic":"LR","expanded":true,"style":{"background":"#FF9595"},"children":[{"id":"1b49a91d638b1decabe348d32c","topic":"先对B左旋再对A右旋，BL < B < CL < C(※) < CR < A < AR","expanded":true,"style":{"background":"#FF9595"},"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-4b5ce69385013c.png","width":658,"height":311}}]},{"id":"7a7b9729a63b3dff9fe948f211","topic":"RL","expanded":true,"style":{"background":"#FF9595"},"children":[{"id":"d6e965d13dca2f3cef6c4bfcbb","topic":"先对B右旋再对A左旋，AL < A < CL < C(※) < CR < B < BR","expanded":true,"style":{"background":"#FF9595"},"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-d44af6bc369694.png","width":661,"height":248}}]}]}]},{"id":"e3781c40aa8ab1e87d9619b181","topic":"查找效率","expanded":true,"style":{"background":"#8EDDF9"},"children":[{"id":"3738fefdcbd8ddece73258a4e8","topic":"树上任意一个结点的左右子树高度只差不超过 1，设n(h)表示为深度为h的平衡树中含有的最少节点数","expanded":true,"style":{"background":"#8EDDF9"},"children":[{"id":"f16bde7f3fa85639e7723ad605","topic":"故有n(h)  = n(h-1) + n(h-2) + 1","expanded":true,"style":{"background":"#8EDDF9"},"children":[{"id":"412d500b-3ca3-4560-a72e-e1342cf6a02a","topic":"第二类数学归纳法","expanded":true,"icons":["emoji:💬"],"style":{"borderStyle":"dashed","borderColor":"#F59E0B"}}]}]},{"id":"ebaa63d249e9ec907edbe8f9ba","topic":"平衡二叉树高度为h，最少的节点数为n，最多的节点数为m：","expanded":true,"style":{"background":"#8EDDF9"},"children":[{"id":"3aaa7c5dd10a1d8472814a2d5e","topic":"h","expanded":true,"style":{"background":"#8EDE99"},"children":[{"id":"c8ab2fa365b81f6828e139d37c","topic":"0","expanded":true,"style":{"background":"#8EDE99"},"children":[{"id":"71093e22023aa034db23bb294d","topic":"1","expanded":true,"style":{"background":"#8EDE99"},"children":[{"id":"23d97549705a4309cf577b9fab","topic":"2","expanded":true,"style":{"background":"#8EDE99"},"children":[{"id":"32da9ba2d2c916941251ab337a","topic":"3","expanded":true,"style":{"background":"#8EDE99"},"children":[{"id":"222b73f90f28ce187f2bb9b68a","topic":"4","expanded":true,"style":{"background":"#8EDE99"},"children":[{"id":"3aab70e3c7eabb1a97ea7a2d9d","topic":"...","expanded":true,"style":{"background":"#8EDE99"},"children":[{"id":"7f090bc449988a12799218a40f","topic":"","expanded":true,"style":{"background":"#8EDE99"},"formula":{"tex":"O(\\log_2 n) = k","displayMode":true,"mathml":"<span class=\"katex\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics><mrow><mi>O</mi><mo stretchy=\"false\">(</mo><msub><mrow><mi>log</mi><mo>⁡</mo></mrow><mn>2</mn></msub><mi>n</mi><mo stretchy=\"false\">)</mo><mo>=</mo><mi>k</mi></mrow><annotation encoding=\"application/x-tex\">O(\\log_2 n) = k</annotation></semantics></math></span>"}}]}]}]}]}]}]}]},{"id":"907a25d4985a892e2c0448dc22","topic":"n","expanded":true,"style":{"background":"#BA69C8"},"children":[{"id":"f958b988d318502a9c22498d36","topic":"0","expanded":true,"style":{"background":"#BA69C8"},"children":[{"id":"322b4ce1ff09fb4c4fad58726e","topic":"1","expanded":true,"style":{"background":"#BA69C8"},"children":[{"id":"a0ab56587c5994854dd46a271f","topic":"2","expanded":true,"style":{"background":"#BA69C8"},"children":[{"id":"459add1de5ca845b15ea3af56b","topic":"4","expanded":true,"style":{"background":"#BA69C8"},"children":[{"id":"5778e90e9dfb6b6af89f686e30","topic":"7","expanded":true,"style":{"background":"#BA69C8"},"children":[{"id":"743b808b0248c711b4f149e0df","topic":"...","expanded":true,"style":{"background":"#BA69C8"},"children":[{"id":"3628c585bb7bcbee9659689e64","topic":"n","expanded":true,"style":{"background":"#BA69C8"}}]}]}]}]}]}]}]},{"id":"ff36f348-a193-4aa5-8695-34596aa055f7","topic":"m","expanded":true,"style":{"background":"#7986CB"},"children":[{"id":"08aedd73-fb5d-4e1c-9f2a-9b9d09bfeb1a","topic":"0","expanded":true,"style":{"background":"#7986CB"},"children":[{"id":"0373bc8b-047c-4c37-a8fc-21a338310cec","topic":"1","expanded":true,"style":{"background":"#7986CB"},"children":[{"id":"532dfd53-cd58-43ae-a42d-5f8583ca1d27","topic":"3","expanded":true,"style":{"background":"#7986CB"},"children":[{"id":"371fa1ce-c2cc-4e67-bc11-868d61ca87e8","topic":"7","expanded":true,"style":{"background":"#7986CB"},"children":[{"id":"b4d7c390-e6ef-4296-a71a-02fc80c5a01b","topic":"15","expanded":true,"style":{"background":"#7986CB"},"children":[{"id":"9199d4c0-115a-4f20-b8b4-f2d674a4f3db","topic":"...","expanded":true,"style":{"background":"#7986CB"},"children":[{"id":"bbca894e-1f61-4ee0-83cd-24b44af0eb1d","topic":"","expanded":true,"style":{"background":"#7986CB"},"formula":{"tex":"k^2 - 1","displayMode":true,"mathml":"<span class=\"katex\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics><mrow><msup><mi>k</mi><mn>2</mn></msup><mo>−</mo><mn>1</mn></mrow><annotation encoding=\"application/x-tex\">k^2 - 1</annotation></semantics></math></span>"}}]}]}]}]}]}]}]}]},{"id":"7e0b87382b59beda1e5f68a3e4","topic":"故平衡二叉树的查找效率为：","expanded":true,"style":{"background":"#8EDDF9"},"children":[{"id":"084a034e3df9fe46e1c05839ab","topic":"","expanded":true,"style":{"background":"#8EDDF9"},"formula":{"tex":"O(\\log_2 n)","displayMode":true,"mathml":"<span class=\"katex\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics><mrow><mi>O</mi><mo stretchy=\"false\">(</mo><msub><mrow><mi>log</mi><mo>⁡</mo></mrow><mn>2</mn></msub><mi>n</mi><mo stretchy=\"false\">)</mo></mrow><annotation encoding=\"application/x-tex\">O(\\log_2 n)</annotation></semantics></math></span>"}}]}]}]},{"id":"747be83f-989a-4109-a734-5b71cbc6f78f","topic":"红黑树 RBT","expanded":true,"children":[{"id":"551b84ad-ef73-4001-aca9-4d04765883ff","topic":"详细：第七章查找","expanded":true}]},{"id":"a66fb271-6303-4401-969d-33fd2fdc2ff2","topic":"考频：高","expanded":true,"style":{"background":"#FF9595"},"children":[{"id":"30dc59c6-1ecf-4b9f-a589-d5024c81efe3","topic":"09、10、11、12、13*2、15、18-21","expanded":true}]},{"id":"77c43657-6857-4a29-a3cc-d23c35d26fa9","topic":"【注】这一小节位于王道书本第7.3章【树形查找】，建议在这里先学了，以免第七章查找的繁杂知识点过多","expanded":true,"style":{"background":"#7986CB"}}]},{"id":"865abcc2da2a5eb096f28addd7","topic":"哈夫曼树","expanded":true,"children":[{"id":"1b08d291-af0a-4fee-a709-7a3d48e62691","topic":"考频：高","expanded":true,"style":{"background":"#FF9595"},"children":[{"id":"b0474782-cc82-4d6a-8af8-2b2d5f23975c","topic":"14、15、17、18、19、21、22、12大、20大","expanded":true}]},{"id":"6a07cbb6-7c87-4ded-b02a-170ea323d9c0","topic":"定义：","expanded":true,"children":[{"id":"ac5035da-db3c-4983-8da9-1b0c2d0c8024","topic":"在二叉树中，每一个节点都赋予一个具有意义的数值，称为该节点的权","expanded":true}]},{"id":"1e5cafc5-c8a7-4709-9340-fc2c764f06b9","topic":"前缀编码：","expanded":true,"style":{"background":"#8EDE99"},"children":[{"id":"bb9346b3-4c6e-4de5-abad-3589658df381","topic":"前缀编码的定义是在一个字符集中，任何一个字符的编码都不是另一个字符编码的前缀。","expanded":true,"style":{"background":"#8EDE99"},"children":[{"id":"76832e8d-79d9-440f-9e7f-1d1e593deb00","topic":"哈夫曼编码就是前缀编码","expanded":true,"style":{"background":"#8EDE99"}}]}]},{"id":"b7bb4a22e0299ea502eaf92ffa","topic":"带权路径长度","expanded":true,"children":[{"id":"b300b9e3-1bb9-48ba-a36d-a0f4d1c23d6b","topic":"结点的：","expanded":true,"children":[{"id":"edfe3ac6-ae69-4d0b-989c-e831eb3c6e0a","topic":"根到结点的边数 * 权值","expanded":true}]},{"id":"6605e6e3-f5e5-4175-b04d-1fe8c9e2e8d5","topic":"树的：","expanded":true,"children":[{"id":"2d7c84be-8994-476a-8c7e-3306dbfc5e9e","topic":"树中所有【叶子】节点带权路径长度之和","expanded":true,"formula":{"tex":"WPL = \\sum_{i=1}^{n} w_i l_i","displayMode":true,"mathml":"<span class=\"katex\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics><mrow><mi>W</mi><mi>P</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>w</mi><mi>i</mi></msub><msub><mi>l</mi><mi>i</mi></msub></mrow><annotation encoding=\"application/x-tex\">WPL = \\sum_{i=1}^{n} w_i l_i</annotation></semantics></math></span>"}}]}]},{"id":"bdd8f45ef10929454ad5ba9afc","topic":"定义","expanded":true,"children":[{"id":"f9f3555c-adbb-4136-8981-06528f6a922a","topic":"n个【带权叶节点】的二叉树中，WPL最小的二叉树称为哈夫曼树","expanded":true}]},{"id":"c07bbad379098ad8a81a6bc8ff","topic":"构造","expanded":true},{"id":"39788274b338e1beec3d4bbbf6","topic":"编码","expanded":true},{"id":"523a3340-7c09-4729-8bb9-f818d7ea3060","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-146749adbf12a6.png","width":543.06,"height":407.41}}]},{"id":"5b9b97bfe0ab07674deabaa703","topic":"并查集","expanded":true,"children":[{"id":"a8982de322a857cb9ef6697c22","topic":"最优雅的算法、帮派战斗、知乎","expanded":true,"hyperlink":"https://zhuanlan.zhihu.com/p/93647900/"},{"id":"a83b5d698b6bbfa8a5063bae52","topic":"定义：","expanded":true,"children":[{"id":"6446e397-01af-4775-9fce-96a53cadc0d9","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-a6dd9c44d87f7b.png","width":406,"height":225},"children":[{"id":"ed823629-140c-470c-8585-5983eb8a2fcb","topic":"存储结构：可以采用森林存储","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-8934141433e20c.png","width":462,"height":232}},{"id":"8d1c80f6-b3d2-4534-adb7-fee363ee03f2","topic":"具体存储方法：采用双亲表示法","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-8695512fa61bef.png","width":460,"height":288}}]},{"id":"b5583261e38949da32a71bde0a","topic":"就是离散数学中的集合的概念","expanded":true,"children":[{"id":"ff3a0198473b4dde4af8b95602","topic":"只支持查找和合并","expanded":true}]}]},{"id":"65d865843acafa68a2e58bb502","topic":"代码：","expanded":true,"children":[{"id":"ffe7df31-fd74-4f06-8aea-bf9b3a4404dc","topic":"初始化","expanded":true,"children":[{"id":"f66a7a3ed94a0376aa78d80cc7","topic":"代码实现","expanded":true,"code":{"lang":"c","code":"/**\n * 并查集的结构定义如下:\n */\n#define SIZE 100\nint UFSets[SIZE];               //集合元素数组 (双亲指针数组)\n/**\n * 并查集的初始化操作 (S 即为并查集) :\n */\nvoid Initial (int S[]) {\n    for(int i=0; i<size; i++)   //每个自成单元素集合\n        S[i] = -1;\n}","title":"UFSets & Initial","tokens":[[{"text":"/**","darkColor":"#908B7E"}],[{"text":" * 并查集的结构定义如下:","darkColor":"#908B7E"}],[{"text":" */","darkColor":"#908B7E"}],[{"text":"#define ","darkColor":"#C699E0"},{"text":"SIZE","darkColor":"#6EC0DF"},{"text":" ","darkColor":"#C699E0"},{"text":"100","darkColor":"#E2B159"}],[{"text":"int","darkColor":"#74CBC4"},{"text":" ","darkColor":"#DEDBD2"},{"text":"UFSets","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"SIZE","darkColor":"#DEDBD2"},{"text":"];","darkColor":"#BAB5A8"},{"text":"               //集合元素数组 (双亲指针数组)","darkColor":"#908B7E"}],[{"text":"/**","darkColor":"#908B7E"}],[{"text":" * 并查集的初始化操作 (S 即为并查集) :","darkColor":"#908B7E"}],[{"text":" */","darkColor":"#908B7E"}],[{"text":"void","darkColor":"#74CBC4"},{"text":" ","darkColor":"#DEDBD2"},{"text":"Initial","darkColor":"#6EC0DF"},{"text":" ","darkColor":"#DEDBD2"},{"text":"(","darkColor":"#BAB5A8"},{"text":"int","darkColor":"#74CBC4"},{"text":" ","darkColor":"#DEDBD2"},{"text":"S","darkColor":"#D5C5AA"},{"text":"[]","darkColor":"#8EA4E2"},{"text":")","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"{","darkColor":"#BAB5A8"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"for","darkColor":"#8EA4E2"},{"text":"(","darkColor":"#BAB5A8"},{"text":"int","darkColor":"#74CBC4"},{"text":" i","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":"0","darkColor":"#E2B159"},{"text":";","darkColor":"#BAB5A8"},{"text":" i","darkColor":"#DEDBD2"},{"text":"<","darkColor":"#BAB5A8"},{"text":"size","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"},{"text":" i","darkColor":"#DEDBD2"},{"text":"++)","darkColor":"#BAB5A8"},{"text":"   //每个自成单元素集合","darkColor":"#908B7E"}],[{"text":"        ","darkColor":"#DEDBD2"},{"text":"S","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"i","darkColor":"#DEDBD2"},{"text":"]","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"-","darkColor":"#BAB5A8"},{"text":"1","darkColor":"#E2B159"},{"text":";","darkColor":"#BAB5A8"}],[{"text":"}","darkColor":"#BAB5A8"}]]}}]},{"id":"cc09d745e81a897deb2a4af02a","topic":"查找：","expanded":true,"children":[{"id":"800af2e1296b33953bc71ada14","topic":"Find 代码实现","expanded":true,"children":[{"id":"83182ef7ebe9d6295dd3fb50ac","topic":"优化：路径合并","expanded":true,"children":[{"id":"22d9b89f3faa4c82c602185fce","topic":"把集合最后变成类似“菊花树”的样子","expanded":true,"code":{"lang":"c","code":"/**\n * 合并 (路径压缩)\n */\nint find(int x) {\n    if(x==fa[x])\n        return x;\n    else {\n        fa[x] = find(fa[x]);    //父节点设为根节点\n        return fa[x];           //返回父节点\n    }\n}\n//以上代码常常简化为一行:\nint find(int x) {\n    return x== fa[x] ? x : (fa[x] = find(fa[x]));\n}","title":"find（路径压缩）","tokens":[[{"text":"/**","darkColor":"#908B7E"}],[{"text":" * 合并 (路径压缩)","darkColor":"#908B7E"}],[{"text":" */","darkColor":"#908B7E"}],[{"text":"int","darkColor":"#74CBC4"},{"text":" ","darkColor":"#DEDBD2"},{"text":"find","darkColor":"#6EC0DF"},{"text":"(","darkColor":"#BAB5A8"},{"text":"int","darkColor":"#74CBC4"},{"text":" ","darkColor":"#DEDBD2"},{"text":"x","darkColor":"#D5C5AA"},{"text":")","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"{","darkColor":"#BAB5A8"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"if","darkColor":"#8EA4E2"},{"text":"(","darkColor":"#BAB5A8"},{"text":"x","darkColor":"#DEDBD2"},{"text":"==","darkColor":"#BAB5A8"},{"text":"fa","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"x","darkColor":"#DEDBD2"},{"text":"])","darkColor":"#BAB5A8"}],[{"text":"        ","darkColor":"#DEDBD2"},{"text":"return","darkColor":"#8EA4E2"},{"text":" x","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"else","darkColor":"#8EA4E2"},{"text":" ","darkColor":"#DEDBD2"},{"text":"{","darkColor":"#BAB5A8"}],[{"text":"        ","darkColor":"#DEDBD2"},{"text":"fa","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"x","darkColor":"#DEDBD2"},{"text":"]","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"find","darkColor":"#6EC0DF"},{"text":"(","darkColor":"#BAB5A8"},{"text":"fa","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"x","darkColor":"#6EC0DF"},{"text":"]);","darkColor":"#BAB5A8"},{"text":"    //父节点设为根节点","darkColor":"#908B7E"}],[{"text":"        ","darkColor":"#DEDBD2"},{"text":"return","darkColor":"#8EA4E2"},{"text":" ","darkColor":"#DEDBD2"},{"text":"fa","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"x","darkColor":"#DEDBD2"},{"text":"];","darkColor":"#BAB5A8"},{"text":"           //返回父节点","darkColor":"#908B7E"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"}","darkColor":"#BAB5A8"}],[{"text":"}","darkColor":"#BAB5A8"}],[{"text":"//以上代码常常简化为一行:","darkColor":"#908B7E"}],[{"text":"int","darkColor":"#74CBC4"},{"text":" ","darkColor":"#DEDBD2"},{"text":"find","darkColor":"#6EC0DF"},{"text":"(","darkColor":"#BAB5A8"},{"text":"int","darkColor":"#74CBC4"},{"text":" ","darkColor":"#DEDBD2"},{"text":"x","darkColor":"#D5C5AA"},{"text":")","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"{","darkColor":"#BAB5A8"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"return","darkColor":"#8EA4E2"},{"text":" x","darkColor":"#DEDBD2"},{"text":"==","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"fa","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"x","darkColor":"#DEDBD2"},{"text":"]","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"?","darkColor":"#BAB5A8"},{"text":" x ","darkColor":"#DEDBD2"},{"text":":","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"(","darkColor":"#BAB5A8"},{"text":"fa","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"x","darkColor":"#DEDBD2"},{"text":"]","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"find","darkColor":"#6EC0DF"},{"text":"(","darkColor":"#BAB5A8"},{"text":"fa","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"x","darkColor":"#6EC0DF"},{"text":"]));","darkColor":"#BAB5A8"}],[{"text":"}","darkColor":"#BAB5A8"}]]}}]}],"code":{"lang":"c","code":"//Find操作 (函数在并查集 S 中查找并返回包含元素 x 的树的根) :\nint Find(int S[], int x) {\n    while(S[x]>=0)          //循环寻找 x 的根\n        x = S[x];\n    return x;               //根的 s[] 小于0\n}","title":"Find","tokens":[[{"text":"//Find操作 (函数在并查集 S 中查找并返回包含元素 x 的树的根) :","darkColor":"#908B7E"}],[{"text":"int","darkColor":"#74CBC4"},{"text":" ","darkColor":"#DEDBD2"},{"text":"Find","darkColor":"#6EC0DF"},{"text":"(","darkColor":"#BAB5A8"},{"text":"int","darkColor":"#74CBC4"},{"text":" ","darkColor":"#DEDBD2"},{"text":"S","darkColor":"#D5C5AA"},{"text":"[]","darkColor":"#8EA4E2"},{"text":",","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"int","darkColor":"#74CBC4"},{"text":" ","darkColor":"#DEDBD2"},{"text":"x","darkColor":"#D5C5AA"},{"text":")","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"{","darkColor":"#BAB5A8"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"while","darkColor":"#8EA4E2"},{"text":"(","darkColor":"#BAB5A8"},{"text":"S","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"x","darkColor":"#DEDBD2"},{"text":"]>=","darkColor":"#BAB5A8"},{"text":"0","darkColor":"#E2B159"},{"text":")","darkColor":"#BAB5A8"},{"text":"          //循环寻找 x 的根","darkColor":"#908B7E"}],[{"text":"        x ","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"S","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"x","darkColor":"#DEDBD2"},{"text":"];","darkColor":"#BAB5A8"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"return","darkColor":"#8EA4E2"},{"text":" x","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"},{"text":"               //根的 s[] 小于0","darkColor":"#908B7E"}],[{"text":"}","darkColor":"#BAB5A8"}]]}}]},{"id":"af2bfbc656dbd6f2fcfd6a56d3","topic":"合并：","expanded":true,"children":[{"id":"0f2968319aa871b07e3b1968ac","topic":"Union 代码实现","expanded":true,"code":{"lang":"c","code":"/**\n * Union操作 (函数求两个不相交子集合的并集) :\n */\nvoid Union(int S[], int Root1, int Root2) {\n    //要求Root1与Root2是不同的，且表示子集合的名字\n    S[Root2] = Root1;   //将根Root2连接到另一根Root1下面\n}","title":"Union","tokens":[[{"text":"/**","darkColor":"#908B7E"}],[{"text":" * Union操作 (函数求两个不相交子集合的并集) :","darkColor":"#908B7E"}],[{"text":" */","darkColor":"#908B7E"}],[{"text":"void","darkColor":"#74CBC4"},{"text":" ","darkColor":"#DEDBD2"},{"text":"Union","darkColor":"#6EC0DF"},{"text":"(","darkColor":"#BAB5A8"},{"text":"int","darkColor":"#74CBC4"},{"text":" ","darkColor":"#DEDBD2"},{"text":"S","darkColor":"#D5C5AA"},{"text":"[]","darkColor":"#8EA4E2"},{"text":",","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"int","darkColor":"#74CBC4"},{"text":" ","darkColor":"#DEDBD2"},{"text":"Root1","darkColor":"#D5C5AA"},{"text":",","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"int","darkColor":"#74CBC4"},{"text":" ","darkColor":"#DEDBD2"},{"text":"Root2","darkColor":"#D5C5AA"},{"text":")","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"{","darkColor":"#BAB5A8"}],[{"text":"    ","darkColor":"#BAB5A8"},{"text":"//要求Root1与Root2是不同的，且表示子集合的名字","darkColor":"#908B7E"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"S","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"Root2","darkColor":"#DEDBD2"},{"text":"]","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":" Root1","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"},{"text":"   //将根Root2连接到另一根Root1下面","darkColor":"#908B7E"}],[{"text":"}","darkColor":"#BAB5A8"}]]}}]}]},{"id":"7776e4ae-6105-4c9a-a8a0-8d48e5ab9b81","topic":"优化：","expanded":true,"children":[{"id":"c85adf06-6e96-445d-a08f-5ce3b8cb358d","topic":"查找的时间复杂度和树高一样，所以要控制树高","expanded":true},{"id":"996586da-0a0f-44a0-bf09-a0d9b208271d","topic":"每次并查集的合并都是小树并到大树里面","expanded":true,"children":[{"id":"139ddc1c-ae34-4afe-8c9c-7eba1a71a0f7","topic":"用根节点的”绝对值“来表示当前结点个数，例如-3即为这个树里面有3个节点","expanded":true},{"id":"f118ef73-44fb-44a9-ac74-964e536e1cd8","topic":"合并后树高不会超过 ⌊log2n⌋+1","expanded":true,"children":[{"id":"378ca391-0318-4a79-9a96-a100f71c296c","topic":"证明：数学归纳法","expanded":true}]},{"id":"61d51809-1050-4447-b55e-2627cad17b36","topic":"实现代码","expanded":true,"code":{"lang":"c","code":"void Union_2(int S[], int Root1, int Root2) {\n    if(Root1 == Root2) return;\n    if(S[Root2] > S[Root1]) {\n        // 如果Root2中的节点数更少，Root2合并到Root1\n        S[Root1] += S[Root2]; // 修改根节点的节点总数\n        S[Root2] = Root1; // Root2合并过去\n    }\n    else {\n        // Root1中的节点数更少，Root1合并到Root2\n        S[Root2] += S[Root1]; // 修改根节点的节点总数\n        S[Root1] = Root2;\n    }\n}","title":"Union_2","tokens":[[{"text":"void","darkColor":"#74CBC4"},{"text":" ","darkColor":"#DEDBD2"},{"text":"Union_2","darkColor":"#6EC0DF"},{"text":"(","darkColor":"#BAB5A8"},{"text":"int","darkColor":"#74CBC4"},{"text":" ","darkColor":"#DEDBD2"},{"text":"S","darkColor":"#D5C5AA"},{"text":"[]","darkColor":"#8EA4E2"},{"text":",","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"int","darkColor":"#74CBC4"},{"text":" ","darkColor":"#DEDBD2"},{"text":"Root1","darkColor":"#D5C5AA"},{"text":",","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"int","darkColor":"#74CBC4"},{"text":" ","darkColor":"#DEDBD2"},{"text":"Root2","darkColor":"#D5C5AA"},{"text":")","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"{","darkColor":"#BAB5A8"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"if","darkColor":"#8EA4E2"},{"text":"(","darkColor":"#BAB5A8"},{"text":"Root1 ","darkColor":"#DEDBD2"},{"text":"==","darkColor":"#BAB5A8"},{"text":" Root2","darkColor":"#DEDBD2"},{"text":")","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"return","darkColor":"#8EA4E2"},{"text":";","darkColor":"#BAB5A8"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"if","darkColor":"#8EA4E2"},{"text":"(","darkColor":"#BAB5A8"},{"text":"S","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"Root2","darkColor":"#DEDBD2"},{"text":"]","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":">","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"S","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"Root1","darkColor":"#DEDBD2"},{"text":"])","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"{","darkColor":"#BAB5A8"}],[{"text":"        ","darkColor":"#BAB5A8"},{"text":"// 如果Root2中的节点数更少，Root2合并到Root1","darkColor":"#908B7E"}],[{"text":"        ","darkColor":"#DEDBD2"},{"text":"S","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"Root1","darkColor":"#DEDBD2"},{"text":"]","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"+=","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"S","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"Root2","darkColor":"#DEDBD2"},{"text":"];","darkColor":"#BAB5A8"},{"text":" // 修改根节点的节点总数","darkColor":"#908B7E"}],[{"text":"        ","darkColor":"#DEDBD2"},{"text":"S","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"Root2","darkColor":"#DEDBD2"},{"text":"]","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":" Root1","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"},{"text":" // Root2合并过去","darkColor":"#908B7E"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"}","darkColor":"#BAB5A8"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"else","darkColor":"#8EA4E2"},{"text":" ","darkColor":"#DEDBD2"},{"text":"{","darkColor":"#BAB5A8"}],[{"text":"        ","darkColor":"#BAB5A8"},{"text":"// Root1中的节点数更少，Root1合并到Root2","darkColor":"#908B7E"}],[{"text":"        ","darkColor":"#DEDBD2"},{"text":"S","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"Root2","darkColor":"#DEDBD2"},{"text":"]","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"+=","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"S","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"Root1","darkColor":"#DEDBD2"},{"text":"];","darkColor":"#BAB5A8"},{"text":" // 修改根节点的节点总数","darkColor":"#908B7E"}],[{"text":"        ","darkColor":"#DEDBD2"},{"text":"S","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"Root1","darkColor":"#DEDBD2"},{"text":"]","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":" Root2","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"}","darkColor":"#BAB5A8"}],[{"text":"}","darkColor":"#BAB5A8"}]]}}],"formula":{"tex":"\\text{时间复杂度 } O(\\log_2 n)","displayMode":true,"mathml":"<span class=\"katex\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics><mrow><mtext>时间复杂度 </mtext><mi>O</mi><mo stretchy=\"false\">(</mo><msub><mrow><mi>log</mi><mo>⁡</mo></mrow><mn>2</mn></msub><mi>n</mi><mo stretchy=\"false\">)</mo></mrow><annotation encoding=\"application/x-tex\">\\text{时间复杂度 } O(\\log_2 n)</annotation></semantics></math></span>"}}]},{"id":"ef95ab7d-7f0d-4c3f-b4c6-54b6d6ac738a","topic":"并查集的究极优化","expanded":true,"children":[{"id":"b6a79052-0f19-46f0-81ce-539fed13f1d7","topic":"压缩路径","expanded":true,"children":[{"id":"19f8cc57-0156-4d74-882e-4589021e0c03","topic":"代码","expanded":true,"children":[{"id":"68d546cc-5f7d-460a-847f-155f13460d64","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-51caaf472cbf22.png","width":691,"height":374}}]},{"id":"c7a6a69a-63d4-45fc-9350-ef66e156867c","topic":"时间复杂度","expanded":true,"children":[{"id":"ade91922-73c5-4e2a-a14e-f7e38ae154b8","topic":"在常见的n的取值范围内是O(4)","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-fd75647cd8eac3.png","width":648,"height":71}}]}]},{"id":"51ca2526-9caf-423f-b0ab-7d55d22b6368","topic":"优化的总结","expanded":true,"children":[{"id":"afe09b21-fdac-4e4d-8af0-10b744bc6bfe","topic":"初始版本：","expanded":true,"children":[{"id":"446945f4-0132-4b8f-82fd-93494ad8b6c0","topic":"用数组、双亲表示法来描述元素之间的集合关系。根节点为-1，非根节点指向父节点下标。","expanded":true}]},{"id":"1e28b856-5d47-428c-91cb-48650da3c948","topic":"Union优化后：","expanded":true,"children":[{"id":"d3d8907e-3ed9-43f7-9388-0f0cd24ef213","topic":"用根节点的负值表示一棵树的节点总数，每次Union的时候是用小树合并到大树根节点下面","expanded":true}]},{"id":"ad7f58d4-4912-491c-ac04-78b89e6010df","topic":"Find优化后：","expanded":true,"children":[{"id":"db8fd20d-01d7-4983-b49c-96fc73522058","topic":"使用了压缩路径的策略，每次Find操作先找到了x所属的根节点，再将查找路径上的所有节点都直接挂载到根节点下面。","expanded":true}]},{"id":"2c5d8da4-aacd-4fb7-86bf-27a1bf2c862a","topic":"最坏时间复杂度比较","expanded":true,"children":[{"id":"cc4e1e60-de0e-4390-bba1-60c16ad8c5e5","topic":"Find操作 = 最坏树高","expanded":true,"children":[{"id":"06091958-72f5-49ec-898d-5a970e65eb22","topic":"初始版本","expanded":true,"style":{"background":"#EEEEEE"},"formula":{"tex":"O(n)","displayMode":true,"mathml":"<span class=\"katex\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics><mrow><mi>O</mi><mo stretchy=\"false\">(</mo><mi>n</mi><mo stretchy=\"false\">)</mo></mrow><annotation encoding=\"application/x-tex\">O(n)</annotation></semantics></math></span>"}},{"id":"ede64f40-9972-40cc-90cc-3f9470859a64","topic":"Union优化后","expanded":true,"style":{"background":"#EEEEEE","borderColor":"#FFAD36"},"formula":{"tex":"O(\\log_2 n)","displayMode":true,"mathml":"<span class=\"katex\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics><mrow><mi>O</mi><mo stretchy=\"false\">(</mo><msub><mrow><mi>log</mi><mo>⁡</mo></mrow><mn>2</mn></msub><mi>n</mi><mo stretchy=\"false\">)</mo></mrow><annotation encoding=\"application/x-tex\">O(\\log_2 n)</annotation></semantics></math></span>"}},{"id":"8b2b8428-e0d3-4324-b4fb-97ee24cad082","topic":"Find优化后","expanded":true,"style":{"background":"#EEEEEE","borderColor":"#FFAD36"},"formula":{"tex":"O(\\alpha(n))","displayMode":true,"mathml":"<span class=\"katex\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics><mrow><mi>O</mi><mo stretchy=\"false\">(</mo><mi>α</mi><mo stretchy=\"false\">(</mo><mi>n</mi><mo stretchy=\"false\">)</mo><mo stretchy=\"false\">)</mo></mrow><annotation encoding=\"application/x-tex\">O(\\alpha(n))</annotation></semantics></math></span>"}}]},{"id":"b44ee75a-6b03-4bd3-a6b2-1979916fff3c","topic":"将n个独立元素经过\nUnion合并为一个集合","expanded":true,"children":[{"id":"e0d165d8-9466-498e-96b1-ca7c776540f5","topic":"初始版本","expanded":true,"style":{"background":"#EEEEEE"},"formula":{"tex":"O(n^2)","displayMode":true,"mathml":"<span class=\"katex\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics><mrow><mi>O</mi><mo stretchy=\"false\">(</mo><msup><mi>n</mi><mn>2</mn></msup><mo stretchy=\"false\">)</mo></mrow><annotation encoding=\"application/x-tex\">O(n^2)</annotation></semantics></math></span>"}},{"id":"5eaea13c-6a54-41af-a3f1-93436a910cee","topic":"Union优化后","expanded":true,"style":{"background":"#EEEEEE","borderColor":"#FFAD36"},"formula":{"tex":"O(n\\log_2 n)","displayMode":true,"mathml":"<span class=\"katex\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics><mrow><mi>O</mi><mo stretchy=\"false\">(</mo><mi>n</mi><msub><mrow><mi>log</mi><mo>⁡</mo></mrow><mn>2</mn></msub><mi>n</mi><mo stretchy=\"false\">)</mo></mrow><annotation encoding=\"application/x-tex\">O(n\\log_2 n)</annotation></semantics></math></span>"}},{"id":"4cbcd647-2ed1-4f22-9522-26d60a96d838","topic":"Find优化后","expanded":true,"style":{"background":"#EEEEEE","borderColor":"#FFAD36"},"formula":{"tex":"O(n\\alpha(n))","displayMode":true,"mathml":"<span class=\"katex\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics><mrow><mi>O</mi><mo stretchy=\"false\">(</mo><mi>n</mi><mi>α</mi><mo stretchy=\"false\">(</mo><mi>n</mi><mo stretchy=\"false\">)</mo><mo stretchy=\"false\">)</mo></mrow><annotation encoding=\"application/x-tex\">O(n\\alpha(n))</annotation></semantics></math></span>"}}]}]}]}]},{"id":"d03e8b46-d0f8-442b-80d6-528e8ea04b51","topic":"应用：","expanded":true,"children":[{"id":"b0c8d946-64ca-4d00-be15-480ef9130d55","topic":"判断图的连通分量","expanded":true},{"id":"811b4517-89dc-4dd3-9122-deead98b033e","topic":"判断图是否有环","expanded":true},{"id":"62cb439e-5b70-40a5-88f2-0d62514b9f34","topic":"Kruskal算法","expanded":true}]},{"id":"af64d4eb-87be-41e3-9579-8a293b26ad62","topic":"考频：低","expanded":true,"style":{"background":"#8EDDF9"},"children":[{"id":"6e0f4c93-3ccf-43f7-bc7c-8628a89156b3","topic":"新考点，没考过","expanded":true}]}]},{"id":"b1ae1f67-e129-43db-83a1-2a6af7e8e154","topic":"END","expanded":true}]},"summaries":[{"id":"030e7744-a7c8-4381-972c-038d939067c9","parentId":"85a931fe5a0aeba77d77e9f7c1","start":1,"end":2,"label":"0还是1 ---> 看题目"},{"id":"79089f5e778bbf0e58c22a413a","parentId":"e8a8f007b4d91c7af642cab42a","start":0,"end":0,"label":"默认谈的就是有序树"},{"id":"930b03e2899944d2820ffbaf7e","parentId":"d56ae45541e9f68d2c4449313b","start":1,"end":1,"label":"访问l/rchild后设置他们的tag和child，以及设置自己的tag和child"},{"id":"69eb40ecbd68cd73c381f892d4","parentId":"5f599383fd4b0efb04554af2d0","start":4,"end":4,"label":"代码实现：先把森林改为孩子兄弟表示法，然后先序 or 中序遍历即可"},{"id":"bc88883a-60b1-4d6a-83f7-7ad2ada8c965","parentId":"51ca2526-9caf-423f-b0ab-7d55d22b6368","start":0,"end":2,"label":""},{"id":"0233540b-92ca-48dc-ad5e-0428db114513","parentId":"5b9b97bfe0ab07674deabaa703","start":5,"end":5,"label":"详见图那章"}],"boundaries":[{"id":"5f088e4d1d3b65d2b9ae680a26","parentId":"ecf97e0d6418ab080b0bdb3f79","start":0,"end":0,"label":"概念不能忘了"},{"id":"6a49027a8b0aa6a184b4593467","parentId":"0299923c4b6b29cea75ae87d28","start":1,"end":1,"label":"故需要堆栈的支持"}]}