Home » Programming & Data Structure » Programming and data structure miscellaneous » Question

Programming and data structure miscellaneous

Programming & Data Structure

  1. An array of n numbers is given, where n is an even number. The maximum as well as the minimum of these n numbers needs to be determined. Which of the following is true about the number of comparisons needed?
    1. At least 2n – c comparisons, for some constant c, are needed
    2. At most 1.5n – 2 comparisons are needed
    3. At least nlog2 n comparisons are needed
    4. None of the above
Correct Option: B

One possible way to do this is we select first element as max & also min. Then we compare it with all others. At most this would take 2n comparisons during linear search. But if we use divide & conquer as for merge sort we have.
T(n) 2T(n / 2) + 2 for n > 2
T(n) = 3n / 2 – 2
= 1.5n - 2



Your comments will be displayed only after manual approval.