What represents the first three steps of BinarySearch(numlist,key) algorithm?
What represents the first three steps of BinarySearch(numlist,key) algorithm?
Solution
✅ Correct Option: 1
Indexing in a list starts at 0, so the search range begins with and ends with . The middle position is then .
The loop runs only while the search range is valid, that is, while . Once crosses , the range is empty and the key is not present.
Options 2 and 4: setting skips index 0, so the first element is never searched.
Options 3 and 4: the condition is wrong. At the start , so the loop would not run at all (for ).
Related questions:
2026: 23 May Shift 1
2025: 22 May Shift 1
2025: 21 May Shift 1
2025: 20 May Shift 1