PRASHNIKAप्रश्निका
‹ Back to the paper

If binary search technique uses recursion instead of iteration, the code: i. will contain two base…

Computer Science20251 markMCQ
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

AI

Correct 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.
Recursion

From ISC Computer Science - Competency Focused Practice Questions (CISCE, August 2024), question 5.