SlideShare a Scribd company logo
1 of 13
BIRLA INSTITUTE OF
TECHNOLOGY,MESRA
JAIPUR CAMPUS
Presented By:
Apoorva Nagar
MCA/25013/18
TREE TRAVERSAL ALGORITHMS
TREE TRAVERSAL
ALGORITHMS
BINARY TREES
• A Binary tree is a tree with all nodes having at most two
branches.
• Each node have a degree of at most two.
• Binary tree can be empty or consists of a root node and
two disjoint binary trees termed left subtree and right
subtree
BINARY TREE TRAVERSAL
• A traversal of a binary tree is where its nodes are
visited in a particular but in repetitive order.
• A traversal is governed by three action.They are:
Move Left(L)
Move Right(R)
Processed Node(P)
• All these action yield into many different combination
out of which three most significant combination result
into three traversal ways.They are:
Inorder Traversal—LPR
Postorder Traversal—LRP
Preorder Traversal—PLR
INORDER TRAVERSAL
ALGORITHM:
Recursive procedure to perform Inorder traversal of a
binary tree.
Procedure INORDER_TRAVERSAL(NODE)
If NODE NIL then
{
call INORDER_TRAVERSAL(LCHILD(NODE));
print (DATA (NODE));
call INORDER_TRAVERSAL(RCHILD(NODE));
}
end INORDER_TRAVERSAL.
• The traversal keeps moving left in the binary tree until
one can move no further, processes the node and
moves to the right to continue its traversal again.
• In the absence of any node to the right, it retracts
backward by a node and continue its traversal.
• Consider a binary tree
Inorder traversal output is: G H F I E A B D C
POSTORDER TRAVERSAL
ALGORITHM:
Recursive procedure to perform postorder traversal of a
binary tree
Procedure POSTORDER_TRAVERSAL(NODE)
If NODE NIL then
{
call POSTORDER_TRAVERSAL(LCHILD(NODE));
call POSTORDER_TRAVERSAL(RCHILD(NODE));
print (DATA(NODE));
}
end POSTORDER_TRAVERSAL.
• The traversal proceeds by keeping to the left until it is no
further possible,turns right to continue its traversal.
• If there is no right node, processes the node and
retraces its direction by one node to continue its
traversal.
• Consider a binary tree
Postorder Traversal output is: G F E I H D C B A
PREORDER TRAVERSAL
ALGORITHM:
Recursive procedure to perform preorder traversal of a
binary tree
Procedure PREORDER_TRAVERSAL(NODE)
If NODE NIL then
{
print (DATA (NODE));
call PREORDER_TRAVERSAL(LCHILD(NODE));
call PREORDER_TRAVERSAL(RCHILD(NODE));
}
end PREORDER_TRAVERSAL.
• The traversal process every node as it moves to left until
it can move no further.Now it turns right to begin again.
• If there is no node in the right, retracts until it can move
right to continue its traversal.
• Consider a binary tree
Preorder Traversal output is: A H G I F E B C D
USES OF TREE TRAVERSAL
In case of binary search trees (BST), Inorder traversal
gives nodes in non-decreasing order.
Preorder and Inorder traversals are used to create a copy
of the tree.
Postorder traversal is used to delete the tree.
REFERENCES
https://www.geeksforgeeks.org/tree-traversals-inorder-
preorder-and-postorder/
https://www.tutorialspoint.com/data_structures_algorithms
/tree_traversal.htm
THANK YOU!!!

More Related Content

What's hot (20)

DFS & BFS Graph
DFS & BFS GraphDFS & BFS Graph
DFS & BFS Graph
 
Data Structure (Tree)
Data Structure (Tree)Data Structure (Tree)
Data Structure (Tree)
 
Binary search tree operations
Binary search tree operationsBinary search tree operations
Binary search tree operations
 
Avl trees final
Avl trees finalAvl trees final
Avl trees final
 
1.5 binary search tree
1.5 binary search tree1.5 binary search tree
1.5 binary search tree
 
Graph traversals in Data Structures
Graph traversals in Data StructuresGraph traversals in Data Structures
Graph traversals in Data Structures
 
Dfs presentation
Dfs presentationDfs presentation
Dfs presentation
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
 
AVL Tree
AVL TreeAVL Tree
AVL Tree
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
 
Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]
 
Depth first search [dfs]
Depth first search [dfs]Depth first search [dfs]
Depth first search [dfs]
 
Linked list
Linked listLinked list
Linked list
 
Red black tree
Red black treeRed black tree
Red black tree
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
 
Red black trees
Red black treesRed black trees
Red black trees
 
Depth-First Search
Depth-First SearchDepth-First Search
Depth-First Search
 
Graphs bfs dfs
Graphs bfs dfsGraphs bfs dfs
Graphs bfs dfs
 
linked lists in data structures
linked lists in data structureslinked lists in data structures
linked lists in data structures
 
Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures
 

Similar to Tree Traversal Algorithm in Data Structure

Data structure and algorithm
Data structure and algorithmData structure and algorithm
Data structure and algorithmSabthamiS1
 
22R01A66C6 DSP.pptx
22R01A66C6 DSP.pptx22R01A66C6 DSP.pptx
22R01A66C6 DSP.pptxSaiM947604
 
Binary tree traversal ppt
Binary tree traversal pptBinary tree traversal ppt
Binary tree traversal pptPREEYANKAV
 
Creating a Binary tree from a General Tree.pptx
Creating a Binary tree from a General Tree.pptxCreating a Binary tree from a General Tree.pptx
Creating a Binary tree from a General Tree.pptxDeepaThirumurugan
 

Similar to Tree Traversal Algorithm in Data Structure (7)

Data structure and algorithm
Data structure and algorithmData structure and algorithm
Data structure and algorithm
 
Tree traversal techniques
Tree traversal  techniquesTree traversal  techniques
Tree traversal techniques
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
 
22R01A66C6 DSP.pptx
22R01A66C6 DSP.pptx22R01A66C6 DSP.pptx
22R01A66C6 DSP.pptx
 
Binary tree traversal ppt
Binary tree traversal pptBinary tree traversal ppt
Binary tree traversal ppt
 
Tree Traversal
Tree TraversalTree Traversal
Tree Traversal
 
Creating a Binary tree from a General Tree.pptx
Creating a Binary tree from a General Tree.pptxCreating a Binary tree from a General Tree.pptx
Creating a Binary tree from a General Tree.pptx
 

More from Meghaj Mallick

PORTFOLIO BY USING HTML & CSS
PORTFOLIO BY USING HTML & CSSPORTFOLIO BY USING HTML & CSS
PORTFOLIO BY USING HTML & CSSMeghaj Mallick
 
Introduction to Software Testing
Introduction to Software TestingIntroduction to Software Testing
Introduction to Software TestingMeghaj Mallick
 
Introduction to System Programming
Introduction to System ProgrammingIntroduction to System Programming
Introduction to System ProgrammingMeghaj Mallick
 
Icons, Image & Multimedia
Icons, Image & MultimediaIcons, Image & Multimedia
Icons, Image & MultimediaMeghaj Mallick
 
Project Tracking & SPC
Project Tracking & SPCProject Tracking & SPC
Project Tracking & SPCMeghaj Mallick
 
Architecture and security in Vanet PPT
Architecture and security in Vanet PPTArchitecture and security in Vanet PPT
Architecture and security in Vanet PPTMeghaj Mallick
 
Design Model & User Interface Design in Software Engineering
Design Model & User Interface Design in Software EngineeringDesign Model & User Interface Design in Software Engineering
Design Model & User Interface Design in Software EngineeringMeghaj Mallick
 
Text Mining of Twitter in Data Mining
Text Mining of Twitter in Data MiningText Mining of Twitter in Data Mining
Text Mining of Twitter in Data MiningMeghaj Mallick
 
DFS & BFS in Computer Algorithm
DFS & BFS in Computer AlgorithmDFS & BFS in Computer Algorithm
DFS & BFS in Computer AlgorithmMeghaj Mallick
 
Software Development Method
Software Development MethodSoftware Development Method
Software Development MethodMeghaj Mallick
 
Secant method in Numerical & Statistical Method
Secant method in Numerical & Statistical MethodSecant method in Numerical & Statistical Method
Secant method in Numerical & Statistical MethodMeghaj Mallick
 
Motivation in Organization
Motivation in OrganizationMotivation in Organization
Motivation in OrganizationMeghaj Mallick
 
Partial-Orderings in Discrete Mathematics
 Partial-Orderings in Discrete Mathematics Partial-Orderings in Discrete Mathematics
Partial-Orderings in Discrete MathematicsMeghaj Mallick
 
Hashing In Data Structure
Hashing In Data Structure Hashing In Data Structure
Hashing In Data Structure Meghaj Mallick
 

More from Meghaj Mallick (20)

24 partial-orderings
24 partial-orderings24 partial-orderings
24 partial-orderings
 
PORTFOLIO BY USING HTML & CSS
PORTFOLIO BY USING HTML & CSSPORTFOLIO BY USING HTML & CSS
PORTFOLIO BY USING HTML & CSS
 
Introduction to Software Testing
Introduction to Software TestingIntroduction to Software Testing
Introduction to Software Testing
 
Introduction to System Programming
Introduction to System ProgrammingIntroduction to System Programming
Introduction to System Programming
 
MACRO ASSEBLER
MACRO ASSEBLERMACRO ASSEBLER
MACRO ASSEBLER
 
Icons, Image & Multimedia
Icons, Image & MultimediaIcons, Image & Multimedia
Icons, Image & Multimedia
 
Project Tracking & SPC
Project Tracking & SPCProject Tracking & SPC
Project Tracking & SPC
 
Peephole Optimization
Peephole OptimizationPeephole Optimization
Peephole Optimization
 
Routing in MANET
Routing in MANETRouting in MANET
Routing in MANET
 
Macro assembler
 Macro assembler Macro assembler
Macro assembler
 
Architecture and security in Vanet PPT
Architecture and security in Vanet PPTArchitecture and security in Vanet PPT
Architecture and security in Vanet PPT
 
Design Model & User Interface Design in Software Engineering
Design Model & User Interface Design in Software EngineeringDesign Model & User Interface Design in Software Engineering
Design Model & User Interface Design in Software Engineering
 
Text Mining of Twitter in Data Mining
Text Mining of Twitter in Data MiningText Mining of Twitter in Data Mining
Text Mining of Twitter in Data Mining
 
DFS & BFS in Computer Algorithm
DFS & BFS in Computer AlgorithmDFS & BFS in Computer Algorithm
DFS & BFS in Computer Algorithm
 
Software Development Method
Software Development MethodSoftware Development Method
Software Development Method
 
Secant method in Numerical & Statistical Method
Secant method in Numerical & Statistical MethodSecant method in Numerical & Statistical Method
Secant method in Numerical & Statistical Method
 
Motivation in Organization
Motivation in OrganizationMotivation in Organization
Motivation in Organization
 
Communication Skill
Communication SkillCommunication Skill
Communication Skill
 
Partial-Orderings in Discrete Mathematics
 Partial-Orderings in Discrete Mathematics Partial-Orderings in Discrete Mathematics
Partial-Orderings in Discrete Mathematics
 
Hashing In Data Structure
Hashing In Data Structure Hashing In Data Structure
Hashing In Data Structure
 

Recently uploaded

SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdfSOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdfMahamudul Hasan
 
lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.lodhisaajjda
 
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...David Celestin
 
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...ZurliaSoop
 
Dreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio IIIDreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio IIINhPhngng3
 
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdfAWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdfSkillCertProExams
 
Dreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video TreatmentDreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video Treatmentnswingard
 
Report Writing Webinar Training
Report Writing Webinar TrainingReport Writing Webinar Training
Report Writing Webinar TrainingKylaCullinane
 
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...amilabibi1
 
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven CuriosityUnlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven CuriosityHung Le
 
Introduction to Artificial intelligence.
Introduction to Artificial intelligence.Introduction to Artificial intelligence.
Introduction to Artificial intelligence.thamaeteboho94
 
Zone Chairperson Role and Responsibilities New updated.pptx
Zone Chairperson Role and Responsibilities New updated.pptxZone Chairperson Role and Responsibilities New updated.pptx
Zone Chairperson Role and Responsibilities New updated.pptxlionnarsimharajumjf
 
Uncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoUncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoKayode Fayemi
 
My Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle BaileyMy Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle Baileyhlharris
 
Digital collaboration with Microsoft 365 as extension of Drupal
Digital collaboration with Microsoft 365 as extension of DrupalDigital collaboration with Microsoft 365 as extension of Drupal
Digital collaboration with Microsoft 365 as extension of DrupalFabian de Rijk
 

Recently uploaded (17)

SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdfSOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
 
lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.
 
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
 
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
 
Dreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio IIIDreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio III
 
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdfAWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
 
Dreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video TreatmentDreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video Treatment
 
in kuwait௹+918133066128....) @abortion pills for sale in Kuwait City
in kuwait௹+918133066128....) @abortion pills for sale in Kuwait Cityin kuwait௹+918133066128....) @abortion pills for sale in Kuwait City
in kuwait௹+918133066128....) @abortion pills for sale in Kuwait City
 
Report Writing Webinar Training
Report Writing Webinar TrainingReport Writing Webinar Training
Report Writing Webinar Training
 
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
 
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven CuriosityUnlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
 
Introduction to Artificial intelligence.
Introduction to Artificial intelligence.Introduction to Artificial intelligence.
Introduction to Artificial intelligence.
 
ICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdfICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdf
 
Zone Chairperson Role and Responsibilities New updated.pptx
Zone Chairperson Role and Responsibilities New updated.pptxZone Chairperson Role and Responsibilities New updated.pptx
Zone Chairperson Role and Responsibilities New updated.pptx
 
Uncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoUncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac Folorunso
 
My Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle BaileyMy Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle Bailey
 
Digital collaboration with Microsoft 365 as extension of Drupal
Digital collaboration with Microsoft 365 as extension of DrupalDigital collaboration with Microsoft 365 as extension of Drupal
Digital collaboration with Microsoft 365 as extension of Drupal
 

Tree Traversal Algorithm in Data Structure

  • 1. BIRLA INSTITUTE OF TECHNOLOGY,MESRA JAIPUR CAMPUS Presented By: Apoorva Nagar MCA/25013/18 TREE TRAVERSAL ALGORITHMS
  • 3. BINARY TREES • A Binary tree is a tree with all nodes having at most two branches. • Each node have a degree of at most two. • Binary tree can be empty or consists of a root node and two disjoint binary trees termed left subtree and right subtree
  • 4. BINARY TREE TRAVERSAL • A traversal of a binary tree is where its nodes are visited in a particular but in repetitive order. • A traversal is governed by three action.They are: Move Left(L) Move Right(R) Processed Node(P) • All these action yield into many different combination out of which three most significant combination result into three traversal ways.They are: Inorder Traversal—LPR Postorder Traversal—LRP Preorder Traversal—PLR
  • 5. INORDER TRAVERSAL ALGORITHM: Recursive procedure to perform Inorder traversal of a binary tree. Procedure INORDER_TRAVERSAL(NODE) If NODE NIL then { call INORDER_TRAVERSAL(LCHILD(NODE)); print (DATA (NODE)); call INORDER_TRAVERSAL(RCHILD(NODE)); } end INORDER_TRAVERSAL.
  • 6. • The traversal keeps moving left in the binary tree until one can move no further, processes the node and moves to the right to continue its traversal again. • In the absence of any node to the right, it retracts backward by a node and continue its traversal. • Consider a binary tree Inorder traversal output is: G H F I E A B D C
  • 7. POSTORDER TRAVERSAL ALGORITHM: Recursive procedure to perform postorder traversal of a binary tree Procedure POSTORDER_TRAVERSAL(NODE) If NODE NIL then { call POSTORDER_TRAVERSAL(LCHILD(NODE)); call POSTORDER_TRAVERSAL(RCHILD(NODE)); print (DATA(NODE)); } end POSTORDER_TRAVERSAL.
  • 8. • The traversal proceeds by keeping to the left until it is no further possible,turns right to continue its traversal. • If there is no right node, processes the node and retraces its direction by one node to continue its traversal. • Consider a binary tree Postorder Traversal output is: G F E I H D C B A
  • 9. PREORDER TRAVERSAL ALGORITHM: Recursive procedure to perform preorder traversal of a binary tree Procedure PREORDER_TRAVERSAL(NODE) If NODE NIL then { print (DATA (NODE)); call PREORDER_TRAVERSAL(LCHILD(NODE)); call PREORDER_TRAVERSAL(RCHILD(NODE)); } end PREORDER_TRAVERSAL.
  • 10. • The traversal process every node as it moves to left until it can move no further.Now it turns right to begin again. • If there is no node in the right, retracts until it can move right to continue its traversal. • Consider a binary tree Preorder Traversal output is: A H G I F E B C D
  • 11. USES OF TREE TRAVERSAL In case of binary search trees (BST), Inorder traversal gives nodes in non-decreasing order. Preorder and Inorder traversals are used to create a copy of the tree. Postorder traversal is used to delete the tree.