This post is completed by 1 user

  • 0
Add to List
Beginner

Given a binary tree, Convert it into its Mirror Tree

Objective: Given a binary tree, Convert it into its Mirror Tree

Mirror Tree: Mirror Tree of a binary tree is where left and right child of every node of given binary tree is interexchanged.

Input: A binary tree.

Example:

Mirror Tree
Mirror Tree

Approach:

  • Do the PreOrder Traversal.
  • Starting from the root, swap the left and right childs.
  • Recursively call the same procedure in the leftsubtree and right subtree.

Code:


Output:

1 2 3 4 5 6 7
 Mirror Image  7 6 5 4 3 2 1



Also Read: