Machine-translated by Google. Questions are authored in English.
Top

Discussion

Which of the following cannot be solved by recursion ?

  • A.Fibonacci series
  • B.Factorial of a number
  • C.Power function
  • D.All of the above can be solved by recursion

Answer: D

The answer is All of the above can be solved by recursion.

Each is defined in terms of a smaller case of itself:

  • Fibonacci: F(n) = F(n-1) + F(n-2), with F(0) = 0 and F(1) = 1.
  • Factorial: n! = n × (n-1)!, with 0! = 1.
  • Power: xn = x × xn-1, with x0 = 1.

Each has a base case that stops the recursion, so a recursive function solves all three, and none of the first three options is a problem recursion cannot handle.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.