Data Structures Using C, 2e Reema Thareja: © Oxford University Press 2014. All Rights Reserved
Data Structures Using C, 2e Reema Thareja: © Oxford University Press 2014. All Rights Reserved
C, 2e
Reema Thareja
T1 T2
2 3
B C G H
D I
E J
• Copies of binary trees: Two binary trees T and T’ are said to be copies if they
have similar structure and same content at the corresponding nodes.
TREE T
TREE T”
A A
B C B C
E
D E D
For example, the children of node 4 are 8 (2*4) and 9 (2* 4 + 1). 2 3
8 9 1 1 1 1
0 1 2 3
Binary tree
int data; 4 5 6 7
};
15 35
12 3
17 21 9
3 4
16 18
6 5
- *
a b c d
a e
a
d e g
a b c d e f g h
• There are three different algorithms for tree traversals, which differ in
the order in which the nodes are visited.
Pre-order algorithm
In-order algorithm
Post-order algorithm
D E
A, B, D, C, E, F, G, H and I
F
H I
D E
B, D, A, E, H, G, I, F and C
G
H I
D E
D, B, H, I, G, F, E, C and A G
H I