Home » Data Structure & Algorithms » mirror Tree of a binary Tree

mirror Tree of a binary Tree

 

Question :
WAP to program to convert a binary tree to its mirror tree in O(n) time complexity.

Solution :
The problem is solved in recussive way.

Algorithm :
A leaf node is a node which has no left and right child.
Step 1 : If node is NULL then return.
Step 2 : Recurssively traverse left and right sub-tree by calling mirrorTree() method;
Step 3 : Swap the nodes of left sub-tree and right sub-tree.

Program :

 


Leave a comment

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

sixteen − 7 =