概念
二叉树是每个结点最多有两个子树的树结构。通常子树被称作“左子树”(left subtree)和“右子树”(right subtree)
因为每个节点最多只能有两个子节点,一颗深度为k的二叉树最大节点数为1+2+22+23+…+2k-1 = 2k-1
注意,树的深度为k意味着包括根节点在内一共有k+1层,因为根节点的深度为0,而某个节点的深度是该点到达根节点的最短路径长度,比如下图中G的深度为2,B深度为3
相关术语
Root | The top node in a tree. | 根 | 树的顶端结点 |
Child | A node directly connected to another node when moving away from the Root. | 孩子 | 当远离根(Root)的时候,直接连接到另外一个结点的结点被称之为孩子(Child); |
Parent | The converse notion of a child. | 双亲 | 相应地,另外一个结点称为孩子(child)的双亲(parent)。 |
Siblings | A group of nodes with the same parent. | 兄弟 | 具有同一个双亲(Parent)的孩子(Child)之间互称为兄弟(Sibling)。 |
Ancestor | A node reachable by repeated proceeding from child to parent. | 祖先 | 结点的祖先(Ancestor)是从根(Root)到该结点所经分支(Branch)上的所有结点。 |
Descendant | A node reachable by repeated proceeding from parent to child. | 子孙 | 反之,以某结点为根的子树中的任一结点都称为该结点的子孙(Ancestor)。 |
Leaf | A node with no children. | 叶子(终端结点) | 没有孩子的结点(也就是度为0的结点)称为叶子(Leaf)或终端结点。 |
Branch | A node with at least one child. | 分支(非终端结点) | 至少有一个孩子的结点称为分支(Branch)或非终端结点。 |
Degree | The number of sub trees of a node. | 度 | 结点所拥有的子树个数称为结点的度(Degree)。 |
Edge | The connection between one node and another. | 边 | 一个结点和另一个结点之间的连接被称之为边(Edge)。 |
Path | A sequence of nodes and edges connecting a node with a descendant. | 路径 | 连接结点和其后代的结点之间的(结点,边)的序列。 |
Level | The level of a node is defined by 0 + (the number of connections between the node and the root). | 层次 | 结点的层次(Level)从根(Root)开始定义起,根为第0层,根的孩子为第1层。以此类推,若某结点在第i层,那么其子树的根就在第i+1层。 |
Height of node | The height of a node is the number of edges on the longest path between that node and a leaf. | 结点的高度 | 结点的高度是该结点和某个叶子之间存在的最长路径上的边的个数。 |
Height of tree | The height of a tree is the height of its root node. | 树的高度 | 树的高度是其根结点的高度。 |
Depth of node | The depth of a node is the number of edges from the tree's root node to the node. | 结点的深度 | 结点的深度是从树的根结点到该结点的边的个数。(注:树的深度指的是树中结点的最大层次。) |
Forest | A forest is a set of n ≥ 0 disjoint trees. | 森林 | 森林是n(>=0)棵互不相交的树的集合。 |
-
满二叉树
a binary tree T is full if each node is either a leaf or possesses exactly two childnodes.
一个二叉树,如果每一个层的结点数都达到最大值,则这个二叉树就是满二叉树。- 国内定义:
- 一个层数为k的满二叉树,结点总数必为2k -1 。其形状必定如此 , 结点数一定是奇数个
- 第i层上的结点数为:2i-1
-
国外定义:
满二叉树的结点要么是叶子结点,度为0,要么是度为2的结点,不存在度为1的结点。美国NIST给出的定义为:A binary tree in which each node has exactly zero or two children. In other words, every node is either a leaf or has two children. For efficiency, any Huffman coding is a full binary tree.
即长成这个样子也算是满二叉树:
参考资料:
[1] https://baike.baidu.com/item/%E4%BA%8C%E5%8F%89%E6%A0%91/1602879
[2] https://blog.csdn.net/qq_22642239/article/details/80774013
[3] https://baike.baidu.com/item/%E6%BB%A1%E4%BA%8C%E5%8F%89%E6%A0%91/7773283
[4]https://baike.baidu.com/item/%E5%AE%8C%E5%85%A8%E4%BA%8C%E5%8F%89%E6%A0%91/7773232