The document defines and discusses binary trees and different methods of traversing them. It provides definitions for binary tree as a finite set of nodes where each node has no more than two children. It also defines the three different traversal methods for binary trees - in-order, pre-order and post-order traversal. Examples of applying each traversal method to a sample binary tree are given to illustrate the traversal process.
7. Binary tree->binary tree is
defined as finite set of node
in which number of the
children of a node should not
exceed more than two .it
means the degree of binary
tree not then greater then
two.
9. TREE TRAVERSAL
TRAVERSAL REFERS TO THE
PROCESS OF VISITING
(EXAMINING AND/OR
UPDATING) EACH NODE IN
A TREE DATA STRUCTURE,
EXACTLY ONCE.
10. To traverse a non empty binary tree in in-
order following three operations are
performed
Traverse the left sub tree in in-order
Visit the root node
Traverse the right sub-tree in in-order
A
B C
D E
F
G
TRVERSE STARTS FROM THE ROOT NODESince D is the leaf node ,it gets printed ,which is
the left child of D.
D
Now B gets printed as it is the
parent of the node D
B
Since E is the leaf node ,it gets printed ,which is
right child of B
E
Now A gets printed as it is the parent of the
node B
A
Since F is the leaf node ,it gets printed
,which is the left child of c
F
Now C gets printed as it is the parent of
the node F
C
Since G is leaf node ,it gets printed ,which the
right child of C
G
IN ORDER TRAVERSAL
11. POST -ORDER TRAVERSALPrinting the data in post-order traversal
To traverse a non empty binary tree in
post-order following three operations are
performed
Traverse the left sub tree in post-order
Traverse the right sub-tree in post-
order
Visit the root node
A
B C
D
E F G
0
Now A gets printed as it is the parent of the
node B
Now C gets printed as it is the parent of the node
F
Since D is the leaf node ,it gets printed ,which is
the left child of D.
TRVERSE STARTS FROM THE ROOT NODENow B gets printed as it is the parent of
the node D
D E B
Now F gets printed as it is the left child of C
F G C A
Since E is the leaf node ,it gets printed
,which is right child of BNow G gets printed ,as it is the right child of C
12. a non empty binary tree in pre-order
following three operations are
performed To traverse
Visit the root node
Traverse the left sub tree in pre-
order
Traverse the right sub-tree in pre-
order
PRE-ORDER TRAVERSAL
A
B C
D E
F G
Printing the data in pre-order traversal
Traversal starts from the root node
The data at the root node i.e. A gets printed
A
Since D is the leaf node ,it gets printed ,which is
the left child of B.
D
Now B gets printed as it is the parent of the
node D
B
Since E is the leaf node ,it gets printed ,
which is right child of B
E
Now C gets printed as it is the parent of
the node F
C
Since F is the leaf node ,it gets printed ,
which is the left child of c
F
Since G is leaf node ,it gets printed ,
which the right child of C
G