Traversal of binary tree: A node is visited only once in the traversal of the binary tree. There are three main types of traversal methods in the binary tree.

  1. In-order traversal
  2. Pre-order traversal
  3. Post-order traversal

In-order traversal: 

In the in-order traversal method, the left child and left subtree are traversed first, afterward the root tree and then the right children or the right subtree are traversed.

Algorithm of In-order traversal

Example: Find the in-order traversal for this tree.

Traversal of binary tree

Solution.

Traversal of binary tree

Step 1: Left sub-tree is 1 → 4 → 9

Step 2: Root node is 5

Step 3: Right sub-tree is 5 → 7 → 2 → 6 → 3    

In-order Traversal = 1 → 4 → 9 → 5 → 5 → 7 → 2 → 6 → 3

Pre-order Traversal:

In the pre-order traversal method, the root node is traversed first, then the left subtree, and then the right subtree is traversed.

Algorithm of pre-order traversal

Example: Find the pre-order traversal for this tree.

Traversal of binary tree

Solution.

Traversal of binary tree

 Step 1: Root node is 5

Step 2: Left sub-tree is 4 → 1 → 9

Step 3: Right sub-tree is 6 → 7 → 5 → 2 → 3    

Pre-order Traversal = 5 → 4 → 1 → 9 → 6 → 7 → 5 → 2 → 3

Post-order traversal:

In the post-order traversal method, the left child and left subtree are traversed first, then the right subtree is traversed, and then the root node.

Algorithm of Post-order traversal

Example: Find the Post-order traversal for this tree.

Traversal of binary tree

Solution.

Traversal of binary tree

Applications of binary tree

  1. The binary search tree is used in many search applications.
  2. Nowadays, a binary Space Partition is used for every 3D game.3.
  3. The binary tree is used in every high bandwidth router that stores the router table.

Binary tree program in C language

Pin It on Pinterest

Share This