Given an array arr = {45,77,89,90,94,99,100} and key = 99; what are the mid…

2025

Given an array arr = {45,77,89,90,94,99,100} and key = 99; what are the mid values(corresponding array elements) in the first and second levels of recursion?

  1. A.

    90 and 99

  2. B.

    90 and 94

  3. C.

    89 and 99

  4. D.

    89 and 94

Attempted by 51 students.

Show answer & explanation

Correct answer: A

To find the mid values in binary search, we start with the full array.

Step 1: The array is arr = {45,77,89,90,94,99,100}, with indices 0 to 6.

Step 2: The first mid is calculated as (low + high) / 2, where low = 0 and high = 6.

Mid index = (0 + 6) / 2 = 3, so the first mid value is arr[3] = 90.

Step 3: Since the key 99 is greater than 90, the search continues in the right half of the array.

Step 4: The new search range is from index 4 to 6.

Step 5: The second mid is calculated as (4 + 6) / 2 = 5, so the second mid value is arr[5] = 99.

Thus, the mid values at the first and second levels of recursion are 90 and 99.

Explore the full course: Coding For Placement