SlideShare a Scribd company logo
1 of 10
Binary Tree Traversals
Divide-and-Conquer Technique
Tree Traversal
 Also known as tree search and walking the tree
 Refers to the process of visiting each node in a tree data
structure exactly once
structure exactly once
Tree Traversal Technique
 Based on the order in which the nodes are visited,
 Inorder traversal L-Ro-R
 Preorder traversal Ro-L-R
 Postorder traversal L-R-Ro
Inorder traversal
Inorder(root)
 Traverse the left sub-tree,
(recursively call inorder(root -> left)
(recursively call inorder(root -> left)
 Visit and print the root node.
 Traverse the right sub-tree,
(recursively call inorder(root -> right)
Inorder: d, g, b, e, a, f, c
Preorder traversal
Preorder(root)
 Visit and print the root node.
 Traverse the left sub-tree,
(recursively call inorder(root -> left)
 Traverse the right sub-tree,
(recursively call inorder(root -> right)
Preorder: a, b, d, g, e, c, f
Postorder traversal
Preorder(root)
 Traverse the left sub-tree,
(recursively call inorder(root -> left)
(recursively call inorder(root -> left)
 Traverse the right sub-tree,
(recursively call inorder(root -> right)
 Visit and print the root node.
Postorder: g, d, e, b, f, c, a
Pre-order (node access at position
red ):
F, B, A, D, C, E, G, I, H
In-order (node access at position
In-order (node access at position
green):
A, B, C, D, E, F, G, H, I
Post-order (node access at position
blue):
A, C, E, D, B, H, I, G, F
External and Internal Node
 Number of external
nodes x is
always 1 more than
the number of
the number of
internal nodes n:
x = n + 1
Binary tree traversals (Divide and Conquer)

More Related Content

More from Gem WeBlog

Designing multimedia
Designing multimediaDesigning multimedia
Designing multimediaGem WeBlog
 
Testing and Rolling Out Enterprise Applications
Testing and Rolling Out Enterprise ApplicationsTesting and Rolling Out Enterprise Applications
Testing and Rolling Out Enterprise ApplicationsGem WeBlog
 
Constructing Enterprise Applications
Constructing Enterprise  ApplicationsConstructing Enterprise  Applications
Constructing Enterprise ApplicationsGem WeBlog
 
Architecting and Designing Enterprise Applications
Architecting and Designing Enterprise ApplicationsArchitecting and Designing Enterprise Applications
Architecting and Designing Enterprise ApplicationsGem WeBlog
 
Incepting Enterprise Applications
Incepting Enterprise ApplicationsIncepting Enterprise Applications
Incepting Enterprise ApplicationsGem WeBlog
 
Introduction to BEA
Introduction to BEAIntroduction to BEA
Introduction to BEAGem WeBlog
 
Pointers and Structures
Pointers and StructuresPointers and Structures
Pointers and StructuresGem WeBlog
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocationGem WeBlog
 
Function pointer
Function pointerFunction pointer
Function pointerGem WeBlog
 
10. NULL pointer
10. NULL pointer10. NULL pointer
10. NULL pointerGem WeBlog
 
13. Pointer and 2D array
13. Pointer  and  2D array13. Pointer  and  2D array
13. Pointer and 2D arrayGem WeBlog
 
12.string and pointer
12.string and pointer12.string and pointer
12.string and pointerGem WeBlog
 
7. Pointer Arithmetic
7. Pointer Arithmetic7. Pointer Arithmetic
7. Pointer ArithmeticGem WeBlog
 
1. Pointer Basic
1. Pointer Basic1. Pointer Basic
1. Pointer BasicGem WeBlog
 
Quick Select - Computing a Median (Decrease and Conquer)
Quick Select - Computing a Median (Decrease and Conquer) Quick Select - Computing a Median (Decrease and Conquer)
Quick Select - Computing a Median (Decrease and Conquer) Gem WeBlog
 
Quick Select (Decrease and Conquer)
Quick Select (Decrease and Conquer) Quick Select (Decrease and Conquer)
Quick Select (Decrease and Conquer) Gem WeBlog
 
Topological Sorting (Decrease and Conquer)
Topological Sorting (Decrease and Conquer)Topological Sorting (Decrease and Conquer)
Topological Sorting (Decrease and Conquer)Gem WeBlog
 
Convex hull problems(Divide and Conquer)
Convex hull problems(Divide and Conquer)Convex hull problems(Divide and Conquer)
Convex hull problems(Divide and Conquer)Gem WeBlog
 
Closest pair problems (Divide and Conquer)
Closest pair problems (Divide and Conquer)Closest pair problems (Divide and Conquer)
Closest pair problems (Divide and Conquer)Gem WeBlog
 
Convex hull problem
Convex hull problemConvex hull problem
Convex hull problemGem WeBlog
 

More from Gem WeBlog (20)

Designing multimedia
Designing multimediaDesigning multimedia
Designing multimedia
 
Testing and Rolling Out Enterprise Applications
Testing and Rolling Out Enterprise ApplicationsTesting and Rolling Out Enterprise Applications
Testing and Rolling Out Enterprise Applications
 
Constructing Enterprise Applications
Constructing Enterprise  ApplicationsConstructing Enterprise  Applications
Constructing Enterprise Applications
 
Architecting and Designing Enterprise Applications
Architecting and Designing Enterprise ApplicationsArchitecting and Designing Enterprise Applications
Architecting and Designing Enterprise Applications
 
Incepting Enterprise Applications
Incepting Enterprise ApplicationsIncepting Enterprise Applications
Incepting Enterprise Applications
 
Introduction to BEA
Introduction to BEAIntroduction to BEA
Introduction to BEA
 
Pointers and Structures
Pointers and StructuresPointers and Structures
Pointers and Structures
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
 
Function pointer
Function pointerFunction pointer
Function pointer
 
10. NULL pointer
10. NULL pointer10. NULL pointer
10. NULL pointer
 
13. Pointer and 2D array
13. Pointer  and  2D array13. Pointer  and  2D array
13. Pointer and 2D array
 
12.string and pointer
12.string and pointer12.string and pointer
12.string and pointer
 
7. Pointer Arithmetic
7. Pointer Arithmetic7. Pointer Arithmetic
7. Pointer Arithmetic
 
1. Pointer Basic
1. Pointer Basic1. Pointer Basic
1. Pointer Basic
 
Quick Select - Computing a Median (Decrease and Conquer)
Quick Select - Computing a Median (Decrease and Conquer) Quick Select - Computing a Median (Decrease and Conquer)
Quick Select - Computing a Median (Decrease and Conquer)
 
Quick Select (Decrease and Conquer)
Quick Select (Decrease and Conquer) Quick Select (Decrease and Conquer)
Quick Select (Decrease and Conquer)
 
Topological Sorting (Decrease and Conquer)
Topological Sorting (Decrease and Conquer)Topological Sorting (Decrease and Conquer)
Topological Sorting (Decrease and Conquer)
 
Convex hull problems(Divide and Conquer)
Convex hull problems(Divide and Conquer)Convex hull problems(Divide and Conquer)
Convex hull problems(Divide and Conquer)
 
Closest pair problems (Divide and Conquer)
Closest pair problems (Divide and Conquer)Closest pair problems (Divide and Conquer)
Closest pair problems (Divide and Conquer)
 
Convex hull problem
Convex hull problemConvex hull problem
Convex hull problem
 

Recently uploaded

Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoordharasingh5698
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptMsecMca
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01KreezheaRecto
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfRagavanV2
 

Recently uploaded (20)

Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdf
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 

Binary tree traversals (Divide and Conquer)

  • 2. Tree Traversal  Also known as tree search and walking the tree  Refers to the process of visiting each node in a tree data structure exactly once structure exactly once
  • 3. Tree Traversal Technique  Based on the order in which the nodes are visited,  Inorder traversal L-Ro-R  Preorder traversal Ro-L-R  Postorder traversal L-R-Ro
  • 4. Inorder traversal Inorder(root)  Traverse the left sub-tree, (recursively call inorder(root -> left) (recursively call inorder(root -> left)  Visit and print the root node.  Traverse the right sub-tree, (recursively call inorder(root -> right) Inorder: d, g, b, e, a, f, c
  • 5. Preorder traversal Preorder(root)  Visit and print the root node.  Traverse the left sub-tree, (recursively call inorder(root -> left)  Traverse the right sub-tree, (recursively call inorder(root -> right) Preorder: a, b, d, g, e, c, f
  • 6. Postorder traversal Preorder(root)  Traverse the left sub-tree, (recursively call inorder(root -> left) (recursively call inorder(root -> left)  Traverse the right sub-tree, (recursively call inorder(root -> right)  Visit and print the root node. Postorder: g, d, e, b, f, c, a
  • 7.
  • 8. Pre-order (node access at position red ): F, B, A, D, C, E, G, I, H In-order (node access at position In-order (node access at position green): A, B, C, D, E, F, G, H, I Post-order (node access at position blue): A, C, E, D, B, H, I, G, F
  • 9. External and Internal Node  Number of external nodes x is always 1 more than the number of the number of internal nodes n: x = n + 1