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

1 Response

  1. Gaurav says:

    Nice article. Thanks

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: