@Navneet: Don't we want both subtrees to be isomorphic?

Dave

On Aug 28, 6:40 am, Navneet <navneetn...@gmail.com> wrote:
> Dave,
>
> I think the last condition should be
>
> return (AreIsomorphic(tree1->left, tree2->left) && 
> AreIsomorphic(tree1->right,tree2->right)) ||
>
>        (AreIsomorphic(tree1->left, tree2->right) &&
> AreIsomorphic(tree1->right,tree2->left))
>
> On Aug 28, 3:39 pm, Ankur Garg <ankurga...@gmail.com> wrote:
>
>
>
> > Daves solution looks cool to me...shud work :)
>
> > Nice one Dave :)
>
> > Regards
> > Ankur
>
> > On Sun, Aug 28, 2011 at 4:08 PM, Ankur Garg <ankurga...@gmail.com> wrote:
> > > cant we just count the no of nodes in each level and compare them with the
> > > second one..
>
> > > if the numbers are same trees can be said to be isomorphic
>
> > > On Sun, Aug 28, 2011 at 3:54 AM, Dave <dave_and_da...@juno.com> wrote:
>
> > >> @Bugaboo: Use recursion. Assuming
>
> > >> struct tree_node {
> > >>    tree_node *left;
> > >>    tree_node *right;
> > >>    int data;
> > >> };
>
> > >> int AreIsomorphic(tree_node tree1, tree_node tree2)
> > >> {
> > >>    if( tree1 == NULL && tree2 == NULL )
> > >>        return TRUE; // both trees are null
> > >>    if( tree1 == NULL || tree2 == NULL)
> > >>        return FALSE; // one tree is null, the other is not
> > >>    return AreIsomorphic(tree1->left,tree2->left) &&
> > >>             AreIsomorphic(tree1->right,tree2->right);
> > >> }
>
> > >> Dave
>
> > >> On Aug 27, 12:05 pm, bugaboo <bharath.sri...@gmail.com> wrote:
> > >> > Considering the definition of binary tree isomorphism is the
> > >> > following:
> > >> > - 2 binary trees are isomorphic if they have the same structure but
> > >> > differ just by values.
>
> > >> > What is the logic (or pseudo code) for checking if two binary trees
> > >> > are isomorphic?
>
> > >> --
> > >> You received this message because you are subscribed to the Google Groups
> > >> "Algorithm Geeks" group.
> > >> To post to this group, send email to algogeeks@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.- Hide quoted text -
>
> - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@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.

Reply via email to