ursive function can have only one base case. t or f?
A recursive function can have only one base case.
t or f?
Recursion is a very important problem-solving approach that is an alternative to iteration remember that iterative solutions include looping construct.
Mathematics background:
There is an accepted form of mathematical definition that uses concepts to define themselves. Such definitions are called inductive definitions. When carefully used, such definitions are very concise, very powerful, and very elegant.
Programming Approach of Recursion:
A problem solving / programming technique in which a method (function) can call itself in order to solve the problem. In the process, the problem is solved by reducing it to smaller versions of itself.
Idea behind recursion : Each successive recursive call should bring you one step closer to a situation in which the problem can easily be solved. Each recursive definition has two separate parts -
- base case
- recursive case
- The easily solved situation or trivial condition is called the base case. The base case is a simple case of the problem that we can answer directly; the base case does NOT use recursion. Each recursive algorithm must have at least one base case. Without at least one base case program may go to into the infinite recursion.
- The recursive case is the more complicated case of the problem that isn't easy to answer directly, but can be expressed elegantly with recursion. The general case is the place where the recursive calls are made --> written so that with repeated calls it reduces to the base case (or brings you closer to the base case).
Must eventually be reduced to a base case; if not --> infinite recursion. Must have at least one general case --> if not, no recursion!
Step by step
Solved in 3 steps