SlideShare uma empresa Scribd logo
1 de 12
TREE TRAVERSAL TECHNIQUES
Submitted to: Submitted by:
Mrs.Amrita Parashar Mudita Srivastava
BTC- 7th Sem
INTRODUCTION
• In computer science, tree traversal (also
known as tree search) is a form of graph
traversal and refers to the process of visiting
(checking and/or updating) each node in
a tree data structure, exactly once.
• Such traversals are classified by the order in
which the nodes are visited. The following
algorithms are described for a binary tree, but
they may be generalized to other trees as well.
TYPES OF TECHNIQUES
PRE ORDER (Root, Left, Right)
• Check if the current node is empty / null.
• Display the data part of the root (or current
node).
• Traverse the left subtree by recursively calling
the pre-order function.
• Traverse the right subtree by recursively
calling the pre-order function.
Until all nodes are traversed −
• Step 1 − Visit root node.
• Step 2 − Recursively traverse left subtree.
• Step 3 − Recursively traverse right subtree.
EXAMPLE:
• We start from A, and following pre-order traversal, we
first visit A itself and then move to its left subtree B.
• B is also traversed pre-order. The process goes on until all
the nodes are visited. The output of pre-order traversal
of this tree will be −
A → B → D → E → C → F → G
INORDER(Left, root, right)
• Check if the current node is empty / null.
• Traverse the left subtree by recursively calling
the in-order function.
• Display the data part of the root (or current
node).
• Traverse the right subtree by recursively
calling the in-order function.
Until all nodes are traversed −
• Step 1 − Recursively traverse left subtree.
• Step 2 − Visit root node.
• Step 3 − Recursively traverse right subtree.
• EXAMPLE:
• We start from A, and following in-order traversal,
we move to its left subtree B. B is also traversed
in-order.
• The process goes on until all the nodes are
visited. The output of inorder traversal of this
tree will be −
D → B → E → A → F → C → G
POSTORDER(Left, right, root)
• Check if the current node is empty / null.
• Traverse the left subtree by recursively calling
the post-order function.
• Traverse the right subtree by recursively
calling the post-order function.
• Display the data part of the root (or current
node).
Until all nodes are traversed −
• Step 1 − Recursively traverse left subtree.
• Step 2 − Recursively traverse right subtree.
• Step 3 − Visit root node.
EXAMPLE:
• We start from A, and following Post-order
traversal, we first visit the left subtree B. B is also
traversed post-order.
• The process goes on until all the nodes are
visited. The output of post-order traversal of this
tree will be −
D → E → B → F → G → C → A
Tree traversal  techniques

Mais conteúdo relacionado

Mais procurados

Insertion sort
Insertion sortInsertion sort
Insertion sort
MYER301
 

Mais procurados (20)

Tree Traversal
Tree TraversalTree Traversal
Tree Traversal
 
Merge Sort
Merge SortMerge Sort
Merge Sort
 
Binary search tree operations
Binary search tree operationsBinary search tree operations
Binary search tree operations
 
Linked list
Linked listLinked list
Linked list
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data Structure
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
 
3.9 external sorting
3.9 external sorting3.9 external sorting
3.9 external sorting
 
Tree Traversal Algorithm in Data Structure
Tree Traversal Algorithm in Data StructureTree Traversal Algorithm in Data Structure
Tree Traversal Algorithm in Data Structure
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
Selection sort
Selection sortSelection sort
Selection sort
 
Linked list
Linked list Linked list
Linked list
 
Tree traversal techniques
Tree traversal techniquesTree traversal techniques
Tree traversal techniques
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
Merge sort
Merge sortMerge sort
Merge sort
 
Different Sorting tecniques in Data Structure
Different Sorting tecniques in Data StructureDifferent Sorting tecniques in Data Structure
Different Sorting tecniques in Data Structure
 
Binary search
Binary searchBinary search
Binary search
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 

Semelhante a Tree traversal techniques

TREE DATA STRUCTURE SLIDES dsa dsa .pptx
TREE DATA STRUCTURE SLIDES dsa dsa .pptxTREE DATA STRUCTURE SLIDES dsa dsa .pptx
TREE DATA STRUCTURE SLIDES dsa dsa .pptx
asimshahzad8611
 
splaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNN
splaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNNsplaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNN
splaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNN
ratnapatil14
 

Semelhante a Tree traversal techniques (20)

22R01A66C6 DSP.pptx
22R01A66C6 DSP.pptx22R01A66C6 DSP.pptx
22R01A66C6 DSP.pptx
 
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
 
Tree traversal
Tree traversalTree traversal
Tree traversal
 
Binary tree
Binary treeBinary tree
Binary tree
 
Lecture 22_Trees - II.pptx
Lecture 22_Trees - II.pptxLecture 22_Trees - II.pptx
Lecture 22_Trees - II.pptx
 
Data structure and algorithm
Data structure and algorithmData structure and algorithm
Data structure and algorithm
 
Binary search tree
Binary search treeBinary search tree
Binary search tree
 
AVL Tree Data Structure
AVL Tree Data StructureAVL Tree Data Structure
AVL Tree Data Structure
 
Binary Tree - Algorithms
Binary Tree - Algorithms Binary Tree - Algorithms
Binary Tree - Algorithms
 
Binary tree
Binary treeBinary tree
Binary tree
 
Short dec
Short decShort dec
Short dec
 
TREE DATA STRUCTURE SLIDES dsa dsa .pptx
TREE DATA STRUCTURE SLIDES dsa dsa .pptxTREE DATA STRUCTURE SLIDES dsa dsa .pptx
TREE DATA STRUCTURE SLIDES dsa dsa .pptx
 
Tree
TreeTree
Tree
 
C++ UNIT4.pptx
C++ UNIT4.pptxC++ UNIT4.pptx
C++ UNIT4.pptx
 
Splay tree
Splay treeSplay tree
Splay tree
 
splaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNN
splaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNNsplaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNN
splaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNN
 
binary tree
binary treebinary tree
binary tree
 
Unit iv data structure-converted
Unit  iv data structure-convertedUnit  iv data structure-converted
Unit iv data structure-converted
 
Queue (1)(1).ppt
Queue (1)(1).pptQueue (1)(1).ppt
Queue (1)(1).ppt
 
BINARY SEARCH TREE
BINARY SEARCH TREEBINARY SEARCH TREE
BINARY SEARCH TREE
 

Último

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 

Tree traversal techniques

  • 1. TREE TRAVERSAL TECHNIQUES Submitted to: Submitted by: Mrs.Amrita Parashar Mudita Srivastava BTC- 7th Sem
  • 2. INTRODUCTION • In computer science, tree traversal (also known as tree search) is a form of graph traversal and refers to the process of visiting (checking and/or updating) each node in a tree data structure, exactly once. • Such traversals are classified by the order in which the nodes are visited. The following algorithms are described for a binary tree, but they may be generalized to other trees as well.
  • 3. TYPES OF TECHNIQUES PRE ORDER (Root, Left, Right) • Check if the current node is empty / null. • Display the data part of the root (or current node). • Traverse the left subtree by recursively calling the pre-order function. • Traverse the right subtree by recursively calling the pre-order function.
  • 4. Until all nodes are traversed − • Step 1 − Visit root node. • Step 2 − Recursively traverse left subtree. • Step 3 − Recursively traverse right subtree.
  • 5. EXAMPLE: • We start from A, and following pre-order traversal, we first visit A itself and then move to its left subtree B. • B is also traversed pre-order. The process goes on until all the nodes are visited. The output of pre-order traversal of this tree will be − A → B → D → E → C → F → G
  • 6. INORDER(Left, root, right) • Check if the current node is empty / null. • Traverse the left subtree by recursively calling the in-order function. • Display the data part of the root (or current node). • Traverse the right subtree by recursively calling the in-order function.
  • 7. Until all nodes are traversed − • Step 1 − Recursively traverse left subtree. • Step 2 − Visit root node. • Step 3 − Recursively traverse right subtree.
  • 8. • EXAMPLE: • We start from A, and following in-order traversal, we move to its left subtree B. B is also traversed in-order. • The process goes on until all the nodes are visited. The output of inorder traversal of this tree will be − D → B → E → A → F → C → G
  • 9. POSTORDER(Left, right, root) • Check if the current node is empty / null. • Traverse the left subtree by recursively calling the post-order function. • Traverse the right subtree by recursively calling the post-order function. • Display the data part of the root (or current node).
  • 10. Until all nodes are traversed − • Step 1 − Recursively traverse left subtree. • Step 2 − Recursively traverse right subtree. • Step 3 − Visit root node.
  • 11. EXAMPLE: • We start from A, and following Post-order traversal, we first visit the left subtree B. B is also traversed post-order. • The process goes on until all the nodes are visited. The output of post-order traversal of this tree will be − D → E → B → F → G → C → A