The Definition of isomorphic trees given in the first post is incomplete We say two rooted unordered trees are isomorphic if 1. a tree with a single node (the root) is only isomorphic to a tree with a single node; 2. two trees with roots A and B, none of which is a single-node tree, are isomorphic if and only if there is a 1-1 correspondence between the subtrees of A and the subtrees of B such that corresponding subtrees are isomorphic.
Lets say each node has an additional field that says the number of children it has. bool IsIsomorphic(Node* T1,Node* T2) { if( T1 == null && T2 == null ) return true; if( T1->numChilderen == T2->numChilderen) { if(IsIsomorphic(( T1->left,T2->left) && IsIsoMorphic(T1->right,T2->right)) || (IsIsoMorphic(T1->right,T2->left) && IsIsomorphic(T1->left,T2->Right)); } else return false; } Correct me if needed ! On Wed, Jun 9, 2010 at 8:29 PM, divya jain <sweetdivya....@gmail.com> wrote: > @vadivel and anand > > { 1,2,3 } is *isomorphic* to { 1,3,2 } > { 1,2,3,4,5,6,7 } is *isomorphic* to { 1,3,2,7,6,4,5 } > { 1,2,3,4,5,6,7 } is NOT *isomorphic* to { 1,3,2,4,5,6,7 } > > so its nt necessary that right and left will interchange. it may or may > not. if all right and left are interchanged then it is mirror tree. i think > ur code is for mirror tree and not isomorphic tree.. > > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.