diff --git a/.obsidian/app.json b/.obsidian/app.json index 9856d35..62c8452 100644 --- a/.obsidian/app.json +++ b/.obsidian/app.json @@ -3,5 +3,6 @@ "showFrontmatter": true, "showUnsupportedFiles": true, "newLinkFormat": "relative", - "alwaysUpdateLinks": true + "alwaysUpdateLinks": true, + "attachmentFolderPath": "./" } \ No newline at end of file diff --git a/.obsidian/backlink.json b/.obsidian/backlink.json new file mode 100644 index 0000000..48ee913 --- /dev/null +++ b/.obsidian/backlink.json @@ -0,0 +1,3 @@ +{ + "backlinkInDocument": true +} \ No newline at end of file diff --git a/.obsidian/switcher.json b/.obsidian/switcher.json new file mode 100644 index 0000000..e08b1c1 --- /dev/null +++ b/.obsidian/switcher.json @@ -0,0 +1,5 @@ +{ + "showExistingOnly": false, + "showAttachments": true, + "showAllFileTypes": true +} \ No newline at end of file diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json index 34d91b6..7f82518 100644 --- a/.obsidian/workspace.json +++ b/.obsidian/workspace.json @@ -7,18 +7,6 @@ "id": "18520963df8aa056", "type": "tabs", "children": [ - { - "id": "5afd0b6ff5387371", - "type": "leaf", - "state": { - "type": "markdown", - "state": { - "file": "4.串/串.md", - "mode": "source", - "source": false - } - } - }, { "id": "de3f9d04c35ed5ff", "type": "leaf", @@ -27,12 +15,12 @@ "state": { "file": "树/树.md", "mode": "source", + "backlinks": true, "source": false } } } - ], - "currentTab": 1 + ] } ], "direction": "vertical" @@ -105,7 +93,7 @@ "showSearch": false, "searchQuery": "", "backlinkCollapsed": false, - "unlinkedCollapsed": false + "unlinkedCollapsed": true } } }, @@ -150,8 +138,7 @@ "state": {} } } - ], - "currentTab": 3 + ] } ], "direction": "horizontal", @@ -174,8 +161,11 @@ }, "active": "de3f9d04c35ed5ff", "lastOpenFiles": [ + "树/pic/Pastedimage20230810154259.png", "4.串/串.md", + "树/pic/Pastedimage2230810153842.png", "树/树.md", + "树/pic", "树", "3.栈、队列、数组/栈、队列、数组.md", "4.串", diff --git a/树/pic/Pastedimage20230810154259.png b/树/pic/Pastedimage20230810154259.png new file mode 100644 index 0000000..56288b3 Binary files /dev/null and b/树/pic/Pastedimage20230810154259.png differ diff --git a/树/pic/Pastedimage2230810153842.png b/树/pic/Pastedimage2230810153842.png new file mode 100644 index 0000000..baad7bb Binary files /dev/null and b/树/pic/Pastedimage2230810153842.png differ diff --git a/树/树.md b/树/树.md index 85d3ee0..d05e869 100644 --- a/树/树.md +++ b/树/树.md @@ -1,13 +1,89 @@ ## 树 +### 1. 树的基本概念 + +树是 $n(n \geq 0)$ 个结点的有限集合,$n=0$ 时,称为空树。 + +而任意非空树应满足: + +1. 有且仅有一个特定的称为**根**的结点。 +2. 当 $n>0$ 时,其余结点可分为 $m(m \geq 0)$ 个互不相交的有限集合,其中每一个集合本身又是一棵树,称为根结点的**子树**。 + +$n$ 个结点的树中只有 $n-1$ 条边。 + +### 2. 基本术语 + +- 祖先结点和子孙结点 +- 双亲结点和孩子结点 +- 兄弟结点 +- (结点的)度:树中一个结点的**子结点的个数**称为该结点的度。 +- (树的)度:树中最大度数。 +- 分支结点:度大于 $0$ 的结点。 +- 叶子结点:度为 $0$ 的结点。 +- 结点的层次:根结点为第一层(或第零层)。 +- 结点的高度:从叶子结点(第一层)开始逐层累加。 +- 结点的深度:从根结点(第一层)开始逐层累加。 +- 树的高度(深度)是树中结点的最大层数。 +- 有序树和无序树 +- 路径:树中两个结点之间的路径是由这两个结点之间所经过的**结点序列**构成的。(树的分支是有向的,即从双亲结点指向孩子结点,所以路径一定是自上而下的。) +- 路径长度:路径上所经过**边**的个数。 +- 森林:$m(m \geq 0)$ 棵互不相交的树的集合。 + +### 3. 树的性质 + +- 树中结点树等于所有结点的度加 $1$。 +- 度为 $m$ 的树中第 $i$ 层上至少有 $m^{i-1}$ 个结点($i \geq 1$)。 +- 高度为 $h$ 的 $m$ 叉树至多有 $(m^h-1)/(m-1)$ 个结点。 +- 具有 $n$ 个结点的 $m$ 叉树的最小高度为:$\left \lceil log_m(n(m-1)+1) \right \rceil$。 + +性质二说明: + +- 第一层:$1=m^0$ +- 第二层:$1=m^1$ +- 第三层:$1=m^2$ +- ... +- 第 $i$ 层:$1=m^{i-1}$ + + ## 二叉树 +二叉树是 $n(n \geq 0)$ 个结点的有限集合。 +二叉树是有序树 +1. $n=0$ 时,二叉树为空。 +2. $n>0$ 时,由根结点和两个互不相交的被称为根的左子树和右子树组成。左子树和右子树也分别是一棵二叉树。 +- 空树 +- 仅有根结点 +- 根结点+左子树 +- 根结点+右子树 +- 根结点+左子树+右子树 +二叉树 VS 度为 2 的有序树 +- 二叉树可以为空,而度为 2 的有序树至少有三个结点。 +- 二叉树的孩子结点始终有左右之分,而度为 2 的有序树孩子结点的次序是相对的。 +### 特殊二叉树 +#### 满二叉树 +一颗高度为 $h$,且含有 $2^h-1$ 个结点的二叉树称为满二叉树。(高度为 $h$ 的 $m$ 叉树至多有 $(m^h-1)/(m-1)$ 个结点。) + +对于编号为 $i$ 的结点,若存在,其双亲结点的编号为:$\left \lfloor i/2 \right \rfloor$,左孩子编号为:$2i$,右孩子编号为:$2i+1$。 +![[pic/Pastedimage2230810153842.png]] +#### 完全二叉树. +设一个高度为 $h$、有 $n$ 个结点的二叉树,当且仅当每个结点都与高度为 $h$ 的满二叉树中编号 $1 \sim n$ 的结点一一对应时,称为完全二叉树。 +- 若 $i<[n/2]$,则结点 $i$ 为分支结点,否则为叶子结点。 +- 叶子结点只可能出现在层次最大的两层上出现。对于最大层次的叶子结点,都依次排在最左边的位置上。 +- 度为 $1$ 的结点若存在,则可能有一个,且是编号最大的分支结点,并孩子结点一定是左结点。 +- ![[pic/Pastedimage20230810154259.png]] +#### 二叉排序树 +一颗二叉树,若树非空,则有如下性质: + +对任意结点若存在左子树或右子树,则其左子树上所有结点的关键字均小于该结点。右子树上所有结点的关键字均大于该结点。 + +#### 平衡二叉树 +树上**任意结点**的左子树和右子树的深度之差不超过 $1$。 ## 森林