Professional Documents
Culture Documents
Binary Trees
Binary Trees
Structures
Binary Trees
Binary Tree
Properties of Binary Trees
Binary Tree Representation
Operations on Binary Tree
Applications
Traversals
Binary Tree
3
D E F G
Differences Between A Tree & A Binary
5
Tree
The subtrees of a binary tree are ordered; those of
a tree are not ordered
a a
b b
depth 0
depth 3
Binary Trees
8
Full binary tree :
All internal nodes have two children.
Complete binary tree :
A complete binary tree is a binary tree in which every level,
except possibly the last, is completely filled, and all nodes are
as far left as possible.
<=20
21
22
23
What is a binary tree? (cont.)
10
minimum number of
nodes is h
Maximum Number Of Nodes
17
All possible nodes at first d depths are present
2 3
4 5 6 7
8 9 10 11 12 13 14 15
Node Number Properties
1
21
2 3
4 5 6 7
8 9 10 11 12 13 14 15
Parent of node j is node j/2
But node 1 is the root and has no parent
Left child of node j is node 2*j
But if 2*j>n, node j has no left child
Right child of node j is node2*j+1
But if 2*j+1>n, node j has no right child
Binary Tree Representation
22
Array representation
Linked representation
Array Representation
23
Number the nodes using the numbering scheme for a full binary tree
Store the node numbered i in tree[i]
Index 0 of array is left empty
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
24
tree[] a - b - - - c - - - - - - - d
0 5 10 15
Linked Representation
25
Each binary tree node is represented as an
object whose data type is NodeType
The space required by an n node binary tree is n
* (space required by one node)
Linked Representation of Binary Trees
26
b c
d e
g
f
leftChild
element h
rightChild
28
The End