Presentation tree traversal
-
Upload
ayesha-tahir -
Category
Technology
-
view
55 -
download
1
Transcript of Presentation tree traversal
PRESENTED TO:
MA’M AMNA
PRESENTED BY
ROLL # 1430303MOMINA IDREES
ROLL # 1430278AYESHA TAHIR
ROLL # 1430328UME AYMEN
ROLL # 1430324SOHA NAEEM
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.
BINARY TREEA
B C
D EF
G
TREE TRAVERSALTRAVERSAL REFERS TO THE
PROCESS OF VISITING (EXAMINING AND/OR
UPDATING) EACH NODE IN A TREE DATA STRUCTURE,
EXACTLY ONCE.
To traverse a non empty binary tree in in-order following three operations are performed Traverse the left sub –tree in in-orderVisit the root nodeTraverse the right sub-tree in in-order
A
B C
D EF 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
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-orderTraverse the right sub-tree in post-orderVisit the root node
A
B C
DE 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 FSince 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
a non empty binary tree in pre-order following three operations are performed To traverse Visit the root nodeTraverse the left sub –tree in pre-orderTraverse the right sub-tree in pre-order
PRE-ORDER TRAVERSAL
A
B C
D EF G
Printing the data in pre-order traversal
Traversal starts from the root nodeThe 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