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?
- A.
90 and 99
- B.
90 and 94
- C.
89 and 99
- 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.