SlideShare a Scribd company logo
Discrete Structures
Trees
Trees and Forests
• A (free) tree is an undirected graph T
such that
– T is connected
– T has no cycles (circuits)
This definition of tree is different
from the one of a rooted tree
• A rooted tree is a tree in which one
vertex has been designated as the
root and every edge is directed away
from the root.
• A forest is an undirected graph
without cycles
• The connected components of a
forest are trees
Tree
Forest
Spanning Trees and Forests
• A spanning tree of a connected
graph is a spanning subgraph that
is a tree
• A spanning tree is not unique
unless the graph is a tree
• Spanning trees have applications
to the design of communication
networks
• A spanning forest of a graph is a
spanning subgraph that is a forest
Graph
Spanning tree
Tree Traversal
• Ordered Rooted Tree:
An ordered rooted tree is a rooted tree where
the children of each internal vertex are
ordered.
• Tree Traversal:
Ordered rooted trees are often used to store
information. Tree traversal is the procedure of
visiting different vertices of the tree to read
information stored in that vertex. There are
three different orders of the tree traversal.
Inorder Traversal
• Let T be an ordered rooted tree with root r
and T1, T2, …Tn are the subtrees at r from left to
right. The in order traversal begins by
traversing T1 in inorder, then visiting r. It
continues by traversing T2 in inorder, then T3 in
inorder, . . . , and finally Tn in inorder.
Inorder Tree Walk
• Left, root, right
• Example:
• A, B, D, F, H, K
F
B H
KDA
Inorder Tree Walk
• What does the following code do?
TreeWalk(x)
TreeWalk(left[x]);
print(x);
TreeWalk(right[x]);
• A: prints elements in sorted (increasing) order
• This is called an inorder tree walk
– Preorder tree walk: print root, then left, then right
– Postorder tree walk: print left, then right, then root
Example – Inorder Traversal
• Example 3, p-714
Preorder Traversal
• Let T be an ordered rooted tree with root r
and T1, T2, …Tn are the subtrees at r from left to
right. The preorder traversal begins by visiting
r . It continues by traversing T1 in preorder,
then T2 in preorder, then T3 in preorder, . . . ,
and finally Tn in preorder.
Preorder Traversal
• Root, left, right
• Example:
• F, B, A, D, H, K
F
B H
KDA
Preorder Traversal
• Example 2, p-714
Postorder Traversal
• Let T be an ordered rooted tree with root r
and T1, T2, …Tn are the subtrees at r from left to
right. The preorder traversal begins by
traversing T1 in postorder, then T2 in postorder,
then T3 in postorder, . . . , and finally Tn in
postorder and ends by visiting r.
Postorder Traversal
• Left, right, root
• Example:
• A, D, B, K, H, F
F
B H
KDA
Postorder Traversal
• Example 4, p-714
02/09/15
A Shortcut for Traversing an Ordered
Rooted Tree in Preorder, Inorder, and Postorder.
• See Q. 7 to 15, p-723

More Related Content

What's hot

Bivariate data
Bivariate dataBivariate data
Bivariate data
julienorman80065
 
Sharing Using Ratios
Sharing Using RatiosSharing Using Ratios
Sharing Using Ratios
Passy World
 
Center and axial symmetry
Center and axial symmetryCenter and axial symmetry
Center and axial symmetry
Tomas Krsko
 
MATRICES
MATRICESMATRICES
MATRICESfaijmsk
 
Percentages
PercentagesPercentages
Matrix algebra
Matrix algebraMatrix algebra
Matrix algebra
Farzad Javidanrad
 
Langrange Interpolation Polynomials
Langrange Interpolation PolynomialsLangrange Interpolation Polynomials
Langrange Interpolation Polynomials
Sohaib H. Khan
 
Estimating square roots
Estimating square rootsEstimating square roots
Estimating square rootsmstf mstf
 
HCF and LCM
HCF and LCMHCF and LCM
HCF and LCM
PRIYANKA ABRAHAM
 
Data presentation
Data presentationData presentation
Data presentation
Weam Banjar
 
Stem and-leaf plots
Stem and-leaf plotsStem and-leaf plots
Stem and-leaf plotsValPatton
 
FREQUENCY DISTRIBUTION.pptx
FREQUENCY DISTRIBUTION.pptxFREQUENCY DISTRIBUTION.pptx
FREQUENCY DISTRIBUTION.pptx
SreeLatha98
 
Data sources and collection methods
Data sources and collection methods Data sources and collection methods
Data sources and collection methods
Governance Asssessment Portal
 
The Tangent Ratio
The Tangent RatioThe Tangent Ratio
The Tangent Ratio
Passy World
 
Bisection method
Bisection methodBisection method
Bisection method
Md. Mujahid Islam
 
3. Venn Diagram.pptx
3. Venn Diagram.pptx3. Venn Diagram.pptx
3. Venn Diagram.pptx
EllenGrace9
 
Permutations & combinations
Permutations & combinationsPermutations & combinations
Permutations & combinationsNCVPS
 
Data Handling
Data HandlingData Handling
Data Handling
Manisha Keim
 

What's hot (20)

Bivariate data
Bivariate dataBivariate data
Bivariate data
 
Descriptive statistics
Descriptive statisticsDescriptive statistics
Descriptive statistics
 
Sharing Using Ratios
Sharing Using RatiosSharing Using Ratios
Sharing Using Ratios
 
Center and axial symmetry
Center and axial symmetryCenter and axial symmetry
Center and axial symmetry
 
MATRICES
MATRICESMATRICES
MATRICES
 
Percentages
PercentagesPercentages
Percentages
 
Matrix algebra
Matrix algebraMatrix algebra
Matrix algebra
 
Langrange Interpolation Polynomials
Langrange Interpolation PolynomialsLangrange Interpolation Polynomials
Langrange Interpolation Polynomials
 
Estimating square roots
Estimating square rootsEstimating square roots
Estimating square roots
 
HCF and LCM
HCF and LCMHCF and LCM
HCF and LCM
 
Data presentation
Data presentationData presentation
Data presentation
 
Stem and-leaf plots
Stem and-leaf plotsStem and-leaf plots
Stem and-leaf plots
 
FREQUENCY DISTRIBUTION.pptx
FREQUENCY DISTRIBUTION.pptxFREQUENCY DISTRIBUTION.pptx
FREQUENCY DISTRIBUTION.pptx
 
Data sources and collection methods
Data sources and collection methods Data sources and collection methods
Data sources and collection methods
 
The Tangent Ratio
The Tangent RatioThe Tangent Ratio
The Tangent Ratio
 
Bisection method
Bisection methodBisection method
Bisection method
 
3. Venn Diagram.pptx
3. Venn Diagram.pptx3. Venn Diagram.pptx
3. Venn Diagram.pptx
 
Arithmetic mean
Arithmetic meanArithmetic mean
Arithmetic mean
 
Permutations & combinations
Permutations & combinationsPermutations & combinations
Permutations & combinations
 
Data Handling
Data HandlingData Handling
Data Handling
 

Similar to Trees

Trees
Trees Trees
Trees
Gaditek
 
Tree
TreeTree
Data structure(Part 2)
Data structure(Part 2)Data structure(Part 2)
Data structure(Part 2)
SURBHI SAROHA
 
Mca iii dfs u-4 tree and graph
Mca iii dfs u-4 tree and graphMca iii dfs u-4 tree and graph
Mca iii dfs u-4 tree and graph
Rai University
 
Bca ii dfs u-3 tree and graph
Bca  ii dfs u-3 tree and graphBca  ii dfs u-3 tree and graph
Bca ii dfs u-3 tree and graph
Rai University
 
Bsc cs ii dfs u-3 tree and graph
Bsc cs  ii dfs u-3 tree and graphBsc cs  ii dfs u-3 tree and graph
Bsc cs ii dfs u-3 tree and graph
Rai University
 
Data structures and Algorithm analysis_Lecture4.pptx
Data structures and Algorithm analysis_Lecture4.pptxData structures and Algorithm analysis_Lecture4.pptx
Data structures and Algorithm analysis_Lecture4.pptx
AhmedEldesoky24
 
Tree
TreeTree
Farhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructureFarhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructure
Farhana Shaikh
 
Trees
TreesTrees
Trees
Niliha
 
unit 4 for trees data structure notes it is
unit 4 for trees data structure notes it isunit 4 for trees data structure notes it is
unit 4 for trees data structure notes it is
logesswarisrinivasan
 
BINARY SEARCH TREE
BINARY SEARCH TREEBINARY SEARCH TREE
BINARY SEARCH TREE
ER Punit Jain
 
tree-160731205832.pptx
tree-160731205832.pptxtree-160731205832.pptx
tree-160731205832.pptx
MouDhara1
 
Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
Ashim Lamichhane
 
Tree.pptx
Tree.pptxTree.pptx
Tree.pptx
worldchannel
 
358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10
sumitbardhan
 

Similar to Trees (20)

Trees
Trees Trees
Trees
 
Tree
TreeTree
Tree
 
Data structure(Part 2)
Data structure(Part 2)Data structure(Part 2)
Data structure(Part 2)
 
Mca iii dfs u-4 tree and graph
Mca iii dfs u-4 tree and graphMca iii dfs u-4 tree and graph
Mca iii dfs u-4 tree and graph
 
Bca ii dfs u-3 tree and graph
Bca  ii dfs u-3 tree and graphBca  ii dfs u-3 tree and graph
Bca ii dfs u-3 tree and graph
 
Bsc cs ii dfs u-3 tree and graph
Bsc cs  ii dfs u-3 tree and graphBsc cs  ii dfs u-3 tree and graph
Bsc cs ii dfs u-3 tree and graph
 
Unit III.ppt
Unit III.pptUnit III.ppt
Unit III.ppt
 
Data structures and Algorithm analysis_Lecture4.pptx
Data structures and Algorithm analysis_Lecture4.pptxData structures and Algorithm analysis_Lecture4.pptx
Data structures and Algorithm analysis_Lecture4.pptx
 
Data structures 3
Data structures 3Data structures 3
Data structures 3
 
Tree
TreeTree
Tree
 
Farhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructureFarhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructure
 
Trees
TreesTrees
Trees
 
unit 4 for trees data structure notes it is
unit 4 for trees data structure notes it isunit 4 for trees data structure notes it is
unit 4 for trees data structure notes it is
 
Tree 11.ppt
Tree 11.pptTree 11.ppt
Tree 11.ppt
 
BINARY SEARCH TREE
BINARY SEARCH TREEBINARY SEARCH TREE
BINARY SEARCH TREE
 
tree-160731205832.pptx
tree-160731205832.pptxtree-160731205832.pptx
tree-160731205832.pptx
 
Trees krw
Trees krwTrees krw
Trees krw
 
Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
 
Tree.pptx
Tree.pptxTree.pptx
Tree.pptx
 
358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10
 

More from Ali Saleem

Nested quantifiers
Nested quantifiersNested quantifiers
Nested quantifiers
Ali Saleem
 
Graphs
GraphsGraphs
Graphs
Ali Saleem
 
Relations
RelationsRelations
Relations
Ali Saleem
 
Sequences and summations
Sequences and summationsSequences and summations
Sequences and summations
Ali Saleem
 
Nested quantifiers
Nested quantifiersNested quantifiers
Nested quantifiers
Ali Saleem
 
Writing a memo, letter, and e mail
Writing a memo, letter, and e mailWriting a memo, letter, and e mail
Writing a memo, letter, and e mail
Ali Saleem
 
Challenges for the newborn state
Challenges for the newborn  stateChallenges for the newborn  state
Challenges for the newborn state
Ali Saleem
 
Objectives or goals of technical communication
Objectives or goals of technical communicationObjectives or goals of technical communication
Objectives or goals of technical communication
Ali Saleem
 
17 using rules of inference to build arguments
17   using rules of inference to build arguments17   using rules of inference to build arguments
17 using rules of inference to build arguments
Ali Saleem
 

More from Ali Saleem (9)

Nested quantifiers
Nested quantifiersNested quantifiers
Nested quantifiers
 
Graphs
GraphsGraphs
Graphs
 
Relations
RelationsRelations
Relations
 
Sequences and summations
Sequences and summationsSequences and summations
Sequences and summations
 
Nested quantifiers
Nested quantifiersNested quantifiers
Nested quantifiers
 
Writing a memo, letter, and e mail
Writing a memo, letter, and e mailWriting a memo, letter, and e mail
Writing a memo, letter, and e mail
 
Challenges for the newborn state
Challenges for the newborn  stateChallenges for the newborn  state
Challenges for the newborn state
 
Objectives or goals of technical communication
Objectives or goals of technical communicationObjectives or goals of technical communication
Objectives or goals of technical communication
 
17 using rules of inference to build arguments
17   using rules of inference to build arguments17   using rules of inference to build arguments
17 using rules of inference to build arguments
 

Recently uploaded

The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 

Recently uploaded (20)

The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 

Trees

  • 2. Trees and Forests • A (free) tree is an undirected graph T such that – T is connected – T has no cycles (circuits) This definition of tree is different from the one of a rooted tree • A rooted tree is a tree in which one vertex has been designated as the root and every edge is directed away from the root. • A forest is an undirected graph without cycles • The connected components of a forest are trees Tree Forest
  • 3. Spanning Trees and Forests • A spanning tree of a connected graph is a spanning subgraph that is a tree • A spanning tree is not unique unless the graph is a tree • Spanning trees have applications to the design of communication networks • A spanning forest of a graph is a spanning subgraph that is a forest Graph Spanning tree
  • 4. Tree Traversal • Ordered Rooted Tree: An ordered rooted tree is a rooted tree where the children of each internal vertex are ordered. • Tree Traversal: Ordered rooted trees are often used to store information. Tree traversal is the procedure of visiting different vertices of the tree to read information stored in that vertex. There are three different orders of the tree traversal.
  • 5. Inorder Traversal • Let T be an ordered rooted tree with root r and T1, T2, …Tn are the subtrees at r from left to right. The in order traversal begins by traversing T1 in inorder, then visiting r. It continues by traversing T2 in inorder, then T3 in inorder, . . . , and finally Tn in inorder.
  • 6. Inorder Tree Walk • Left, root, right • Example: • A, B, D, F, H, K F B H KDA
  • 7. Inorder Tree Walk • What does the following code do? TreeWalk(x) TreeWalk(left[x]); print(x); TreeWalk(right[x]); • A: prints elements in sorted (increasing) order • This is called an inorder tree walk – Preorder tree walk: print root, then left, then right – Postorder tree walk: print left, then right, then root
  • 8. Example – Inorder Traversal • Example 3, p-714
  • 9. Preorder Traversal • Let T be an ordered rooted tree with root r and T1, T2, …Tn are the subtrees at r from left to right. The preorder traversal begins by visiting r . It continues by traversing T1 in preorder, then T2 in preorder, then T3 in preorder, . . . , and finally Tn in preorder.
  • 10. Preorder Traversal • Root, left, right • Example: • F, B, A, D, H, K F B H KDA
  • 12. Postorder Traversal • Let T be an ordered rooted tree with root r and T1, T2, …Tn are the subtrees at r from left to right. The preorder traversal begins by traversing T1 in postorder, then T2 in postorder, then T3 in postorder, . . . , and finally Tn in postorder and ends by visiting r.
  • 13. Postorder Traversal • Left, right, root • Example: • A, D, B, K, H, F F B H KDA
  • 14. Postorder Traversal • Example 4, p-714 02/09/15
  • 15. A Shortcut for Traversing an Ordered Rooted Tree in Preorder, Inorder, and Postorder. • See Q. 7 to 15, p-723