MCQ Single Best Answer Moderate

Q[Recursion]
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?

ID: #24938 Competency focused Practice Questions ISC Class XII Computer Science 4 views
Question Info
#24938Q ID
ModerateDifficulty
Competency focused Practice Questions ISC Class XII Computer ScienceTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A i and ii
  • B ii and iii
  • C i and iii
  • D Only iii
Correct Answer: Option A

Explanation

[Recursion]

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
Correct Answer: (a) i and ii

Explanation:

Binary Search can be implemented using recursion. In recursive binary search, the array is repeatedly divided into two halves until the element is found or the search space becomes empty.

Understanding Each Statement:

  • Statement i: "will contain two base cases."
    This statement is correct. Recursive binary search generally contains two base cases:
    • The element is found.
    • The search interval becomes invalid (low > high).
  • Statement ii: "will contain two recursive cases."
    This statement is also correct. Binary search recursively searches:
    • The left half of the array.
    • The right half of the array.
    Therefore, there are two recursive cases.
  • Statement iii: "will lead to stack overflow."
    This statement is incorrect. Binary search reduces the problem size by half in every recursive call. Therefore, recursion depth remains very small:

    Example:
    • For 1024 elements, recursion depth is only 10.
    Since the recursion depth is very low, stack overflow normally does not occur.

Conclusion:

Statements i and ii are correct. Therefore, the correct answer is: (a) i and ii

Share This Question

Challenge a friend or share with your study group.