{"format":"brushup-mindmap-v1","id":"ds-05-tree","title":"树与二叉树【王道】","structure":"logic-right","theme":"auto","root":{"id":"4ffb78a9fbe94d301c764bbfd7","topic":"第五章 树与二叉树","expanded":true,"children":[{"id":"0cd8151f989b4008ae69a96e48","topic":"树的基本概念","expanded":true,"children":[{"id":"b5ec2056-5bc8-49ac-8a11-398a04bd8541","topic":"树的定义（一种逻辑结构，具有层次关系）：树是n个结点的有限集","expanded":true,"children":[{"id":"f8e3b575-fe2d-4ff2-88e4-e50c5c72a568","topic":"若n=0，称为空树","expanded":true},{"id":"d9b135e5-651b-4e18-b339-615b3d150000","topic":"若n>0，则需要满足如下两个条件","expanded":true,"children":[{"id":"f783da3f-2a49-41ef-84b7-5f1372e53ced","topic":"有且仅有一个特定的称为根的结点","expanded":true},{"id":"b8e99eb0-0df7-4168-9e05-f6ba8c2c8cf0","topic":"其余结点可分为m个互不相交的有限集T1、T2...Tm，其中每一个集合又是一棵树，并称为根的子树","expanded":true}]}]},{"id":"9502233e-7736-473d-acfd-65dfa3891f7e","topic":"树的基本术语","expanded":true,"style":{"borderColor":"#FF9F00","branchColor":"#EA8ABA"},"children":[{"id":"6a619b8c-f102-4253-af57-f1272246aec5","topic":"结点的关系","expanded":true,"children":[{"id":"3121f382-f4d1-4071-aafa-95ac3801764a","topic":"结点的祖先：从根到该结点所经分支上的所有结点","expanded":true},{"id":"e587241d-0bb9-4ab2-93aa-217ec85b5f01","topic":"结点的子孙：以某结点为根的子树中的任一结点","expanded":true},{"id":"c138122d-f52b-47de-9416-0e6402985f94","topic":"双亲和孩子：结点的子树的根称为该结点的孩子，该结点称为孩子的双亲","expanded":true},{"id":"04bb2b75-7f1f-46cb-8b30-c6e6f9bb3b3e","topic":"兄弟：有相同双亲的结点","expanded":true},{"id":"435fe554-9f80-418b-9869-43481addb383","topic":"堂兄弟：双亲在同一层","expanded":true}]},{"id":"c2eef2e0-4619-44b4-a5b6-d3f40e179e4e","topic":"结点的度","expanded":true,"children":[{"id":"c16cdc13-f467-454e-a66d-2ab33b082311","topic":"树中一个结点的孩子个数，树中结点的最大度数称为树的度","expanded":true}]},{"id":"b9a74712-b1fc-422c-94b5-094c40386a9b","topic":"分支结点（非终端结点）","expanded":true,"children":[{"id":"4026df79-5965-4b8c-a6b2-e7aa2d868930","topic":"度大于0的结点","expanded":true}]},{"id":"dd72ac6e-45fa-4fe8-ab46-8287cf387fbc","topic":"叶子结点（终端结点）","expanded":true,"children":[{"id":"584d010d-6357-4f74-bcfe-d9308d36d812","topic":"度为0的结点","expanded":true}]},{"id":"b9bac111-f896-4d78-a61e-9e01c9518753","topic":"结点的层次","expanded":true,"children":[{"id":"d6e70dad-0ae4-4b67-bca9-87a5e7ae2dec","topic":"从树根开始定义，根结点为第一层","expanded":true}]},{"id":"6f993820-17da-47f2-84d9-272c564299c3","topic":"结点的深度","expanded":true,"children":[{"id":"987bb838-d11f-4edf-a220-acc13e8912ba","topic":"从根结点开始自顶向下逐层累加","expanded":true}]},{"id":"1d1fc01d-a1d7-4aab-9c45-9f9f72dda967","topic":"结点的高度","expanded":true,"children":[{"id":"bf355c23-ec79-48c6-a64f-cb0753d36bff","topic":"从叶结点开始自底向上逐层累加","expanded":true}]},{"id":"1f3b8921-1cd3-4ff6-b163-b3ec8d50543d","topic":"树的高度（深度）","expanded":true,"children":[{"id":"6426fac1-39d2-46ff-a6ee-ae8a3319b6a0","topic":"树中结点的最大层数","expanded":true}]},{"id":"0eaff563-f2a5-4a27-a7bf-eba60f994104","topic":"有序树和无序树","expanded":true,"children":[{"id":"860f3298-80b7-40f3-9461-652d1ddc920a","topic":"树中结点的各子树从左到右时有次序的，则该树为有序树，反之无序树","expanded":true}]},{"id":"0cd1d689-db66-40c5-b1ae-85b35d2d6a3f","topic":"森林","expanded":true,"children":[{"id":"27310fab-5912-44b2-b07d-0d696994fe3d","topic":"n课互不相交的树的集合","expanded":true}]}]},{"id":"3624b0f6-75d3-4a65-9a81-551a9067ddb2","topic":"树的性质","expanded":true,"style":{"borderColor":"#E32C2D"},"children":[{"id":"c50be43b-bb8b-46ea-9760-4e547def272f","topic":"树的结点数=总度数+1","expanded":true},{"id":"482238c7-d4b1-4902-b42e-94f9ace7f56a","topic":"m叉树","expanded":true,"style":{"borderColor":"#EB4D3D"},"children":[{"id":"48bd4772-cb44-440e-9e20-0c683ae911b2","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-4257393c1f6d0f.png","width":376,"height":342},"children":[{"id":"fc33028f-993f-43f8-a820-6dd485de05a4","topic":"每个结点最多只能有m个孩子的树（可以是空树）","expanded":true,"children":[{"id":"8ef8277c-086a-4b1f-8129-2a5e57184180","topic":"允许所有结点度<m","expanded":true}]},{"id":"13f96eea-ac7e-41b3-b29a-f9124bebc467","topic":"高度为h的m叉树至少有h个结点，至多有(m^h-1)/(m-1)个结点（等比数列）","expanded":true},{"id":"c83878a2-adaf-45e8-88de-d6c433dc0672","topic":"具有n个结点的m叉树最小高度为 ⌈logm (n(m-1)+1)⌉","expanded":true}]}]},{"id":"e8432b7d-47a8-4915-96e1-86e09cdda4d8","topic":"度为m的树","expanded":true,"style":{"borderColor":"#EB4D3D"},"children":[{"id":"a4f71215-d014-4d45-9ffd-6021c6ffe800","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-c99ff936316a30.png","width":406,"height":324},"children":[{"id":"1ac2bf06-b211-40fe-918e-54b31f717a75","topic":"任意结点的度<=m","expanded":true},{"id":"06f8e673-5fc9-4c63-a517-8199c784a161","topic":"至少有一个结点度=m","expanded":true},{"id":"a719eab8-3a0a-400b-b150-54d501c19aa2","topic":"一定是非空树，至少有m+1个结点","expanded":true}]}]}]}]},{"id":"044e8102-e175-4d7a-8e4a-f41e221e17ae","topic":"二叉树","expanded":true,"children":[{"id":"67ab8b25-3c61-491a-8dd7-20fbdf1363c0","topic":"二叉树的定义","expanded":true,"children":[{"id":"5c7a77ac-be6b-4698-8e0f-eb0976e830b6","topic":"二叉树是n个结点的有限集，它或者是空集（n=0），或者由一个跟结点及两棵互不相交的分别称作这个根的左子树和右子树的二叉树组成","expanded":true},{"id":"cefd31e7-f4fb-48e2-a6d6-f4e1e7a9e39b","topic":"特点","expanded":true,"children":[{"id":"24ebacdb-705f-47dc-89f9-688031c5d5a0","topic":"二叉树是有序树，子树有左右之分，其次序不能颠倒","expanded":true},{"id":"ff50ab61-b562-4d6f-90e5-6dcd6b022676","topic":"二叉树可以是空集合，根可以有空的左子树或空的右子树","expanded":true}]},{"id":"014097d0-92da-4ccf-80af-d2d48e19740f","topic":"二叉树的性质","expanded":true,"style":{"borderColor":"#E32C2D"},"children":[{"id":"711f466c-d0fc-4fea-bb50-fbdd41719e44","topic":"非空二叉树上的叶子结点数等于度为2的结点数+1","expanded":true},{"id":"71927616-e571-4adb-989b-a4a1c455e550","topic":"非空二叉树上第k层上至多有2^k-1个结点","expanded":true},{"id":"79378f2a-2762-4897-a491-3725b403348d","topic":"高度为h的二叉树至多有2^h-1结点","expanded":true}]}]},{"id":"056fb290-a3c4-4e4a-b47b-6b13fa2b5c5c","topic":"特殊的二叉树","expanded":true,"style":{"borderColor":"#E32C2D","branchColor":"#15831C"},"children":[{"id":"7dd5f0de-3024-4183-a60a-de0e4d16debf","topic":"满二叉树","expanded":true,"children":[{"id":"765203d7-f6d3-4f26-a43c-ff8e6d436a46","topic":"概念","expanded":true,"children":[{"id":"44ce4247-b16d-476f-8e40-918be79c176c","topic":"一颗高度为h，且含有2^h-1个结点的二叉树称为满二叉树","expanded":true}]},{"id":"bed8563b-1916-4255-bd37-85b5fd43df07","topic":"性质","expanded":true,"children":[{"id":"aaaa5184-bc4f-4d5d-b402-b0d8f70b2666","topic":"对于编号为i的结点","expanded":true,"children":[{"id":"05b7a5fd-73ed-463d-88c1-9f31e1b8e526","topic":"双亲为⌊i/2⌋","expanded":true},{"id":"244f1e1f-9620-4f10-b76e-267de6bda7b8","topic":"若有左孩子，则左孩子为2i","expanded":true},{"id":"f26d97c9-c4c3-4258-90d3-f21db42c7e11","topic":"若有右孩子，则右孩子为2i+1","expanded":true}]}]}]},{"id":"27ef8057-bd23-4818-afe8-1c851d43b44c","topic":"完全二叉树","expanded":true,"children":[{"id":"95ad978b-32d8-4ba1-a75b-85c1fc231ad3","topic":"概念","expanded":true,"children":[{"id":"5d2686f6-7eef-4680-8930-433c3ffe528f","topic":"高度为h，有n个结点的二叉树，当且仅当其每个结点都与高度为h的满二叉树中编号为1-n的结点一一对应","expanded":true}]},{"id":"6405ced2-b33f-4e99-8cbc-29e886362d14","topic":"特点","expanded":true,"children":[{"id":"1a773000-1428-4d28-bdda-d2df6883c74a","topic":"i<=⌊n/2⌋则结点为分支结点，否则为叶子结点","expanded":true},{"id":"c738fab5-b0d6-42c5-953f-cef995ec6858","topic":"按编号，一旦出现某结点为叶子结点或只有左孩子，则编号大于i的结点均为叶子结点","expanded":true}]},{"id":"e393c517-cf0c-4ab1-9fec-5a5506973e42","topic":"性质","expanded":true,"children":[{"id":"6014e793-75f0-4413-8716-663afa224f76","topic":"具有n个结点的完全二叉树的深度为⌊log2n⌋+1","expanded":true,"children":[{"id":"92e9464a-18b4-4e06-aecd-4dd28a4fdda8","topic":"证明：二叉树深度为k，结点数量：2^(k-1)<=n<2^k，不等式取对数，推出","expanded":true}]},{"id":"d5f152e5-0f49-410e-81b9-06d7b9020d10","topic":"完全二叉树依次编号1,2,...,n，则对任一结点i有","expanded":true,"children":[{"id":"39042cdd-2b9f-463e-a023-a9da464bc4f0","topic":"如果i>1，则其双亲结点是⌊i/2⌋","expanded":true},{"id":"7ac6aecb-1a98-4d5f-aaa2-0d43b58cbdb5","topic":"如果2i>n，则结点i为叶子结点，无左孩子","expanded":true},{"id":"dde72f02-1216-4e45-8db6-a95e0d71d9fc","topic":"如果2i+1>n，则结点i无右孩子","expanded":true},{"id":"669e2286-99cb-40f9-acfc-106a29be4e5a","topic":"结点i所在层次（深度）为⌊log2i⌋+1","expanded":true}]}]}]}]},{"id":"61b1bbea-08dd-492e-8730-fc2b7685f689","topic":"存储结构","expanded":true,"children":[{"id":"59696074-c078-4104-bd51-bb2fb3a691c2","topic":"顺序存储结构","expanded":true,"children":[{"id":"22a385ec-7942-4a91-8f3f-c14576aee6f2","topic":"用一组地址连续的存储单元存储二叉树，为了反映二叉树结点间的逻辑关系，需要添加很多不存在的空结点","expanded":true},{"id":"ff77eb2d-6702-4058-94ed-ee610095cf44","topic":"浪费空间，存储右单支树时，深度为k需要2^k-1的空间","expanded":true}]},{"id":"3ff2928b-0c2c-450d-b1c9-197204543866","topic":"链式存储结构","expanded":true,"children":[{"id":"7d888ed9-587e-4c62-8836-9d0f4d8506f9","topic":"二叉链表","expanded":true,"children":[{"id":"ef415a0e-a8fc-4948-a342-3786d00a06cb","topic":"BiNode 定义","expanded":true,"code":{"lang":"c","code":"typedef struct BiNode{\n    TElemType data;\n    struct BiNode *lchild,*rchild; //左右孩子指针\n}BiNode,*BiTree;","title":"BiNode / BiTree","tokens":[[{"text":"typedef","darkColor":"#8EA4E2"},{"text":" ","darkColor":"#DEDBD2"},{"text":"struct","darkColor":"#8EA4E2"},{"text":" BiNode","darkColor":"#DEDBD2"},{"text":"{","darkColor":"#BAB5A8"}],[{"text":"    TElemType data","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"struct","darkColor":"#8EA4E2"},{"text":" BiNode ","darkColor":"#DEDBD2"},{"text":"*","darkColor":"#BAB5A8"},{"text":"lchild","darkColor":"#DEDBD2"},{"text":",*","darkColor":"#BAB5A8"},{"text":"rchild","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"},{"text":" //左右孩子指针","darkColor":"#908B7E"}],[{"text":"}","darkColor":"#BAB5A8"},{"text":"BiNode","darkColor":"#DEDBD2"},{"text":",*","darkColor":"#BAB5A8"},{"text":"BiTree","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"}]]}},{"id":"2a588dc5-afa5-44ec-bdeb-f6bf391a0d8c","topic":"含有n个结点的二叉链表中，含有n+1个空链域","expanded":true}]},{"id":"6e2402bb-537c-4111-9649-3129fddfe2b4","topic":"三叉链表（带父结点）","expanded":true,"children":[{"id":"1a2c8582-d9fe-4ba1-a79a-12a605a4a235","topic":"TriTNode 定义","expanded":true,"code":{"lang":"c","code":"typedef struct TriTNode{\n    TelemType data;\n    struct TriTNode *lchild,*parent,*rchild;\n}TriTNode,*TriTree;","title":"TriTNode / TriTree","tokens":[[{"text":"typedef","darkColor":"#8EA4E2"},{"text":" ","darkColor":"#DEDBD2"},{"text":"struct","darkColor":"#8EA4E2"},{"text":" TriTNode","darkColor":"#DEDBD2"},{"text":"{","darkColor":"#BAB5A8"}],[{"text":"    TelemType data","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"struct","darkColor":"#8EA4E2"},{"text":" TriTNode ","darkColor":"#DEDBD2"},{"text":"*","darkColor":"#BAB5A8"},{"text":"lchild","darkColor":"#DEDBD2"},{"text":",*","darkColor":"#BAB5A8"},{"text":"parent","darkColor":"#DEDBD2"},{"text":",*","darkColor":"#BAB5A8"},{"text":"rchild","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"}],[{"text":"}","darkColor":"#BAB5A8"},{"text":"TriTNode","darkColor":"#DEDBD2"},{"text":",*","darkColor":"#BAB5A8"},{"text":"TriTree","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"}]]}}]}]}]}]},{"id":"a95987409199d2a3b4eda8871d","topic":"遍历二叉树和线索二叉树","expanded":true,"children":[{"id":"ecdc19c7-b7c0-48f4-942f-39e21a7f8b5a","topic":"二叉树的遍历","expanded":true,"style":{"borderColor":"#E32C2D"},"children":[{"id":"8be475e1-31b7-4ccf-a0ee-a66e82e700fa","topic":"概念","expanded":true,"children":[{"id":"c2a9f8b6-8a5c-453c-b381-d2b5676609f9","topic":"二叉树的遍历是指按某条搜索路径访问树中每个结点，每个结点均被且仅被访问一次","expanded":true}]},{"id":"879a22de-d8c8-4306-b995-b323734fc75a","topic":"先序遍历","expanded":true,"children":[{"id":"7ef2542e-5791-40ca-8510-5d24acf2b55c","topic":"PreOrderTraverse","expanded":true,"children":[{"id":"e7861ca1-6d3e-4cff-9b54-a4a16884a321","topic":"先访问根结点","expanded":true},{"id":"9b813243-f6fc-4c75-884a-3c9c25f0acba","topic":"先序遍历左子树","expanded":true},{"id":"44c14ec4-02e6-4b53-8216-8a33959d94af","topic":"先序遍历右子树","expanded":true}],"code":{"lang":"c","code":"Status PreOrderTraverse(BiTree T){\n    if(T==NULL) return OK; //空二叉树\n    else{\n        visit(T); //访问根结点\n        PreOrderTraverse(T->lchild); //递归遍历左子树\n        PreOrderTraverse(T->rchild); //递归遍历右子树\n    }\n}","title":"PreOrderTraverse","tokens":[[{"text":"Status ","darkColor":"#DEDBD2"},{"text":"PreOrderTraverse","darkColor":"#6EC0DF"},{"text":"(","darkColor":"#BAB5A8"},{"text":"BiTree ","darkColor":"#DEDBD2"},{"text":"T","darkColor":"#D5C5AA"},{"text":"){","darkColor":"#BAB5A8"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"if","darkColor":"#8EA4E2"},{"text":"(","darkColor":"#BAB5A8"},{"text":"T","darkColor":"#DEDBD2"},{"text":"==","darkColor":"#BAB5A8"},{"text":"NULL","darkColor":"#E2B159"},{"text":")","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"return","darkColor":"#8EA4E2"},{"text":" OK","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"},{"text":" //空二叉树","darkColor":"#908B7E"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"else","darkColor":"#8EA4E2"},{"text":"{","darkColor":"#BAB5A8"}],[{"text":"        ","darkColor":"#DEDBD2"},{"text":"visit","darkColor":"#6EC0DF"},{"text":"(","darkColor":"#BAB5A8"},{"text":"T","darkColor":"#6EC0DF"},{"text":");","darkColor":"#BAB5A8"},{"text":" //访问根结点","darkColor":"#908B7E"}],[{"text":"        ","darkColor":"#DEDBD2"},{"text":"PreOrderTraverse","darkColor":"#6EC0DF"},{"text":"(","darkColor":"#BAB5A8"},{"text":"T","darkColor":"#EEECE6"},{"text":"->","darkColor":"#BAB5A8"},{"text":"lchild","darkColor":"#EEECE6"},{"text":");","darkColor":"#BAB5A8"},{"text":" //递归遍历左子树","darkColor":"#908B7E"}],[{"text":"        ","darkColor":"#DEDBD2"},{"text":"PreOrderTraverse","darkColor":"#6EC0DF"},{"text":"(","darkColor":"#BAB5A8"},{"text":"T","darkColor":"#EEECE6"},{"text":"->","darkColor":"#BAB5A8"},{"text":"rchild","darkColor":"#EEECE6"},{"text":");","darkColor":"#BAB5A8"},{"text":" //递归遍历右子树","darkColor":"#908B7E"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"}","darkColor":"#BAB5A8"}],[{"text":"}","darkColor":"#BAB5A8"}]]}}]},{"id":"55bcb977-4f8c-48a7-9939-794eefc03186","topic":"中序遍历","expanded":true,"children":[{"id":"95cd0aa5-09ad-4e9e-b7bc-efc1cc65387c","topic":"InOrderTraverse","expanded":true,"children":[{"id":"709160b0-e1ed-4bb9-9076-b36bf3c652e3","topic":"中序遍历左子树","expanded":true},{"id":"a4bcf0de-c85a-4546-a8eb-c0ae6a7c06ec","topic":"访问根结点","expanded":true},{"id":"493ce10c-2e27-43a3-a19d-0e1ce5ffe6ea","topic":"中序遍历右子树","expanded":true}],"code":{"lang":"c","code":"Status InOrderTraverse(BiTree T){\n    if(T==NULL) return OK; //空二叉树\n    else{\n        InOrderTraverse(T->lchild); //递归遍历左子树\n        visit(T); //访问根结点;\n        InOrderTraverse(T->rchild); //递归遍历右子树\n    }\n}","title":"InOrderTraverse","tokens":[[{"text":"Status ","darkColor":"#DEDBD2"},{"text":"InOrderTraverse","darkColor":"#6EC0DF"},{"text":"(","darkColor":"#BAB5A8"},{"text":"BiTree ","darkColor":"#DEDBD2"},{"text":"T","darkColor":"#D5C5AA"},{"text":"){","darkColor":"#BAB5A8"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"if","darkColor":"#8EA4E2"},{"text":"(","darkColor":"#BAB5A8"},{"text":"T","darkColor":"#DEDBD2"},{"text":"==","darkColor":"#BAB5A8"},{"text":"NULL","darkColor":"#E2B159"},{"text":")","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"return","darkColor":"#8EA4E2"},{"text":" OK","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"},{"text":" //空二叉树","darkColor":"#908B7E"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"else","darkColor":"#8EA4E2"},{"text":"{","darkColor":"#BAB5A8"}],[{"text":"        ","darkColor":"#DEDBD2"},{"text":"InOrderTraverse","darkColor":"#6EC0DF"},{"text":"(","darkColor":"#BAB5A8"},{"text":"T","darkColor":"#EEECE6"},{"text":"->","darkColor":"#BAB5A8"},{"text":"lchild","darkColor":"#EEECE6"},{"text":");","darkColor":"#BAB5A8"},{"text":" //递归遍历左子树","darkColor":"#908B7E"}],[{"text":"        ","darkColor":"#DEDBD2"},{"text":"visit","darkColor":"#6EC0DF"},{"text":"(","darkColor":"#BAB5A8"},{"text":"T","darkColor":"#6EC0DF"},{"text":");","darkColor":"#BAB5A8"},{"text":" //访问根结点;","darkColor":"#908B7E"}],[{"text":"        ","darkColor":"#DEDBD2"},{"text":"InOrderTraverse","darkColor":"#6EC0DF"},{"text":"(","darkColor":"#BAB5A8"},{"text":"T","darkColor":"#EEECE6"},{"text":"->","darkColor":"#BAB5A8"},{"text":"rchild","darkColor":"#EEECE6"},{"text":");","darkColor":"#BAB5A8"},{"text":" //递归遍历右子树","darkColor":"#908B7E"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"}","darkColor":"#BAB5A8"}],[{"text":"}","darkColor":"#BAB5A8"}]]}}]},{"id":"6a16aa9a-76f9-401d-8d94-436b60c5de08","topic":"后序遍历","expanded":true,"children":[{"id":"9f2a24bb-613c-43fe-b96c-091d055414ac","topic":"PostOrderTraverse","expanded":true,"children":[{"id":"8be067f4-f386-42b3-b375-8d8563dccfa2","topic":"后序遍历左子树","expanded":true},{"id":"978f4793-02a7-4798-aeb8-f25b8652c03a","topic":"后序遍历右子树","expanded":true},{"id":"25ca8078-52cb-4511-b4b5-c09a93818838","topic":"访问根结点","expanded":true},{"id":"454fb078-23ee-4765-9a35-ac805ca58b6c","topic":"可用于找祖先和子孙结点间路径","expanded":true,"style":{"borderColor":"#EB4D3D"}}],"code":{"lang":"c","code":"Status PostOrderTraverse(BiTree T){\n    if(T==NULL) return OK; //空二叉树\n    else{\n        PostOrderTraverse(T->lchild); //递归遍历左子树\n        PostOrderTraverse(T->rchild); //递归遍历右子树\n        visit(T); //访问根结点\n    }\n}","title":"PostOrderTraverse","tokens":[[{"text":"Status ","darkColor":"#DEDBD2"},{"text":"PostOrderTraverse","darkColor":"#6EC0DF"},{"text":"(","darkColor":"#BAB5A8"},{"text":"BiTree ","darkColor":"#DEDBD2"},{"text":"T","darkColor":"#D5C5AA"},{"text":"){","darkColor":"#BAB5A8"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"if","darkColor":"#8EA4E2"},{"text":"(","darkColor":"#BAB5A8"},{"text":"T","darkColor":"#DEDBD2"},{"text":"==","darkColor":"#BAB5A8"},{"text":"NULL","darkColor":"#E2B159"},{"text":")","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"return","darkColor":"#8EA4E2"},{"text":" OK","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"},{"text":" //空二叉树","darkColor":"#908B7E"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"else","darkColor":"#8EA4E2"},{"text":"{","darkColor":"#BAB5A8"}],[{"text":"        ","darkColor":"#DEDBD2"},{"text":"PostOrderTraverse","darkColor":"#6EC0DF"},{"text":"(","darkColor":"#BAB5A8"},{"text":"T","darkColor":"#EEECE6"},{"text":"->","darkColor":"#BAB5A8"},{"text":"lchild","darkColor":"#EEECE6"},{"text":");","darkColor":"#BAB5A8"},{"text":" //递归遍历左子树","darkColor":"#908B7E"}],[{"text":"        ","darkColor":"#DEDBD2"},{"text":"PostOrderTraverse","darkColor":"#6EC0DF"},{"text":"(","darkColor":"#BAB5A8"},{"text":"T","darkColor":"#EEECE6"},{"text":"->","darkColor":"#BAB5A8"},{"text":"rchild","darkColor":"#EEECE6"},{"text":");","darkColor":"#BAB5A8"},{"text":" //递归遍历右子树","darkColor":"#908B7E"}],[{"text":"        ","darkColor":"#DEDBD2"},{"text":"visit","darkColor":"#6EC0DF"},{"text":"(","darkColor":"#BAB5A8"},{"text":"T","darkColor":"#6EC0DF"},{"text":");","darkColor":"#BAB5A8"},{"text":" //访问根结点","darkColor":"#908B7E"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"}","darkColor":"#BAB5A8"}],[{"text":"}","darkColor":"#BAB5A8"}]]}}]},{"id":"50229655-b6a3-4406-bb0e-010fa4238783","topic":"层次遍历","expanded":true,"children":[{"id":"748c3f02-5653-4ac0-a914-638065a62635","topic":"LevelOrder","expanded":true,"children":[{"id":"36db1a3b-cc55-4e6a-9e47-59c6f3a683ee","topic":"先将二叉树根结点入队，然后出队，访问出队结点","expanded":true},{"id":"8ec20185-c862-4c90-aac5-27f5a1d6c11d","topic":"若它有左子树，则将左子树根结点入队","expanded":true},{"id":"e479d714-6709-46c1-a106-5c6ea63e2401","topic":"若它有右子树，则将右子树根结点入队","expanded":true},{"id":"7209de6e-f13f-4ad3-bb5f-856e63146ca1","topic":"然后出队，访问出队结点......如此反复，直到队列为空","expanded":true}],"code":{"lang":"c","code":"void LevelOrder(BTNode *b) {\n    BTNode *p;     SqQueue *qu;\n    InitQueue(qu);                  //初始化队列\n    enQueue(qu, b);                 //根结点指针进入队列\n    while (!QueueEmpty(qu) ) {      //队不为空，则循环\n        deQueue(qu, p);     //出队结点p\n        printf(\"%c \", p->data);     //访问结点p\n        if (p->lchild!=NULL) enQueue(qu, p->lchild);\n                                    //有左孩子时将其进队\n        if (p->rchild!=NULL) enQueue(qu, p->rchild);\n                                    //有右孩子时将其进队\n    }\n}","title":"LevelOrder","tokens":[[{"text":"void","darkColor":"#74CBC4"},{"text":" ","darkColor":"#DEDBD2"},{"text":"LevelOrder","darkColor":"#6EC0DF"},{"text":"(","darkColor":"#BAB5A8"},{"text":"BTNode ","darkColor":"#DEDBD2"},{"text":"*","darkColor":"#BAB5A8"},{"text":"b","darkColor":"#D5C5AA"},{"text":")","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"{","darkColor":"#BAB5A8"}],[{"text":"    BTNode ","darkColor":"#DEDBD2"},{"text":"*","darkColor":"#BAB5A8"},{"text":"p","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"},{"text":"     SqQueue ","darkColor":"#DEDBD2"},{"text":"*","darkColor":"#BAB5A8"},{"text":"qu","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"InitQueue","darkColor":"#6EC0DF"},{"text":"(","darkColor":"#BAB5A8"},{"text":"qu","darkColor":"#6EC0DF"},{"text":");","darkColor":"#BAB5A8"},{"text":"                  //初始化队列","darkColor":"#908B7E"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"enQueue","darkColor":"#6EC0DF"},{"text":"(","darkColor":"#BAB5A8"},{"text":"qu","darkColor":"#6EC0DF"},{"text":",","darkColor":"#BAB5A8"},{"text":" b","darkColor":"#6EC0DF"},{"text":");","darkColor":"#BAB5A8"},{"text":"                 //根结点指针进入队列","darkColor":"#908B7E"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"while","darkColor":"#8EA4E2"},{"text":" ","darkColor":"#DEDBD2"},{"text":"(","darkColor":"#BAB5A8"},{"text":"!","darkColor":"#8EA4E2"},{"text":"QueueEmpty","darkColor":"#6EC0DF"},{"text":"(","darkColor":"#BAB5A8"},{"text":"qu","darkColor":"#6EC0DF"},{"text":")","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":")","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"{","darkColor":"#BAB5A8"},{"text":"      //队不为空，则循环","darkColor":"#908B7E"}],[{"text":"        ","darkColor":"#DEDBD2"},{"text":"deQueue","darkColor":"#6EC0DF"},{"text":"(","darkColor":"#BAB5A8"},{"text":"qu","darkColor":"#6EC0DF"},{"text":",","darkColor":"#BAB5A8"},{"text":" p","darkColor":"#6EC0DF"},{"text":");","darkColor":"#BAB5A8"},{"text":"     //出队结点p","darkColor":"#908B7E"}],[{"text":"        ","darkColor":"#DEDBD2"},{"text":"printf","darkColor":"#6EC0DF"},{"text":"(","darkColor":"#BAB5A8"},{"text":"\"","darkColor":"#94C977"},{"text":"%c","darkColor":"#E2B159"},{"text":" \"","darkColor":"#94C977"},{"text":",","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#6EC0DF"},{"text":"p","darkColor":"#EEECE6"},{"text":"->","darkColor":"#BAB5A8"},{"text":"data","darkColor":"#EEECE6"},{"text":");","darkColor":"#BAB5A8"},{"text":"     //访问结点p","darkColor":"#908B7E"}],[{"text":"        ","darkColor":"#DEDBD2"},{"text":"if","darkColor":"#8EA4E2"},{"text":" ","darkColor":"#DEDBD2"},{"text":"(","darkColor":"#BAB5A8"},{"text":"p","darkColor":"#EEECE6"},{"text":"->","darkColor":"#BAB5A8"},{"text":"lchild","darkColor":"#EEECE6"},{"text":"!=","darkColor":"#BAB5A8"},{"text":"NULL","darkColor":"#E2B159"},{"text":")","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"enQueue","darkColor":"#6EC0DF"},{"text":"(","darkColor":"#BAB5A8"},{"text":"qu","darkColor":"#6EC0DF"},{"text":",","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#6EC0DF"},{"text":"p","darkColor":"#EEECE6"},{"text":"->","darkColor":"#BAB5A8"},{"text":"lchild","darkColor":"#EEECE6"},{"text":");","darkColor":"#BAB5A8"}],[{"text":"                                    ","darkColor":"#BAB5A8"},{"text":"//有左孩子时将其进队","darkColor":"#908B7E"}],[{"text":"        ","darkColor":"#DEDBD2"},{"text":"if","darkColor":"#8EA4E2"},{"text":" ","darkColor":"#DEDBD2"},{"text":"(","darkColor":"#BAB5A8"},{"text":"p","darkColor":"#EEECE6"},{"text":"->","darkColor":"#BAB5A8"},{"text":"rchild","darkColor":"#EEECE6"},{"text":"!=","darkColor":"#BAB5A8"},{"text":"NULL","darkColor":"#E2B159"},{"text":")","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"enQueue","darkColor":"#6EC0DF"},{"text":"(","darkColor":"#BAB5A8"},{"text":"qu","darkColor":"#6EC0DF"},{"text":",","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#6EC0DF"},{"text":"p","darkColor":"#EEECE6"},{"text":"->","darkColor":"#BAB5A8"},{"text":"rchild","darkColor":"#EEECE6"},{"text":");","darkColor":"#BAB5A8"}],[{"text":"                                    ","darkColor":"#BAB5A8"},{"text":"//有右孩子时将其进队","darkColor":"#908B7E"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"}","darkColor":"#BAB5A8"}],[{"text":"}","darkColor":"#BAB5A8"}]]}}]},{"id":"fc8ab420-d28f-4663-8f07-abb77f6ea5ba","topic":"由遍历序列构造二叉树","expanded":true,"children":[{"id":"a937cc6b-b0cf-4133-9dac-d770d9748072","topic":"二叉树的先序（或后序）序列和中序序列可以唯一确定一颗二叉树","expanded":true,"children":[{"id":"48a72668-f967-4b97-999c-b56cbb5ee03d","topic":"这样构造一颗二叉树的算法题还挺多的","expanded":true}]}]},{"id":"9799f0eb-c23d-40fd-ae42-eaa0e750a51e","topic":"用二叉树表示算术表达式，将算术表达式转变为二叉树","expanded":true,"children":[{"id":"dee6f4a8-ad04-448d-a109-3abe15cd809a","topic":"先序遍历对应前缀表示","expanded":true},{"id":"6d595fda-56b1-4fd1-a9ea-c022eb825d82","topic":"中序遍历对应中缀表示","expanded":true},{"id":"81e02f04-0116-4160-912a-d4e60a33e081","topic":"后序遍历对应后缀表示","expanded":true}]},{"id":"12c1d930-fa77-47bf-bdd6-d9266b3c4f36","topic":"递归算法和非递归算法的转换：利用栈进行实现","expanded":true,"children":[{"id":"3930f434-5cb4-4879-bd38-80b6817769df","topic":"非递归中序遍历 InOrder2","expanded":true,"code":{"lang":"c","code":"void InOrder2(BiTree T){\nInitStack(S); BiTree p=T;          //初始化栈 S；p是遍历指针\n    while(p||!IsEmpty(S)){         //栈不空或p不空时循环\n        if(p){                     //一路向左\n            Push(S,p);             //当前结点入栈\n            p=p->lchild;           //左孩子不空，一直向左走\n        }\n        else{                      //出栈，并转向出栈结点的右子树\n            Pop(S,p);visit(p);     //栈顶元素出栈，访问出栈结点\n            p=p->rchild;           //向右子树走，p赋值为当前结点的右孩子\n        }                          //返回 while 循环继续进入 if-else 语句\n    }\n}","title":"InOrder2","tokens":[[{"text":"void","darkColor":"#74CBC4"},{"text":" ","darkColor":"#DEDBD2"},{"text":"InOrder2","darkColor":"#6EC0DF"},{"text":"(","darkColor":"#BAB5A8"},{"text":"BiTree ","darkColor":"#DEDBD2"},{"text":"T","darkColor":"#D5C5AA"},{"text":"){","darkColor":"#BAB5A8"}],[{"text":"InitStack","darkColor":"#6EC0DF"},{"text":"(","darkColor":"#BAB5A8"},{"text":"S","darkColor":"#6EC0DF"},{"text":");","darkColor":"#BAB5A8"},{"text":" BiTree p","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":"T","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"},{"text":"          //初始化栈 S；p是遍历指针","darkColor":"#908B7E"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"while","darkColor":"#8EA4E2"},{"text":"(","darkColor":"#BAB5A8"},{"text":"p","darkColor":"#DEDBD2"},{"text":"||!","darkColor":"#8EA4E2"},{"text":"IsEmpty","darkColor":"#6EC0DF"},{"text":"(","darkColor":"#BAB5A8"},{"text":"S","darkColor":"#6EC0DF"},{"text":")){","darkColor":"#BAB5A8"},{"text":"         //栈不空或p不空时循环","darkColor":"#908B7E"}],[{"text":"        ","darkColor":"#DEDBD2"},{"text":"if","darkColor":"#8EA4E2"},{"text":"(","darkColor":"#BAB5A8"},{"text":"p","darkColor":"#DEDBD2"},{"text":"){","darkColor":"#BAB5A8"},{"text":"                     //一路向左","darkColor":"#908B7E"}],[{"text":"            ","darkColor":"#DEDBD2"},{"text":"Push","darkColor":"#6EC0DF"},{"text":"(","darkColor":"#BAB5A8"},{"text":"S","darkColor":"#6EC0DF"},{"text":",","darkColor":"#BAB5A8"},{"text":"p","darkColor":"#6EC0DF"},{"text":");","darkColor":"#BAB5A8"},{"text":"             //当前结点入栈","darkColor":"#908B7E"}],[{"text":"            p","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":"p","darkColor":"#EEECE6"},{"text":"->","darkColor":"#BAB5A8"},{"text":"lchild","darkColor":"#EEECE6"},{"text":";","darkColor":"#BAB5A8"},{"text":"           //左孩子不空，一直向左走","darkColor":"#908B7E"}],[{"text":"        ","darkColor":"#DEDBD2"},{"text":"}","darkColor":"#BAB5A8"}],[{"text":"        ","darkColor":"#DEDBD2"},{"text":"else","darkColor":"#8EA4E2"},{"text":"{","darkColor":"#BAB5A8"},{"text":"                      //出栈，并转向出栈结点的右子树","darkColor":"#908B7E"}],[{"text":"            ","darkColor":"#DEDBD2"},{"text":"Pop","darkColor":"#6EC0DF"},{"text":"(","darkColor":"#BAB5A8"},{"text":"S","darkColor":"#6EC0DF"},{"text":",","darkColor":"#BAB5A8"},{"text":"p","darkColor":"#6EC0DF"},{"text":");","darkColor":"#BAB5A8"},{"text":"visit","darkColor":"#6EC0DF"},{"text":"(","darkColor":"#BAB5A8"},{"text":"p","darkColor":"#6EC0DF"},{"text":");","darkColor":"#BAB5A8"},{"text":"     //栈顶元素出栈，访问出栈结点","darkColor":"#908B7E"}],[{"text":"            p","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":"p","darkColor":"#EEECE6"},{"text":"->","darkColor":"#BAB5A8"},{"text":"rchild","darkColor":"#EEECE6"},{"text":";","darkColor":"#BAB5A8"},{"text":"           //向右子树走，p赋值为当前结点的右孩子","darkColor":"#908B7E"}],[{"text":"        ","darkColor":"#DEDBD2"},{"text":"}","darkColor":"#BAB5A8"},{"text":"                          //返回 while 循环继续进入 if-else 语句","darkColor":"#908B7E"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"}","darkColor":"#BAB5A8"}],[{"text":"}","darkColor":"#BAB5A8"}]]}}]}]},{"id":"992d8958-6e0a-4e28-b079-fe047fab2baa","topic":"线索二叉树","expanded":true,"style":{"borderColor":"#E32C2D","branchColor":"#7B1FA2"},"children":[{"id":"98958f40-fc96-44ed-ac71-5c5f21d4cdf5","topic":"概念","expanded":true,"children":[{"id":"19db7980-37e9-4f3e-80e2-7460421a8f76","topic":"将结点空的指针指向其前驱和后继，这种改变指向的指针称为“线索”，加上线索的二叉树称为线索二叉树","expanded":true,"children":[{"id":"b3bfd2f7-53c4-41cc-88fd-53643828053c","topic":"方便找到前驱和后继","expanded":true},{"id":"0b70ddce-6402-4bed-8b19-e091b2a12abe","topic":"遍历可以不从根结点开始","expanded":true}]},{"id":"64530dd2-93f3-4b43-bf08-2261148eb44e","topic":"一种物理结构","expanded":true,"style":{"borderColor":"#EB4D3D"},"children":[{"id":"732aa358-e981-4032-b06a-e37362a94f76","topic":"二叉树内部的存储结构","expanded":true}]}]},{"id":"8fe9e6f2-0376-4f15-9bb1-7097be8ddc8a","topic":"结构","expanded":true,"children":[{"id":"b1d2b474-0be1-414f-b5db-1bb418d62db3","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-6ae806196f3d61.png","width":368.47,"height":83.67},"children":[{"id":"7e30c8a7-6157-46c3-9312-3e4359362888","topic":"1表线索，0表孩子","expanded":true}]}]},{"id":"757a6b3c-1840-4510-ab0f-2e8c467aadbf","topic":"线索二叉树的构造","expanded":true,"children":[{"id":"2a3e2811-5aef-4aa7-813a-773f556dded3","topic":"可以通过设置指针pre指向刚刚访问过的结点，指针p指向正在访问的结点，即pre指向p的前驱，从而找到前驱位置","expanded":true}]},{"id":"7bed2352-0ea0-48a2-a7ae-81f8740364ed","topic":"后序线索二叉树不能有效求后序后继","expanded":true,"style":{"borderColor":"#EB4D3D"}}]}]},{"id":"6dfb6fa3-279f-41c7-80d2-67ea71c17bd8","topic":"树和森林","expanded":true,"children":[{"id":"98700df8-8ffa-48e1-84ed-27d67ad4095c","topic":"树的存储结构","expanded":true,"style":{"borderColor":"#FF9F00"},"children":[{"id":"9a56af4e-84ed-4f4c-b208-6693971b1b29","topic":"双亲表示法","expanded":true,"children":[{"id":"088721b5-e813-4655-928e-dda4c7a4dd96","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-dd5459cb44a8f3.png","width":484,"height":738},"children":[{"id":"c5be586a-fce1-4abe-8425-bd4fbbd40b26","topic":"概念","expanded":true,"children":[{"id":"135b595a-0c0f-4065-9cc2-563b51fdb84b","topic":"采用一组连续空间来存储每个结点，同时每个结点设一个伪指针，指向双亲在数组的位置","expanded":true}]},{"id":"0a6a2713-c073-4fd5-a7e2-157db4bdb11b","topic":"优点","expanded":true,"children":[{"id":"afbec54d-277d-436d-a12a-b4ec21b9ab8e","topic":"访问结点的双亲快","expanded":true}]},{"id":"675a68be-6a58-4435-8b5a-b1b1447df39f","topic":"缺点","expanded":true,"children":[{"id":"f2145f1b-b79e-4747-b603-9349bb36245a","topic":"访问结点的孩子需要遍历整个结构","expanded":true}]}]}]},{"id":"fe5d2ecc-533e-4cc7-9660-47c93b02de2b","topic":"孩子表示法","expanded":true,"children":[{"id":"cfacab14-538d-45ae-8ca8-ec5cce90a2bd","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-ef58aec8e98616.png","width":640,"height":654},"children":[{"id":"78c3f205-3b8a-48e9-9535-3f47e4dee7fb","topic":"概念","expanded":true,"children":[{"id":"686f7e75-0c7e-4723-bc0a-d5d0fbff3d59","topic":"将每个结点的孩子都用单链表链接为一个线性结构","expanded":true}]},{"id":"cf0dd3ee-1175-47ae-8a02-3721d4ed60b5","topic":"优点","expanded":true,"children":[{"id":"e2d61a5a-8f41-4243-9069-cf29da5951de","topic":"访问孩子结点快","expanded":true}]},{"id":"4df294d7-efc0-401f-8de1-a65d80c71e7e","topic":"缺点","expanded":true,"children":[{"id":"40b2822f-5227-41c2-a731-6d8a147a0f4b","topic":"寻找双亲需要遍历n个结点中孩子链表指针域所指n个孩子链表（可为每个结点设parent域指向父结点）","expanded":true}]}]}]},{"id":"ab5a8551-3bf2-4f12-afed-2fa35911ca06","topic":"孩子兄弟表示法","expanded":true,"children":[{"id":"c88c190f-c926-42c7-acd6-fee0436e8135","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-7fd9c007df008b.png","width":534.3,"height":98.98},"children":[{"id":"21cafb09-c0d7-432a-ab66-1d6bbd2e4b21","topic":"概念","expanded":true,"children":[{"id":"2cc81cc0-9249-4bbd-b449-f4529a7be1c9","topic":"以二叉链表为存储结构，孩子兄弟表示法使每个结点包括：结点值、指向结点第一个孩子的左指针、指向结点下一个兄弟结点的右指针","expanded":true}]},{"id":"12035e2c-45b5-4f40-b098-8845c2c7a80e","topic":"优点","expanded":true,"children":[{"id":"80c1ad80-e5ae-4e5d-8588-f4a4ec1dd854","topic":"方便地实现树转换为二叉树的操作，易于查找结点的孩子","expanded":true}]},{"id":"816adb9f-b52a-40bb-b537-6ea51e64fc92","topic":"缺点","expanded":true,"children":[{"id":"d64f9366-e9b6-4bc5-bf19-e8cf3a0d9746","topic":"找双亲麻烦（可为每个结点设parent域指向父结点）","expanded":true}]}]}]}]},{"id":"96f9526e-30e8-414a-8b11-f61ddd2f2fda","topic":"树、森林与二叉树的转换","expanded":true,"style":{"borderColor":"#E32C2D","branchColor":"#EA8ABA"},"children":[{"id":"805a0a2d-e567-4ca1-a9ea-d4d24e885528","topic":"树转换成二叉树","expanded":true,"children":[{"id":"2a1b6e96-3c9d-4d3b-af06-c52e285e366e","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-8ff79448eef371.png","width":354.56,"height":157.65},"children":[{"id":"9e6d7e16-028d-400b-925c-a480d94fcabd","topic":"加线：在兄弟之间架一条线","expanded":true},{"id":"5e7f2316-780e-4ed1-a5fe-3d565e1ebfa3","topic":"抹线：对每个结点，除了左孩子外，去除其与其余孩子之间的关系","expanded":true},{"id":"fa6e347c-39c7-4902-9a45-7b62342aaaa2","topic":"旋转：以树的根结点为轴心，将树顺时针旋转45度","expanded":true}]}]},{"id":"45265b87-6bdd-4032-a535-ece50bdc5a0a","topic":"二叉树转换成树","expanded":true,"children":[{"id":"b787e6ea-142c-4b77-8e85-c5db1ef788f4","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-b8c45b378760f7.png","width":352.22,"height":168.48},"children":[{"id":"f75ee806-a21a-4273-9fa0-b888b46ad110","topic":"加线：若p结点是双亲结点的左孩子，则将p的右孩子，右孩子的右孩子......沿分支找到的所有右孩子，都与p的双亲连起来","expanded":true},{"id":"e9e49dbb-8a7c-46fc-a174-7eccd2ecba44","topic":"抹线：抹掉原二叉树中双亲与右孩子之间的连线","expanded":true},{"id":"28ea2e7d-b0a7-4ad7-9e5b-edf13e0770d7","topic":"调整：将结点按层次排序，形成树结构","expanded":true}]}]},{"id":"d414b87e-1b96-4ed2-96dc-cea9d387beae","topic":"森林转换成二叉树","expanded":true,"children":[{"id":"f5c18866-edd2-4cfe-88bc-a704451ad8bc","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-2124694e591340.png","width":340.07,"height":159.78},"children":[{"id":"18a044aa-9225-4947-ad9a-c4058c9726ce","topic":"将个棵树分别转换成二叉树","expanded":true},{"id":"4e233d3b-6e6a-45c0-9b2a-e669d37ffe89","topic":"将每棵树的根结点用线相连","expanded":true},{"id":"64b5678a-24f1-4416-9326-1d8e07c178f6","topic":"以第一课树根结点为二叉树的根，顺时针旋转即可","expanded":true}]}]},{"id":"25e08719-aa7f-4f7b-889d-7e7e8758e4ae","topic":"二叉树转换成森林","expanded":true,"children":[{"id":"74e05d1c-77ad-494f-a531-83611135f55e","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-efcfb9e74868d4.png","width":339.71,"height":168.34},"children":[{"id":"959126c8-3eb5-4bfe-b978-ad2ee899f7c4","topic":"抹线：将二叉树中根结点与其右孩子连线，及沿右分支搜索到的所有右孩子间连线全部抹掉","expanded":true},{"id":"0c5553be-64a7-4d98-bc0d-7349ea36417d","topic":"还原：将孤立的二叉树还原成树","expanded":true}]}]}]},{"id":"eb4b831a-5321-4a32-877d-65969a9b26ce","topic":"树和森林的遍历","expanded":true,"style":{"borderColor":"#E32C2D"},"children":[{"id":"99325b92-4bf4-46dd-bbb5-1d7c5c246c96","topic":"树","expanded":true,"children":[{"id":"7746eb83-4825-4809-bac6-5d0cb970ed2b","topic":"先根遍历","expanded":true,"children":[{"id":"4c120a7e-3f91-44f8-a986-b4cb4df750b1","topic":"若树非空，先访问根结点，再用先根遍历规则依次遍历根结点的每一颗子树","expanded":true},{"id":"beab7c13-a2d2-4acd-a3e2-bf01e19f2f49","topic":"其遍历序列与这棵树相应二叉树的先序序列相同","expanded":true}]},{"id":"19daa2c7-e65b-4e96-9d08-8bce2a644e12","topic":"后根遍历","expanded":true,"children":[{"id":"5a0de51f-9854-45c8-864d-ded9c0d7b51b","topic":"若树非空，先用后根遍历规则依次遍历根结点的每一颗子树，再访问根结点","expanded":true},{"id":"7cd68d07-b4b7-4bba-944c-c77a5cddf7ce","topic":"其遍历序列与这棵树相应二叉树的中序序列相同","expanded":true}]}]},{"id":"0d8826aa-2f3d-4ff6-a59e-0a5fab625483","topic":"森林","expanded":true,"children":[{"id":"a8f6aa72-eb24-4369-a441-872ce48b202c","topic":"先序遍历","expanded":true,"children":[{"id":"6d89de34-6ba4-48a2-a221-7019ea3ccb70","topic":"访问森林中第一棵树的根结点","expanded":true},{"id":"c849626a-5082-4546-a96f-83cf4c865948","topic":"先序遍历第一棵树中根结点的子树森林","expanded":true},{"id":"87d25f11-2167-4023-9418-8ced4f78e055","topic":"先序遍历除去第一棵树之后剩余树构成的森林","expanded":true}]},{"id":"188659c3-8f82-47ce-abcd-948a7b832825","topic":"中序遍历","expanded":true,"children":[{"id":"4c0dcbf5-aa75-42ae-b310-3d45ba9e05ee","topic":"中序遍历森林中第一棵树的根结点的子树森林","expanded":true},{"id":"3bc27501-4214-49a6-925c-475fb45a2fc0","topic":"访问第一棵树的根结点","expanded":true},{"id":"46fb1bf5-21cb-4709-91be-b2d1847e3d26","topic":"中序遍历除去第一棵树之后剩余树构成的森林","expanded":true}]}]},{"id":"a120603d-8f11-4f38-b3e3-2b3362c666f7","topic":"对应关系","expanded":true,"children":[{"id":"42282785-58a3-46ac-a665-0d57640fa432","topic":"树","expanded":true,"children":[{"id":"2ebda54e-f706-4731-bcb4-d41965430615","topic":"森林","expanded":true,"children":[{"id":"4d741a4c-ba6e-4e5f-ae95-dd4755e53999","topic":"二叉树","expanded":true}]}]},{"id":"0098ba37-7705-4753-b557-f3de56a9ad88","topic":"先根遍历","expanded":true,"children":[{"id":"2c7a0d05-ed2e-4229-948f-d01a6da506f8","topic":"先序遍历","expanded":true,"children":[{"id":"0578acba-7c89-4b6c-b486-cf97ce067ba3","topic":"先序遍历","expanded":true}]}]},{"id":"a136c3fa-83a3-493d-a89f-1430cadbb756","topic":"后根遍历","expanded":true,"children":[{"id":"f105d75a-bbf3-4241-8f68-27a6a0d95538","topic":"中序遍历","expanded":true,"children":[{"id":"a9dd4422-45dc-41c2-9c31-7b500e9e8dd1","topic":"中序遍历","expanded":true}]}]}]}]}]},{"id":"d864a5be-8bec-443b-90f8-16840154c6e0","topic":"哈夫曼树及其应用","expanded":true,"style":{"borderColor":"#E32C2D"},"children":[{"id":"93f6e5bd-3c80-46c4-a8b0-dcd2355efba6","topic":"基本概念","expanded":true,"children":[{"id":"72792890-f227-4fe9-9e18-035d3d44c41f","topic":"路径","expanded":true,"children":[{"id":"0a0a6db2-05d7-4d95-9a1d-f7dd851c5e98","topic":"从树中一个结点到另一个结点之间的分支构成这两个结点间的路径","expanded":true}]},{"id":"02daa92d-07c2-4c0f-9e53-20d962a98925","topic":"结点的路径长度","expanded":true,"children":[{"id":"41706d5a-dc9d-41e9-bc80-887a6d0ddd58","topic":"两结点间路径上的分支数","expanded":true}]},{"id":"1f4891c6-5e03-46f3-8a0d-d0917c2ac004","topic":"树的路径长度","expanded":true,"children":[{"id":"a73b278a-6c30-4a04-80ab-1bda451888bf","topic":"从树根到每个结点的路径长度之和","expanded":true}]},{"id":"758a0e4a-63ad-4853-b13e-059a92776962","topic":"权","expanded":true,"children":[{"id":"edb863e1-7280-4c10-bb5a-a18501c1977b","topic":"将树中结点赋给一个有着某种含义的数值，则这个数值称为该结点的权","expanded":true}]},{"id":"3bfac8fe-203e-47d1-821f-63538df12b32","topic":"结点的带权路径长度","expanded":true,"children":[{"id":"914697d2-8106-46af-b9cc-5b25d8d4526c","topic":"从根结点到该结点之间的路径长度与该结点的权的乘积","expanded":true}]},{"id":"3aa95806-47b2-4d00-ae39-e72f15a5b570","topic":"树的带权路径长度","expanded":true,"children":[{"id":"0a0adc6d-5089-42d8-9987-8f4399ec4aac","topic":"树中所有叶子结点的带权路径长度之和","expanded":true}]}]},{"id":"c569d996-52f5-4e2c-b628-3d48b3d9e57f","topic":"哈夫曼树的定义","expanded":true,"style":{"branchColor":"#15831C"},"children":[{"id":"499c579c-3ccc-4e48-9400-50813187f124","topic":"最优二叉树，带权路径长度（WPL）最短的二叉树","expanded":true}]},{"id":"01849b53-63d7-482e-b07b-1b321735cc42","topic":"哈夫曼树的构造","expanded":true,"children":[{"id":"598c6754-f837-4316-bb30-3d9f198ce40f","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-f7254acdb14051.png","width":385.74,"height":124.54},"children":[{"id":"c57ffe9a-da1a-41c3-b453-c7f4cff8f3b4","topic":"每次从合成后存在的结点中选出两个权最小的进行构造二叉树，直到所有结点均在树中","expanded":true}]}]},{"id":"2779d2d7-ca24-44ad-a403-41763a6c75d5","topic":"哈夫曼编码","expanded":true,"style":{"branchColor":"#15831C"},"children":[{"id":"dcd76cc7-c03b-40ea-97b9-29cd2590d877","topic":"哈夫曼树的应用，数据压缩编码技术，是最优前缀码","expanded":true},{"id":"386e9904-88bd-400c-816b-e19089011705","topic":"基本概念","expanded":true,"children":[{"id":"93d69093-38dc-43f0-b0fe-be764f904a84","topic":"固定长度编码：在数据通信中，对每个字符用等长二进制位表示","expanded":true},{"id":"27a1d66f-6f43-42a7-881a-aef514b1ecfa","topic":"可变长编码：对频率高的字符赋以短编码，而对频率较低的字符则赋以较长一些的编码，起到压缩效果","expanded":true},{"id":"f0cc8ad6-9480-49f0-95dc-b44fe82b6d21","topic":"前缀编码：没有一个编码是另一个编码的前缀","expanded":true}]},{"id":"a3d580b0-4244-4ff7-9013-519eb754d5cd","topic":"构造哈夫曼编码","expanded":true,"children":[{"id":"57f4aad8-9c55-40ae-94c7-bbac7f316fb8","topic":"将每个出现的字符当作一个独立的结点，其权值为它出现的频度（或次数），构造出对应的哈夫曼树","expanded":true},{"id":"cd61b1b7-ca30-431c-96ae-c39ea0e29347","topic":"将字符的编码解释为从根至该字符的路径上边标记的序列","expanded":true},{"id":"d7a60326-c607-4a7f-9a24-d5ed0992342f","topic":"其中边标记为0表示“转向左孩子”，标记为1表示“转向右孩子”","expanded":true}]}]},{"id":"f28c4b4b-1f15-478a-baee-370e0f313cd8","topic":"多叉哈夫曼树（题目考点，类比外部排序的知识点），补0结点（虚叶结点）","expanded":true}]},{"id":"fc496054-9542-4859-90c3-2127ed9901d9","topic":"并查集","expanded":true,"style":{"borderColor":"#E32C2D"},"children":[{"id":"48d4c866-4306-4448-888a-00599a508cbd","topic":"基本思路","expanded":true,"children":[{"id":"30764f5f-fa0a-426e-83af-c4a97b1ede37","topic":"存储结构","expanded":true,"children":[{"id":"44285f48-7a40-4e21-abf2-74586d428162","topic":"顺序存储，每个集合组织成一棵树，采用双亲表示法","expanded":true}]},{"id":"b319f9c4-400e-4f19-afd2-b5f751d4d99a","topic":"所有表示子集合的树，构成表示全集合的森林，存放在双亲表示数组内","expanded":true},{"id":"ef14442d-3412-40a7-b885-7fd1a42514c9","topic":"通常用数组元素的下标代表元素名，用根结点的下标代表子集合名","expanded":true}]},{"id":"c16b4efb-f593-4793-bc11-3c70b5bf26e6","topic":"优化","expanded":true,"style":{"branchColor":"#BA69C8"},"children":[{"id":"3cff183c-3203-4aba-95e0-7b8e083e905e","topic":"查\n并","expanded":true,"children":[{"id":"d8ad0472-0ea0-44fa-9d27-8be7f0637a19","topic":"O(n)\nO(n^2)","expanded":true,"children":[{"id":"e1b49dac-18a0-4649-bfc4-97e8749248d1","topic":"小树合并到大树","expanded":true,"children":[{"id":"36f324c0-a113-4533-b6b2-2e683b658500","topic":"O(log2n)\nO(nlog2n)","expanded":true,"children":[{"id":"908ff87c-d428-442b-b97d-cf324e5ffe18","topic":"压缩路径","expanded":true,"children":[{"id":"143a9c0a-3581-4a51-9a76-35d274be295f","topic":"O(d(n))\nO(nd(n))","expanded":true}]}]}]}]}]},{"id":"75264458-a332-4851-b718-20b4aab6ab02","topic":"压缩路径：查找路径上所有结点都直接挂根结点","expanded":true}]},{"id":"f65f3b2c-1427-49ea-9f63-2c4a84240385","topic":"并查集应用","expanded":true,"children":[{"id":"a07c0fa8-8620-483d-aa19-3f5d5e30ac5e","topic":"Cruskal算法、无向图的连通性、无向图是否有环","expanded":true}]},{"id":"af2b6907-5620-438e-ba3d-88695486ab7b","topic":"代码（巨无敌，就两行代码）","expanded":true,"style":{"branchColor":"#BA69C8"},"children":[{"id":"bb169ee7-e83f-4122-9dc5-1dc0a2ecebc1","topic":"原理：每个集合用一棵树表示。树根的编号就是整个集合的编号。每个节点存储它的父节点，p[x]表示x的父节点。\n血的教训!!!\n注意很多题目需要在合并时去最小值，若f数组存父亲值\nf[y]=min(f[x],f[y]),f[x]=min(f[x],f[y]);\n每次执行find操作，确实会让每个节点直接存根节点的值，之后查找的时间复杂度接近O(1)，但仅仅是接近，不一定全是1次找到，即之后查找要用find函数而不是直接f[]找。","expanded":true,"children":[{"id":"28a158d9-474f-4cd9-9afc-7e2242d088e1","topic":"const int N=100010;\nint n,m,p[N],j,k;\nstring str;\n//并查集核心代码，就两行！！！！\nint find(int x)\n{\n    if (p[x] != x) p[x] = find(p[x]);\n    return p[x];\n}\n//main函数给大家可以便于理解\nint main(){\n    scanf(\"%d%d\",&n,&m);\n    for(int i=1;i<n+1;i++) p[i]=i;\n    for(int i=0;i<m;i++){\n        cin>>str>>j>>k;\n        if(str==\"M\") p[find(j)]=find(k);\n        else if(find(j)==find(k))\n            printf(\"Yes\\n\");\n        else\n            printf(\"No\\n\");\n    }\n}","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-198b8408228c90.png","width":424.18,"height":405.36}}]}]}]}]}}