Check if Tree is Isomorphic
Write a function to detect if two trees are isomorphic. Two trees are called isomorphic if one of them can be obtained from other by a series of flips, i.e. by swapping left and right children of a number of nodes. Any number of nodes at any level can have their children swapped.
Example1:

These two trees are isomorphic
Swap left child & right child of 1

Swap left & right child of 5

Example 2:

The conditions which needed to be satisfied are:
Pre-requisite:
Two Input binary trees (their roots actually), i.e., root1, root2
FUNCTION isIsomorphic(Node *root1,Node *root2) 1. Both are empty then it's isomorphic. //condition-1 IF (!root1 && !root2) return true; If particularly exactly one of them is empty, then they can't be isomorphic.//extension of condition-1 IF(!root1 || !root2) return false; 2. If root value are different, they can't be isomorphic//condition-2 IF(root1->data!=root2->data) return false; 3. Check condition-3 Recursively checking subtrees return ( ( isIsomorphic(root1->left,root2->left) && isIsomorphic(root1->right,root2->right) ) || (isIsomorphic(root1->right,root2->left) && isIsomorphic(root1->left,root2->right))); END FUNCTIONC++ implementation
Output
Explanation with example
Let's check the example-1
Nodes are represented by their respective values for better understanding
You can check the second example same way & can find returning FALSE
need an explanation for this answer? contact us directly to get an explanation for this answer