Upload
raj-upadhyay
View
357
Download
2
Embed Size (px)
Citation preview
Traversal Techniques In Binary Tree
How to Find PRI-ORDER, IN-ORDER, POST-ORDER Traversal in TREE.
• As we all know there are certain rules (or manner) that we have to follow for Traversal in tree.
• Pri-Order :- Root, Left, Right. • In-Order :-Left, Root, Right.• Post-Order :-Left, Right, Root .
• Sometimes it’s confusing that what manner we have to follow for PRI-Oder, IN-Order, POSTER-Order Traversal.
• So now we see how to do In-order, Pri-order and Post-order traversal in different manner.
Let’s learn basic things
Left, Right, Bottom side of NODE.
50Left-hand side of Node Right-hand side of Node
Bottom side of Node
FOR PER-ORDER TRAVERSAL YOU HAVE
TO FOLLOW THIS STEPS.
For PRI-ORDER TRAVERSAL.IF YOU ARE IN LEFT-HAND SIDE OF NODE THEN YOU
HAVE TO WRITE THAT VALUE IN OUTPUT.
50
Pri-Order:-
50
• IF YOU ARE IN BOTTOM OF THE NODE THEN YOU DON’T HAVE TO WRITE ANYTHING IN OUTPUT.
50
Pri-Order:- NULL
PRI-ORDER TRAVERSAL
• IF YOU ARE IN RIGHT-HAND SIDE OF THE NODE THEN ALSO YOU DON’T HAVE TO WRITE ANTHING IN OUTPUT.
50
Pri-Order:- NULL
PRI-ORDER TRAVERSAL
Now see how to follow this steps in TREE Traversal.
50
35
20 45 7060
80
Example.
Draw one imaginary path around given TREE
Step 1:
35
20 45 9060
80
5050
PRI-ORDER:- .
20
35
45
80
60 90
IF YOU ARE IN LEFT HAND SIDE OF NODE THEN YOU HAVE TO WRITE THAT VALUE IN OUTPUT
FOR IN-ORDER TRAVERSAL YOU HAVE
TO FOLLOW THIS STEPS.
For IN-ORDER TRAVERSAL.IF YOU ARE IN LEFT-HAND SIDE OF NODE THEN YOU
DON’T HAVE TO WRITE ANYTHING IN OUTPUT.
50
IN-Order:-NULL
50
• IF YOU ARE IN BOTTOM OF THE NODE THEN YOU HAVE TO WRITE THAT VALUE IN OUTPUT.
50
IN-Order:-
50
IN-ORDER TRAVERSAL
• IF YOU ARE IN RIGHT-HAND SIDE OF THE NODE THEN YOU DON’T HAVE TO WRITE ANYTHING IN OUTPUT.
50
IN-Order:- NULL
IN-ORDER TRAVERSAL
50
35
20 45 7060
80
Example.
Draw one imaginary path around given TREE
Step 1:
50
35
20 45 9060
80
Let’s see one example.IF YOU ARE IN BOTTOM SIDE OF NODE THEN YOU HAVE TO WRITE THAT VALUE IN OUTPUT
20
IN-ORDER:- .
35
45
50
60
80
90
FOR POST-ORDER TRAVERSAL YOU
HAVE TO FOLLOW THIS STEPS.
For POST-ORDER TRAVERSAL.IF YOU ARE IN LEFT-HAND SIDE OF NODE THEN YOU
DON’T HAVE TO WRITE THAT VALUE IN OUTPUT.
50
POST-Order:-NULL
50
• IF YOU ARE IN BOTTOM OF THE NODE THEN YOU DON’T HAVE TO WRITE ANYTING IN OUTPUT.
50
POST-Order:-NULL
POST-ORDER TRAVERSAL
• IF YOU ARE IN RIGHT-HAND SIDE OF THE NODE THEN YOU HAVE TO WRITE THAT VALUE IN OUTPUT.
50
POST-Order:-
50
POST-ORDER TRAVERSAL
50
35
20 45 7060
80
Example.
Draw one imaginary path around given TREE
Step 1:
50
35
20 45 9060
80
Let’s see one example.
Post-Order:- .
20
IF YOU ARE IN RIGHT-HAND SIDE OF NODE THEN YOU HAVE TO WRITE THAT VALUE IN OUTPUT
45
35
60 90
80
50
Conclusion
• PRI-ORDER :- Consider the value If you are in LEFT-HAND SIDE of the NODE.
• IN-ORDER :- Consider the value if you are in BOTTOM SIDE of the NODE
• POST-ORDER:- Consider the value If you are in RIGHT-HAND SIDE of the NODE.
50
50
50
• Still if you have any queries then ask them on. Email:[email protected]
THANK YOU
Prepared by :- RAJ UPADHYAY