in Algorithms
757 views
1 vote
1 vote
in Algorithms
757 views

1 comment

no any option is correct ...
0
0

1 Answer

5 votes
5 votes
Best answer

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/2)n -2 

 Thus, the approach does 3/2n -2 comparisons if n is a power of 2. And it does more than (3/2)n -2 comparisons if n is not a power of 2.

edited by