SlideShare a Scribd company logo
Tree Traversals (In-order, Pre-order and Post-order)
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.
Tree Traversals (In-order, Pre-order and Post-order)
Left, Right, Bottom side of NODE.
50Left-hand side of Node Right-hand side of Node
Bottom side of Node
Tree Traversals (In-order, Pre-order and Post-order)
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
Tree Traversals (In-order, Pre-order and Post-order)
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
Tree Traversals (In-order, Pre-order and Post-order)
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:-Upadhyayraj007@gmail.com

More Related Content

PPT
Force and Motion Year 10
PDF
Standing Waves
PPT
Lecture 02 density, pressure and pascal's principle
PPTX
Wave equation (speed, wavelength & frequency
PPT
8 k light (boardworks)
PPTX
Disadvantages of file management system (file processing systems)
PDF
JavaScript Regular Expression Match
PPTX
Basics of java (1)
Force and Motion Year 10
Standing Waves
Lecture 02 density, pressure and pascal's principle
Wave equation (speed, wavelength & frequency
8 k light (boardworks)
Disadvantages of file management system (file processing systems)
JavaScript Regular Expression Match
Basics of java (1)

More from raj upadhyay (9)

PPTX
Zed attack proxy [ What is ZAP(Zed Attack Proxy)? ]
PPTX
Folder Can't Delete How to Remove FILES That Won't Delete?
PPTX
Recovering unallocated space of a usb flash drive
PPTX
Terminal commands ubuntu 2
PPTX
Terminal Commands (Linux - ubuntu) (part-1)
PPTX
Find out Which Versions of the .NET Framework are Installed on a PC.
PPTX
Relational Algebra,Types of join
PPTX
PL-SQL DIFFERENT PROGRAMS
PPT
How to get notification from google group
Zed attack proxy [ What is ZAP(Zed Attack Proxy)? ]
Folder Can't Delete How to Remove FILES That Won't Delete?
Recovering unallocated space of a usb flash drive
Terminal commands ubuntu 2
Terminal Commands (Linux - ubuntu) (part-1)
Find out Which Versions of the .NET Framework are Installed on a PC.
Relational Algebra,Types of join
PL-SQL DIFFERENT PROGRAMS
How to get notification from google group
Ad

Recently uploaded (20)

PPTX
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PPTX
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx
PPTX
Cell Structure & Organelles in detailed.
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
The Final Stretch: How to Release a Game and Not Die in the Process.
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Open Quiz Monsoon Mind Game Prelims.pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Introduction and Scope of Bichemistry.pptx
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
PSYCHOLOGY IN EDUCATION.pdf ( nice pdf ...)
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Pre independence Education in Inndia.pdf
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx
Cell Structure & Organelles in detailed.
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
human mycosis Human fungal infections are called human mycosis..pptx
The Final Stretch: How to Release a Game and Not Die in the Process.
Microbial diseases, their pathogenesis and prophylaxis
Open Quiz Monsoon Mind Game Prelims.pptx
Anesthesia in Laparoscopic Surgery in India
Introduction and Scope of Bichemistry.pptx
Abdominal Access Techniques with Prof. Dr. R K Mishra
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
FourierSeries-QuestionsWithAnswers(Part-A).pdf
TR - Agricultural Crops Production NC III.pdf
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PSYCHOLOGY IN EDUCATION.pdf ( nice pdf ...)
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Pre independence Education in Inndia.pdf
Ad

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

  • 2. 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.
  • 4. Left, Right, Bottom side of NODE. 50Left-hand side of Node Right-hand side of Node Bottom side of Node
  • 6. 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
  • 7. • 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
  • 8. • 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
  • 9. Now see how to follow this steps in TREE Traversal.
  • 11. Draw one imaginary path around given TREE Step 1:
  • 12. 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
  • 14. 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
  • 15. • IF YOU ARE IN BOTTOM OF THE NODE THEN YOU HAVE TO WRITE THAT VALUE IN OUTPUT. 50 IN-Order:- 50 IN-ORDER TRAVERSAL
  • 16. • 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
  • 18. Draw one imaginary path around given TREE Step 1:
  • 19. 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
  • 21. 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
  • 22. • 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
  • 23. • 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
  • 25. Draw one imaginary path around given TREE Step 1:
  • 26. 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
  • 27. 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
  • 28. • Still if you have any queries then ask them on. Email:[email protected]