Take numbers in pair of 2, compare with each other and then compare the
maximum among them with max (maximum element so far) and minimum among them
with min (minimum element so far) , In this way you will be able to find
max, min in 3 comparisons for each 2 integers. Hence 3n/2 comparisons
needed for finding min and max simultaneously in an array.


On Mon, Nov 28, 2011 at 9:56 PM, Nitin Garg <[email protected]>wrote:

> Find the min and max in an array. Now do it in less than 2n comparisons.
> (they were looking for the solution that finds both max and min in about
> 3/2 n comparisons).
>
>
> --
> Nitin Garg
>
> "Personality can open doors, but only Character can keep them open"
>
> --
> 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.
>



-- 
Aamir Khan | 3rd Year  | Computer Science & Engineering | IIT Roorkee

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