‹ Back to the paper
If binary search technique uses recursion instead of iteration, the code: i. will contain two base…
If binary search technique uses recursion instead of iteration, the code:
i. will contain two base cases.
ii. will contain two recursive cases.
iii. when executed will lead to an exception, stack overflow.
Which of the above is valid?
- ai and ii
- bii and iii
- ci and iii
- dOnly iii
Answer
Answer
AICorrect option: a
Answer: (a) i and ii.
A recursive binary search needs two base cases - element found, and search range exhausted (low > high) - and its code contains two possible recursive calls, one for the left half and one for the right half (only one executes per call). Statement iii is false: since the search range halves each call, the recursion depth is only about log2(n), so it does not cause a stack overflow.
From ISC Computer Science - Competency Focused Practice Questions (CISCE, August 2024), question 5.