Prashnikaप्रश्निका
Code
About
‹ Back to the paper

Question 5

1 mark

Computer ScienceISC Computer Science - Competency Focused Practice Questions (CISCE, August 2024)MCQRecursion

Choose the correct option.

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?
  • (a)i and ii
  • (b)ii and iii
  • (c)i and iii
  • (d)Only iii

Answer

Answer

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.