Professional Documents
Culture Documents
Binary Tree
Binary Tree Properties
Binary Tree Traversal Methods
Binary Tree Representation
Binary Tree
A binary tree is a finite set of nodes that is
either empty or consists of a root and two
disjoint binary trees called the left subtree
and the right subtree.
A nonempty binary tree has a root element.
The remaining elements (if any) are partitioned
into two binary trees.
These are called the left and right subtrees of
the binary tree.
Differences Between A Tree & A Binary Tree
b b
* +
e f
+ -
a b c d
Properties of Binary Tree
• Before Examining data representation
for binary tree, let us make some
observation about BT,
• In Particular, we want to determine the
maximum number of nodes in a binary
tree of depth k and the relationship
between the number of leaf nodes and
the number of degree-two nodes in
binary tree
Minimum Number Of Nodes
Minimum number of nodes in a binary
tree whose height is h.
At least one node at each of first h
levels.
minimum number of
nodes is h
Maximum Number of Nodes in BT
The maximum number of nodes on level i of a
binary tree is 2i-1, i>=1.
i 1
Relations between Number of
Leaf Nodes and Nodes of Degree 2
B C
D E F G
H I
Complete binary tree
Full Binary Tree
A full binary tree of a given height h has 2h – 1
nodes.
2 3
4 5 6 7
8 9 10 11 12 13 14 15
Node Number Properties
1
2 3
4 5 6 7
8 9 10 11 12 13 14 15
2 3
4 5 6 7
8 9 10 11 12 13 14 15
B C B C
D E F G D E F G
H I J K L M N O
H I
Array representation.
Linked representation.
Array Representation
Number the nodes using the numbering
scheme for a full binary tree. The node that
is numbered i is stored in tree[i].
a1
2 3
b c
4 5 6 7
d e f g
8 9 10
h i j
tree[] a b c d e f g h i j
0 5 10
Right-Skewed Binary Tree
a1
b 3
7
c
15
d
tree[] a - b - - - c - - - - - - - d
0 5 10 15
Array Representation
If a complete binary tree with n nodes is represented
sequentially, then for any node with index i, 1<i<n,
we have