Two binary trees T1 an T2 and given, the task is to identify if "T1" is a mirror image of "T2".
Solutions
Method 1: Recursion
If two binary trees are mirror image of each other, following conditions must be true:
1) The value of their "root" node should be same.
2) Left subtree of root of "T1" should be a mirror image of right subtree of root of "T2".
3) Right subtree of root of "T1" should be a mirror image of left subtree of root of "T2".
Below is the implementation for above mentioned idea.
Complexity
The time complexity of this solution is O(n) and space complexity is O(h), where "h" is height of binary tree.