6 Tree 2
6 Tree 2
Tree Part-2
Tree Traversal
The most common operations performed on tree structure is that of traversal.
This is a procedure by which each node in the tree is processed exactly once in a systematic
manner.
There are three ways of traversing a binary tree. A
1. Preorder Traversal
2. Inorder Traversal B D
3. Postorder Traversal
C E G
A B C D E F G
C ✓ E ✓ G ✓
F ✓
C B A E F D G
C ✓ E ✓ G ✓
F ✓
2 3 25 75
3 1
6 22
4 22 40 60 80
5 45
5 15 30 90
23 65
34 78
A
B D
B D
C E G
C E G
F
F
Node structure of binary tree is described as below Typical node of Binary Tree
Node structure of binary tree is described as below. Typical node of Binary Tree
Node structure of binary tree is described as below. Typical node of Binary Tree
Postorder : G D B H I E F C A
A A
Inorder : D G B AA H E I C F
B C B C
A
D,G H,E,I F D E F
D,G,B H,E,I,C,F
G H I
G G G
QBKCFA PED HR B P B P
D Q A D
Q A
G
C E R
B KCF E HR
P
K F H
Q KCFA ED HR
A
B D
B D
C E G
C E G
F
F
Because the left or right link of a node can denote either structural link or a thread, we must
somehow be able to distinguish them
B D
A
C E G
B D
C E G
Inorder Traversal
C B A E F D G
F
B E
A
C D F H
B E
G
Inorder Traversal
C D F H
CBDAFGEH
G
50
25 75
22 40 60 80
15 30 90
Delete node a
a Delete node a b
Delete node a
a C
b C