take the inorder and preorder traversal of both the trees. store the inorder traversal of T1 and T2 in I1 and I2 respectively and store the preorder traversal of T1 and T2 in P1 and P2 respectively.
now if I1 is a substring in I2 and P1 is a substring of P2 then T1 is a part of T2. i hope it works. On 6/21/10, sharad <[email protected]> wrote: > > Given two n-ary trees T1 and T2. Write a program to check if T1 has T2 > in it. > > -- > 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.
