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.

Complete Code:


Output:

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

__________________________________________________
Top Companies Interview Questions..-

Google Microsoft Amazon Facebook more..

If you find anything incorrect or you feel that there is any better approach to solve the above problem, please write comment.
__________________________________________________

  • Gaurav

    Nice article. Thanks

%d bloggers like this: