Question:

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: Sep 18, 2025
  • (A), (B), (D), (C)
  • (D), (B), (A), (C)
  • (B), (A), (D), (C)
  • (D), (A), (B), (C)
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is C

Solution and Explanation

Step 1: Initialization.
Binary search begins by setting search boundaries: first = 0, last = n-1. → (B). 
Step 2: Mid calculation.
Compute the middle index: mid = (first + last) // 2. → (A). 
Step 3: Loop until element is found or list exhausted.
Repeat while first <= last: compare key with numList[mid]. If equal, found. If smaller, move left (last = mid - 1), else move right (first = mid + 1). → (D). 
Step 4: Failure case.
If loop exits without finding element, print unsuccessful search. → (C). 
Final Answer:\[  \boxed{(B), (A), (D), (C)}  \]

Was this answer helpful?
0
0

Questions Asked in CUET exam

View More Questions