Make a Self Balancing BST like RB Tree or AVL Tree, lets call it T. ( O(n) )
Perform an inorder traversal of the Binary tree and for every element keep
it inserting it to T only if its not found in T. If its found, then its
repeated. (  O(logn) )

Total Time: O(nlogn)
Total Space: O(n)

Or use a hashmap instead of RB-Tree
Total Time: O(n)
Total Space: O(1)

Anurag Sharma


On Fri, Jun 25, 2010 at 5:34 PM, RIDER <[email protected]> wrote:

> you are given a binary tree (not a BST) .how to find is there is  any
> element which occurs twice and if so what is value ?
>
> --
> 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.

Reply via email to