Question 6 A sorted list of ten numbers is given as A:[0,1,2,3,4,5,6,8,9,10].
Sigmoid technical mcq question, verified with a worked answer. Free to practise - no sign-up.
A sorted list of ten numbers is given as A:[0,1,2,3,4,5,6,8,9,10]. The requirement is to find the first missing element index. In this case 7 is the missing element.
Select the correct binary search algorithm for the above requirement.
Show answer & explanation
Answer: C. C) 1. Compare the middle value and middle index.
In an array of elements 0..n with one missing number, comparing A[mid] with mid determines if the missing element is to the left (A[mid] > mid) or right (A[mid] == mid).
Step-by-step Derivation:
Step 1: Before the missing element, A[i] == i. After the missing element, A[i] == i + 1.
Step 2: Checking if A[mid] == mid allows O(log n) binary search.