Successfully reported this slideshow.
Upcoming SlideShare
×

# 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.

See all

### Related Audiobooks

#### Free with a 30 day trial from Scribd

See all
• Full Name
Comment goes here.

Are you sure you want to Yes No

### 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