Do an inorder walk on T1 till you get the root of T2.

Then do a simultaneous walks on both the trees till T2(smaller tree) is
fully explored.

If at any point you discover dissimilar nodes. print 'no'
else print 'yes'

One more issue is if duplicates are allowed, then we cant print 'no' with
just one failure, repeat till you explore the bigger tree fully.
Correct me if i am wrong.

On Sat, Jan 8, 2011 at 9:31 PM, Harshal <[email protected]> wrote:

> Given two binary trees T1 and T2 which store character data, duplicates
> allowed. You have to devise an algorithm to decide whether the T2 is a
> subtree of T1. T1 has millions of nodes and T2 has hundreds of nodes.
>
> --
> Harshal Choudhary,
> III Year B.Tech Undergraduate,
> Computer Science and Engineering,
> National Institute of Technology Surathkal, Karnataka
> India.
>
>  --
> 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.
>



-- 
S.Nishaanth,
Computer Science and engineering,
IIT Madras.

-- 
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.

Reply via email to