One approach is to parse the element of the two tree in two arrays and
compare the arrays to fiind if they are isomorphic.
parsing takes O(n).
Comparision takes O(n/2)
for (i=0;i<n;i++)
{
if(2i+1 > n)
break;
if(arr_1[2i] != arr_2[2i+1])
{
break;
}
}
if(i == n/2)
printf("trees are isomorphic\n");
On Tue, Jun 8, 2010 at 8:01 AM, divya <[email protected]> wrote:
> Two binary trees T1 and T2 are isomorphic if T1 can be transformed
> into T2 swapping left and right children of the nodes in T1.Give an
> algorithm to report whether 2 given 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 [email protected].
> To unsubscribe from this group, send email to
> [email protected]<algogeeks%[email protected]>
> .
> 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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.