Write a recursive algorithm that tests if the trees rooted at two given tree nodes are isomorphic. Given that the question requests a signature: isIsomorphic(treeNode A, treeNode B) with input of treeNode A and treeNode B and boolean output of true or false depending on whether A and B are isomorphic or not, I am confused as to how I can use recursion since I don't see how the indices of whatever can be tracked with such an input. If more information is needed, just ask and any help would be greatly appreciated! Thanks in advance!
I would write a recursive function that reads one tree. Then add the code to do a second tree at the same time (mostly mirroring any mention of the first tree's variable name). At every point, both traversals need to have the same result: if( A->left != NULL) && ( B->left != NULL ) { // traverse the left nodes } else return false;
Join our real-time social learning platform and learn together with your friends!