The document discusses tree traversal methods in data structures, specifically focusing on inorder, preorder, and postorder traversals. Each traversal method is explained with its respective algorithm and examples, demonstrating how they process nodes in a binary tree. Additionally, the document provides recursive routines for implementing these traversal methods in code.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
1 views
05-Tree Traversals
The document discusses tree traversal methods in data structures, specifically focusing on inorder, preorder, and postorder traversals. Each traversal method is explained with its respective algorithm and examples, demonstrating how they process nodes in a binary tree. Additionally, the document provides recursive routines for implementing these traversal methods in code.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15
Data Structures and Algorithms
Tree Traversals
B.Bhuvaneswaran, AP (SG) / CSE
9791519152 [email protected] Introduction The process of visiting all nodes of a tree is called tree traversal. Each node is processed only once but it may be visited more than once.
Tree Traversals Rajalakshmi Engineering College 2
Types of Tree Traversal Inorder traversal Preorder traversal Postorder traversal
Tree Traversals Rajalakshmi Engineering College 3
Inorder Traversal The inorder traversal of a binary tree is performed as: • Traverse the left subtree in inorder • Visit the root • Traverse the right subtree in inorder The inorder traversal of the binary tree for an arithmetic expression gives the expression in an infix form.
Preorder Traversal The preorder traversal of a binary tree is performed as: • Visit the root • Traverse the left subtree in preorder • Traverse the right subtree in preorder The preorder traversal of the binary tree for the given expression gives in prefix form.
Postorder Traversal The postorder traversal of a binary tree is performed by: • Traverse the left subtree in postorder • Traverse the right subtree in postorder • Visit the root The postorder traversal of the binary tree for the given expression gives in postfix form.
Tree Traversals Rajalakshmi Engineering College 10
Example BACEHGJKID
Tree Traversals Rajalakshmi Engineering College 11