【总结】二叉树概念大总结

1,003 阅读2分钟

专栏 | 九章算法
网址 | www.jiuzhang.com



树的很多概念非常confusing,让主页群带大家来过一遍五花八门的树的概念吧

(一)
About the Tree: full binary tree: A binary tree in which each node has exactly zero or two children.

Perfect binary tree: A binary tree with all leaf nodes at the same depth. All internal nodes have degree 2 [1]

满二叉树:每个节点都有0或是2个孩子。

完美二叉树:所有的叶子都拥有同的深度,所有的内部节点拥有 2个孩子


(二)
The difference between Full Binary Tree & Complete Binary Tree:
(1). a binary tree T is full if each node is either a leaf or possesses exactly two child nodes.
(2). a binary tree T with n levels is complete if all levels except possibly the last are completely full, and the last level has all its nodes to the left side. [2]

满二叉树和完全二叉树的区别:

满二叉树:是每个节点要不是叶子要不拥有 2个孩子

完全二叉树:每一层都是完全的,除了最后一层,而最后一层所有的节点都在左边。


(三)
AVL Trees: AVL trees are self-balancing binary search trees. These trees are named after their two inventors G.M. Adel’son-Vel’skii and E.M. Landis. [3]

The height/depth of a tree:
The height of a node is the length of the longest downward path to a leaf from that node. The height of the root is the height of the tree.

The depth of a node is the length of the path to its root (i.e., its root path).


(四)
This is commonly needed in the manipulation of the various self-balancing trees, AVL Trees in particular. The root node has depth zero, leaf nodes have height zero, and a tree with only a single node (hence both a root and leaf) has depth and height zero. Conventionally, an empty tree (tree with no nodes, if such are allowed) has depth and height −1.[4]

根的深度为0,叶子高度为0.只有一个节点的树的depth height 都为0.

按照惯例,一个空树的depth, height 都是-1

参考资料:

  1. xlinux.nist.gov/dads//HTML/…
  2. courses.cs.vt.edu/~cs3114/Fal…
  3. courses.csail.mit.edu/6.006/fall0…
  4. www.cs.cmu.edu/~adamchik/1…


欢迎关注我的微信公众号:九章算法(ninechapter)。
精英程序员交流社区,定期发布面试题、面试技巧、求职信息等

九章算法,IT教育领域的深耕者