What is the Tree Traversal in DSA? with Free Notes

What is the Tree Traversal in DSA?

Tree Traversal in DSA involving the process of visiting all nodes in a tree Data Structure. It is essential for various types of operations like, searching, sorting and manipulating series data. We have Four Methods of Tree Traversal in DSA.

1. Pre Order Traversal

In The Pre Order Traversal, the root node is processed before its child nodes. This method is useful when you need to create a copy of the tree or evaluate expressions represented in tree form. This visits the node in the following order,

  1. Visit the Root
  2. Traverse the Left Subtree
  3. Traverse the Right Subtree
DSA Hand-Written-Notes

2. In Order Traversal

In Order Traversal, the left subtree is processed first, followed by the root, and then the right subtree. This Method is widely used in Binary Search tree (BST) as it retrieves nodes in accessing order. It visits the nodes in the following order.

  1. Traverse the Left Subtree
  2. Visit the Root
  3. Traverse the Right Subtree

3. Post Order Traversal

In Post Order Traversal, the root node is processed after its child nodes. This method is useful for deleting trees or evaluating postfix expressions. It visits the nodes in the following order.

  1. Traverse the Left Subtree
  2. Traverse the Right Subtree
  3. Visit the Root

4. Level Order Traversal

Level Order Traversal which is also known as Breadth – First Traversal. Here Nodes are visited level by level which is started from the root and moving downwards. This method is widely used for finding the shortest path in unweighted trees and for many Graph Algorithms. It visits the nodes level by level from left to right.

  1. Visit the Nodes at the current level
  2. Move to the next level and repeat

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top