@Atul: Your code uses 2*n - 2 comparisons. Thus, it is non-responsive
to the problem of using something close to 3*n/2 comparisons.

Dave

On Nov 28, 12:20 pm, atul anand <[email protected]> wrote:
> void findMinMax(int arr[],int len,int *min,int *max)
> {
>   int tempMin,tempMax,i;
>
>   tempMin=arr[0];
>   tempMax=arr[0];
>   for(i=1;i<len;i++)
>   {
>      if(arr[i] < tempMin)
>      {
>          tempMin=arr[i];
>
>      }
>      if(arr[i] > tempMax)
>      {
>          tempMax=arr[i];
>
>      }
>   }
>
> *min=tempMin;
> *max=tempMax;
>
>
>
> }
> On Mon, Nov 28, 2011 at 10:00 PM, Aamir Khan <[email protected]> wrote:
> > 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.

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