Tree isomorphism Two unordered binary trees A and B are said to be isomorphic if
ID: 3864278 • Letter: T
Question
Tree isomorphism Two unordered binary trees A and B are said to be isomorphic if, by swapping the left and right subtrees of certain nodes of A, one can obtain a tree identical to B. For example, the following two trees are isomorphic: Write the pseudocode of a recursive algorithm that tests if the trees rooted at two given tree Nodes are isomorphic.Explanation / Answer
bool isomorphic(node p, node r) if (p = null & r = null) return true // check for empty trees if true goes outside of test if (p = null || r = null) return false //check for number of subtree and false output else return (isomorphic(p->leftchild, r->leftchild) && isomorphic(p->rightchild, r->rightchild) || (isomorphic(p->leftchild, r->rightchild) && isomorphic(p->rightchild, r->leftchild))
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.