2.1 - Tree
介紹Tree的定義及其表示法
1. 定義
Tree是由n個節點(node)所構成之集合,不可為空。
至少有一個Root
其餘的節點可分為T1~Tm個互斥集合,稱為Root的子樹(subtree)。
2. 術語
Degree of nodes
Degree of A = 3
Degreee of B = 2
Leaf: Degree = 0
Non-leaf: A, B, E, G
Child: B is a child of A
Parent: A is the parent of B
Sibling: 有相同Parent彼此稱之
Ancestors & Descendants
Level of nodes
Degree of a Tree = Max(degrees of nodes)
Height of a Tree = Max(levels of nodes)
Forest: >=0個互斥的樹所形成之集合。
3. 表示法
1. 使用Link List表示
Nodes = n , Degree of tree = k
Available links = n-1(扣掉root,其他節點都有一個有用的Link)
Empty links = n*k - (n-1)
非常浪費空間的表示法。
2. 使用Binary Tree表示。
3. Sibling-Child表示法。
節點中的child指標指向leftmost-child(A->B)
節點中的sibling指標指向right-sibling(B->C, C->D)
4. 括號法
A(B(CD)E(F)G(HIJ))
Last updated