DATA STRUCTURE
Programming and Technical
Programming
Technical
How many minimum number of comparisons required to find minimum and maximum of 100 numbers
Read Solution (Total 9)
-
- It requires 148 comparisons.
To find maximum or minimum it take 3n/2 -2 comparissions
So 150-2=148 - 10 years agoHelpfull: Yes(5) No(0)
- minimum comparisions will be 99
min=arr[0];
max=arr[0];
for(i=1;i - 10 years agoHelpfull: Yes(4) No(0)
- 98 comparisons only
- 10 years agoHelpfull: Yes(1) No(0)
- Ans: minimum number of comparison require to find minimum and maximum is: Approach is divide and conquer ....
T(n) = T(floor(n/2)) + T(ceil(n/2)) + 2
T(2) = 1 // if two element then compare both and return max and min
T(1) = 0 // if one element then return both max and min same
If n is a power of 2, then we can write T(n) as:
T(n) = 2T(n/2) + 2
After solving above recursion, we get
T(n) = 3/2n -2
Thus, the approach does 3/2n -2 comparisons if n is a power of 2. And it does more than 3/2n -2 comparisons if n is not a power of 2.
So, here in this case put n=100 and we will get (3/2)(100) - 2 = 148 comparison ..... - 7 years agoHelpfull: Yes(1) No(0)
- How 98??
Please explain. - 10 years agoHelpfull: Yes(0) No(0)
- Using Merge sort or Heap sort, we can find min. and max. 100 nos. as worst case efficiency for both algorithms is o(nlog n)... i.e. 100*log 100 = 200.
- 10 years agoHelpfull: Yes(0) No(0)
- 98 comparisions
- 10 years agoHelpfull: Yes(0) No(0)
- n-1 => 99 comparisons given the data is unsorted.
- 10 years agoHelpfull: Yes(0) No(0)
- 1 + 2(n-2) in worst case and 1 + n – 2 in best case
here consider best case.
1+n-2
=1+100-2
=99
- 10 years agoHelpfull: Yes(0) No(0)
DATA STRUCTURE Other Question