Site icon i2tutorials

Data Structures-Binary Tree Traversals

Binary Tree Traversals

 

Binary tree traversals can be done in the following ways:

  1. In order traversals
  2. Preorder traversals 
  3. Postorder traversals

 

In order traversals 

In order traversals specify nodes in non-descending order. 

 

Preorder traversals

Preorder traversals create a copy of the tree. It is also used to get the prefix expression of the expression.

 

Postorder traversals

Postorder traversals are used to get the postfix expression of the expression given. 

 

Algorithm for binary tree traversals:

 

 

Step 1: Traverse the left sub-tree.

Step 2: Print the root node.

Step 3: Traverse the right sub-tree. 

 

 

 

Step 1: Print the root node.

Step 2: Traverse the left sub-tree.

Step 3: Traverse the right sub-tree. 

 

 

 

Step 1: Traverse the left sub-tree.

Step 2: Traverse the right sub-tree.

Step 3: Print the root node. 

 

Reference

Binary Tree Traversals

Exit mobile version