Two binary trees are isomorphic if they have the same shape

Two binary trees are isomorphic if they have the same shape (i.e. they have identical structures.) Implement the following recursive method: public static boolean isomorphic(BTNode T1, BTNode T2) {/* your code here */} that returns true if the trees rooted at T1 and T2 are isomorphic, and false otherwise. BTNode is defined as follows: public class BTNode {T data; BTNode left, right; BTNode(T data, BTNode left, BTNode right) {this.data = data; this.left = left; this.right = right;}}

Solution

public static boolean isomorphic(BTNode T1, BTNode T2) { if(T1 == null && T2 == null){ return true; } if(T1 == null || T2 == null){ return false; } if(!isomorphic(T1.left, T2.left)){ return false; } else{ return isomorphic(T1.right, T2.right); }
 Two binary trees are isomorphic if they have the same shape (i.e. they have identical structures.) Implement the following recursive method: public static bool

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site