SlideShare a Scribd company logo
3
Most read
4
Most read
5
Most read
Dept. of Computer science of Engineering
Batch: Spring 2022- 221-DA
Date: 10/05/2022
Course teacher: Md. Suntanul Islam Ovi
Subject: Discrete Math
Topic: Tree Traversal
Md. Sabbir Hossain
ID: 221902126
Md. Israil Fakir
ID: 221902125
Dina Azad
ID: 221902123
Md. Emam Hossain
ID: 221902124
Tree Traversal
 What is Tree Traversal ?
 Tree traversal means visiting each node of the tree
However, in tree data structures, there are multiple
ways to traverse it.
Tree Traversal
 Types of Tree Traversal
There are three types of tree traversal.
In-order Traversal
Tree Traversal
Pre-order Traversal Post-order traversal
Pre-order Traversal
Preorder traversal
1. Visit root node
2. Visit all the nodes in the left subtree
3. Visit all the nodes in the right subtree
 In this traversal method, the root node is visited first, then the
left subtree and finally the right subtree
Pre-order Traversal
Example:
Solution: 1 2 4 5 3
Pre-order Traversal
Algorithm: Pre-order traversal
procedure preorder (T: Ordered rooted tree )
r:=root of T
List r
For each child c of r from left to right
begin
T(c):= subtree with c as its root
Preorder ( T(c))
end
T
r
b c
d e
g
f
k
h i j
In-order Traversal
In this traversal method, the left subtree is visited
first, then the root and later the right sub-tree. We
should always remember that every node may
represent a subtree itself.
In-order traversal
1. Visit all the nodes in the left subtree
2. Visit root node
3. Visit all the nodes in the right subtree
In-order Traversal
Example:
Solution: 4 2 5 1 3
In-order Traversal
T
r
b c
d e
g
f
k
h i j
Algorithm: In-order traversal
Procedure In-order (T: ordered rooted tree)
r := root of T
If r is a leaf then list r
else
begin
l := first child of from left to right
T (l) := subtree with l as its root
In-order( T(l))
list r
for each child c of r except for l from left to right
T ( c):= subtree with c as its root
In-order(T(c))
end
Post-order Traversal
 In this traversal method, the root node is visited last,
hence the name. First we traverse the left subtree,
then the right subtree and finally the root node.
In-order traversal
1. Visit all the nodes in the left subtree
2. Visit all the nodes in the right subtree
3. Visit root node
Post-order Traversal
Example:
Solution: 4 5 2 3 1
Pre-order Traversal
T
r
b c
d e
g
f
k
h i j
Algorithm: Post-order traversal
Procedure post-order(T : ordered rooted tree)
r :=root of T
For each child c of r from left to right
Begin
T(c) := subtree with c as its root
Post-order (T(c))
end
List r
Thank you

More Related Content

PPTX
Binary Tree Traversal
PDF
Binary tree
PPTX
trees in data structure
PPT
Binary tree
PPTX
Binary Search Tree
PDF
Trees, Binary Search Tree, AVL Tree in Data Structures
PPTX
Trees (data structure)
PPSX
Data Structure (Tree)
Binary Tree Traversal
Binary tree
trees in data structure
Binary tree
Binary Search Tree
Trees, Binary Search Tree, AVL Tree in Data Structures
Trees (data structure)
Data Structure (Tree)

What's hot (20)

PPTX
Binary Tree in Data Structure
PPTX
Binary Search Tree
PPTX
Binary Search Tree in Data Structure
PPTX
Queue in Data Structure
PPTX
Doubly Linked List
PPT
Data Structures- Part5 recursion
PDF
Expression trees
PPTX
Stacks IN DATA STRUCTURES
PPTX
Binary search
PPTX
Hashing Technique In Data Structures
PPTX
PPTX
Linked List
PPTX
Linked list
PPTX
Graph traversals in Data Structures
PPTX
Quick sort
PPT
BINARY TREE REPRESENTATION.ppt
PPTX
single linked list
PPTX
Selection sorting
PPTX
Terminology of tree
Binary Tree in Data Structure
Binary Search Tree
Binary Search Tree in Data Structure
Queue in Data Structure
Doubly Linked List
Data Structures- Part5 recursion
Expression trees
Stacks IN DATA STRUCTURES
Binary search
Hashing Technique In Data Structures
Linked List
Linked list
Graph traversals in Data Structures
Quick sort
BINARY TREE REPRESENTATION.ppt
single linked list
Selection sorting
Terminology of tree
Ad

Similar to Tree Traversal (20)

PPTX
22R01A66C6 DSP.pptx
PPTX
Tree traversal techniques
PPTX
Binary tree traversal in data structure .pptx
PPTX
Pratechhnology of techtik Gautechhnology of techrav.pptx
PPTX
Tree-Traversal-Algorithms on data structure algorithms
PPTX
Data structure
PPTX
Creating a Binary tree from a General Tree.pptx
PPT
Data Structures- Part9 trees simplified
PPTX
Tree Traversal Algorithm in Data Structure
PDF
Binary Trees
PPTX
Tree Traversals in Binary Tree for Beginner in Computer Science
PPTX
Tree Traversal
PPTX
Why Tree is considered a non-linear data structure?
PPTX
Tree data structure
PPT
tutorial-tree (3).ppt
PPTX
Presentation tree traversal
PPT
Trees
PPTX
Lecture 22_Trees - II.pptx
22R01A66C6 DSP.pptx
Tree traversal techniques
Binary tree traversal in data structure .pptx
Pratechhnology of techtik Gautechhnology of techrav.pptx
Tree-Traversal-Algorithms on data structure algorithms
Data structure
Creating a Binary tree from a General Tree.pptx
Data Structures- Part9 trees simplified
Tree Traversal Algorithm in Data Structure
Binary Trees
Tree Traversals in Binary Tree for Beginner in Computer Science
Tree Traversal
Why Tree is considered a non-linear data structure?
Tree data structure
tutorial-tree (3).ppt
Presentation tree traversal
Trees
Lecture 22_Trees - II.pptx
Ad

Recently uploaded (20)

PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
PPT on Performance Review to get promotions
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
bas. eng. economics group 4 presentation 1.pptx
DOCX
573137875-Attendance-Management-System-original
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
Current and future trends in Computer Vision.pptx
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
Fundamentals of safety and accident prevention -final (1).pptx
PPTX
Sustainable Sites - Green Building Construction
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPTX
OOP with Java - Java Introduction (Basics)
PDF
R24 SURVEYING LAB MANUAL for civil enggi
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPT on Performance Review to get promotions
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Internet of Things (IOT) - A guide to understanding
bas. eng. economics group 4 presentation 1.pptx
573137875-Attendance-Management-System-original
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Current and future trends in Computer Vision.pptx
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
CYBER-CRIMES AND SECURITY A guide to understanding
UNIT-1 - COAL BASED THERMAL POWER PLANTS
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Operating System & Kernel Study Guide-1 - converted.pdf
Fundamentals of safety and accident prevention -final (1).pptx
Sustainable Sites - Green Building Construction
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
OOP with Java - Java Introduction (Basics)
R24 SURVEYING LAB MANUAL for civil enggi

Tree Traversal

  • 1. Dept. of Computer science of Engineering Batch: Spring 2022- 221-DA Date: 10/05/2022 Course teacher: Md. Suntanul Islam Ovi Subject: Discrete Math Topic: Tree Traversal
  • 2. Md. Sabbir Hossain ID: 221902126 Md. Israil Fakir ID: 221902125 Dina Azad ID: 221902123 Md. Emam Hossain ID: 221902124
  • 3. Tree Traversal  What is Tree Traversal ?  Tree traversal means visiting each node of the tree However, in tree data structures, there are multiple ways to traverse it.
  • 4. Tree Traversal  Types of Tree Traversal There are three types of tree traversal. In-order Traversal Tree Traversal Pre-order Traversal Post-order traversal
  • 5. Pre-order Traversal Preorder traversal 1. Visit root node 2. Visit all the nodes in the left subtree 3. Visit all the nodes in the right subtree  In this traversal method, the root node is visited first, then the left subtree and finally the right subtree
  • 7. Pre-order Traversal Algorithm: Pre-order traversal procedure preorder (T: Ordered rooted tree ) r:=root of T List r For each child c of r from left to right begin T(c):= subtree with c as its root Preorder ( T(c)) end T r b c d e g f k h i j
  • 8. In-order Traversal In this traversal method, the left subtree is visited first, then the root and later the right sub-tree. We should always remember that every node may represent a subtree itself. In-order traversal 1. Visit all the nodes in the left subtree 2. Visit root node 3. Visit all the nodes in the right subtree
  • 10. In-order Traversal T r b c d e g f k h i j Algorithm: In-order traversal Procedure In-order (T: ordered rooted tree) r := root of T If r is a leaf then list r else begin l := first child of from left to right T (l) := subtree with l as its root In-order( T(l)) list r for each child c of r except for l from left to right T ( c):= subtree with c as its root In-order(T(c)) end
  • 11. Post-order Traversal  In this traversal method, the root node is visited last, hence the name. First we traverse the left subtree, then the right subtree and finally the root node. In-order traversal 1. Visit all the nodes in the left subtree 2. Visit all the nodes in the right subtree 3. Visit root node
  • 13. Pre-order Traversal T r b c d e g f k h i j Algorithm: Post-order traversal Procedure post-order(T : ordered rooted tree) r :=root of T For each child c of r from left to right Begin T(c) := subtree with c as its root Post-order (T(c)) end List r