Asked by Griselle Gomez on May 21, 2024

verifed

Verified

Which of the following statements describe the base case of a recursive algorithm?
(i) F(0) = 0;
(ii) F(x) = 2 * F(x - 1) ;
(iii) if (x == 0)
F(x) = 5 + x;

A) Only (i)
B) Only (ii)
C) Only (iii)
D) Both (i) and (iii)

Base Case

In recursion, the base case is a condition that stops the recursion by not making a call to itself, thus avoiding an infinite loop.

Recursive Algorithm

An algorithm that solves a problem by dividing it into smaller problems of the same type, calling itself with these smaller problems.

  • Understand the concept of base cases in recursive functions.
verifed

Verified Answer

NA
Naadhilatul AwaanisMay 24, 2024
Final Answer :
D
Explanation :
The base case of a recursive algorithm is the case where the recursion stops and the function returns a definite result. In (i), F(0) = 0 is a definite result, so it is a valid base case. In (ii), F(x) = 2 * F(x - 1) does not have a definite result for any value of x, so it is not a valid base case. In (iii), if (x==0) F(x) = 5 + x is a definite result, so it is a valid base case. Therefore, the best choice is D, which includes both (i) and (iii) as valid base cases.