ursive function can have only one base case. t or f?

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 20SA
icon
Related questions
Question

A recursive function can have only one base case.

t or f?

Expert Solution
Step 1

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.

 

Step 2

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
  1. 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.
  2. 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!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Declaring and Defining the Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage