Question:medium

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 the binary search algorithm i.e. BinarySearch(numList, key).

 

  1. (A) Calculate mid = (first + last) // 2
  2. (B) SET first = 0, last = n - 1
  3. (C) PRINT "Search unsuccessful"
  4. (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

Show Hint

Binary search steps: Initialize → Calculate mid → Compare in loop → Print unsuccessful if not found.
Updated On: Feb 15, 2026
  • (A), (B), (D), (C)
  • (D), (B), (A), (C)
  • (B), (A), (D), (C)
  • (D), (A), (B), (C)
Show Solution

The Correct Option is C

Solution and Explanation

Step 1: Initialization.
Establish search boundaries: set first = 0 and last = n-1. → (B).
Step 2: Midpoint Calculation.
Determine the middle index: calculate mid = (first + last) // 2. → (A). 
Step 3: Iterative Search.
Continue as long as first <= last: compare the target key with the element at numList[mid]. If they match, the element is found. If the key is smaller, adjust the upper boundary (last = mid - 1); otherwise, adjust the lower boundary (first = mid + 1). → (D). 
Step 4: Search Failure.
If the loop completes without locating the element, indicate an unsuccessful search. → (C). 
Final Answer:\[\r  \boxed{(B), (A), (D), (C)}\r  \]

Was this answer helpful?
0


Questions Asked in CUET (UG) exam