Binary tree is 2n-2 this question was asked in MS also...
Best Regards Ashish Goel "Think positive and find fuel in failure" +919985813081 +919966006652 On Sun, Dec 4, 2011 at 4:59 PM, Ashish Goel <ashg...@gmail.com> wrote: > wouldn't a binary tree do? > Best Regards > Ashish Goel > "Think positive and find fuel in failure" > +919985813081 > +919966006652 > > > On Tue, Nov 29, 2011 at 3:17 AM, Dave <dave_and_da...@juno.com> wrote: > >> @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 <atul.87fri...@gmail.com> 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 <ak4u2...@gmail.com> >> 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 < >> nitin.garg.i...@gmail.com>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 algogeeks@googlegroups.com. >> > >> To unsubscribe from this group, send email to >> > >> algogeeks+unsubscr...@googlegroups.com. >> > >> 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 algogeeks@googlegroups.com. >> > > To unsubscribe from this group, send email to >> > > algogeeks+unsubscr...@googlegroups.com. >> > > 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 algogeeks@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com. >> 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 algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.