Professional Documents
Culture Documents
Data Structure Tree - 2
Data Structure Tree - 2
• a binary tree
– empty tree having zero nodes
– consist of a root and two disjoint binary tree
(left subtree and right subtree)
Binary tree
Binary search tree
2
The abstract data type(cont.)
3
The abstract data type (Cont.)
4
The abstract data type (C
• a skewed binary tree: Figure 5.10(a)
• a complete binary tree: Figure 5.10(b)
5
Properties of binary trees
• Lemma 5.2 [Maximum number of nodes]
1) maximum number of nodes on level i of a binary tree: 2i-1
2) maximum number of nodes in a binary tree of depth k : 2k – 1
• reading the proof
• Lemma 5.3
[Relation between # of leaf nodes and degree-2
nodes]
– n0: # of leaf nodes
– n2: # of nodes of degree 2
– n0 = n 2 + 1
6
Properties of binary trees
(Cont.)
• Lemma 5.3 [Relation between # of leaf nodes and
degree-2 nodes] (Cont.)
– Proof:
• n1 : # of nodes of degree one
• n : the total number of nodes
• n = n0 + n1 + n2 ----- (5.1)
• B : the number of branches
• n=B+1
– every node except the root has a branch leading into it
• B = n1 + 2n2
• n = B + 1 = n1 + 2n2 + 1 ----- (5.2)
• n0 = n2 + 1 from Eq. 5.1 and 5.2
7
Properties of binary trees
(Cont.)
• Definition: a binary tree with n nodes and depth k is complete iff its
nodes correspond to the nodes numbered from 1 to n in the full binary
tree of depth k