Given a list numList of n elements and key value K, arrange the following steps for finding the position of the key K in the numList using binary search algorithm i.e. BinarySearch(numList, key)
(A) Calculate mid = (first+last)//2
(B) SET first = 0, last = n-1
(C) PRINT “Search unsuccessful”
(D) WHILE first <= last REPEAT
IF numList[mid] = key
PRINT “Element found at position”, mid+1
STOP
ELSE
IF numList[mid] > key, THEN last = mid-1
ELSE first = mid + 1
Given a list numList of n elements and key value K, arrange the following steps for finding the position of the key K in the numList using binary search algorithm i.e. BinarySearch(numList, key)
(A) Calculate mid = (first+last)//2
(B) SET first = 0, last = n-1
(C) PRINT “Search unsuccessful”
(D) WHILE first <= last REPEAT
IF numList[mid] = key
PRINT “Element found at position”, mid+1
STOP
ELSE
IF numList[mid] > key, THEN last = mid-1
ELSE first = mid + 1
Solution
(B) SET first = 0, last = n-1
(A) Calculate mid = (first+last)//2
(D) WHILE first <= last REPEAT, comparing numList[mid] with key and narrowing the range
(C) PRINT "Search unsuccessful"
The search range must be set first, so (B) comes first. Mid needs first and last, so (A) follows (B). Step (D) uses mid, so it comes after (A). The "Search unsuccessful" message is reached only after the loop ends without finding the key, so (C) is last.
Option 1: (A) comes before (B), but mid cannot be calculated before first and last are set.
Options 2 and 4: (D) comes first, but the loop uses first, last and mid, which are not yet defined.
Related questions:
2026: 29 May Shift 1
2026: 18 May Shift 2
2026: 13 May Shift 2