Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
How to Find PRI-ORDER, IN-ORDER, POST-ORDER
Traversal in TREE.
• As we all know there are certain rules (or manner) that w...
Left, Right, Bottom side of NODE.
50Left-hand side of Node Right-hand side of Node
Bottom side of Node
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:-...
• 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-O...
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 VAL...
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...
• 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 T...
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
2...
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...
• 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 TRA...
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...
Conclusion
• PRI-ORDER :- Consider the value If you are in LEFT-HAND SIDE
of the NODE.
• IN-ORDER :- Consider the value if...
• Still if you have any queries then ask them on.
Email:-Upadhyayraj007@gmail.com
Tree Traversals (In-order, Pre-order and Post-order)
Tree Traversals (In-order, Pre-order and Post-order)
Tree Traversals (In-order, Pre-order and Post-order)
Tree Traversals (In-order, Pre-order and Post-order)
Tree Traversals (In-order, Pre-order and Post-order)
Upcoming SlideShare
Loading in …5
×

Tree Traversals (In-order, Pre-order and Post-order)

Sometimes it’s confusing that what manner we have to follow for PRI-Oder, IN-Order, POSTER-Order Traversal.
So now you can see how to do In-order, Pri-order and Post-order traversal in different manner.
you will find shortcut technique for in-order, pri-order and post-order traversal.

Related Books

Free with a 30 day trial from Scribd

See all
  • Login to see the comments

Tree Traversals (In-order, Pre-order and Post-order)

  1. 1. 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.
  2. 2. Left, Right, Bottom side of NODE. 50Left-hand side of Node Right-hand side of Node Bottom side of Node
  3. 3. 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
  4. 4. • 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
  5. 5. • 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
  6. 6. Now see how to follow this steps in TREE Traversal.
  7. 7. 50 35 20 45 7060 80 Example.
  8. 8. Draw one imaginary path around given TREE Step 1:
  9. 9. 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
  10. 10. 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
  11. 11. • IF YOU ARE IN BOTTOM OF THE NODE THEN YOU HAVE TO WRITE THAT VALUE IN OUTPUT. 50 IN-Order:- 50 IN-ORDER TRAVERSAL
  12. 12. • 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
  13. 13. 50 35 20 45 7060 80 Example.
  14. 14. Draw one imaginary path around given TREE Step 1:
  15. 15. 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
  16. 16. 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
  17. 17. • 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
  18. 18. • 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
  19. 19. 50 35 20 45 7060 80 Example.
  20. 20. Draw one imaginary path around given TREE Step 1:
  21. 21. 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
  22. 22. 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
  23. 23. • Still if you have any queries then ask them on. Email:-Upadhyayraj007@gmail.com

×