【總結】二叉樹概念大總結

九章演算法發表於2017-04-26

專欄 | 九章演算法
網址 | 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教育領域的深耕者

相關文章