On Mon, Oct 12, 2009 at 1:29 PM, ankur aggarwal <[email protected]>wrote:
> @shishir
> can u give the ds
>
data structure used is a binary tree, with each node key being the maximum
of its two children's key values.
Space complexity of implementation of tournament principle is O(n).
> how would u save the history part ("save the data that was rejected by the
> highest element in order to get the 2nd highest")
>
> extra space will b required.. :(
>
> I don't think that the problem statement suggest any constraint in the
memory. The only objective is to reduce the number of comparisons to n +
ceil(log n) - 2 from (n-1 + n-2) comparisons that would be required in case
of a naive algorithm where one first finds the maximum and then finds the
maximum of the remaining elements of the array.
--
Shishir Mittal
Ph: +91 9936 180 121
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---