PA of Algorithms Q99

0. The minimum number of comparisons required to find the minimum and the maximum of 100 numbers is ___________.

  • Option : A
  • Explanation :
    From the list of given n numbers [say n is even], Pick up first two elements, compare them
    assign Current – min = min of two numbers
    Current – max = max of two numbers
    From the remaining n – 2 numbers, take pairs wise and follow this process given below.

    1. Compare two elements
    Assign min = min of two numbers
    max = max of two numbers

    2. Compare min and current – min
    Assign current – min
    = min{current– min,min}

    3. Compare max and current – max
    Assign current – max
    = max{current – max, max}

    Repeat above procedure for all the remaining pairs of numbers. We can observe that each of pair requires 3 comparisons
    1. for finding min and max
    2. For updating current – min
    3. for updating current – max
    But for initial pair we need only one comparison not 3.
    ∴ Total number of comparisons

    Here n =100, so number of comparisons = 148.
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *