Chapter 12 Flashcards
Recursion is a
Problem-solving method
Recursion is often used when a problem’s solution relies on a
Simpler solution to the same problem
A recursive method is a method that
Calls itself
A recursive method
Might contain any number of statements
a useful recursive method must
Provide a way to stop recursion
The approach to writing nonrecursive methods that include loops to produce results is
Iterative
Programmer might choose an iterative approach to a problem rather than a recursive one because iterative programs often
Run more quickly
The excess computation time required for repeated method calls in recursive programs is called
Overhead
When you use recursion, you frequently ask a method to call itself repeatedly
Using a simpler version of the problem each time
When a method calls another method, the location to return to when the second method finishes is stored in the
Call stack
In a recursive method, there typically are
More recursive cases than base cases
The case in a recursive method that does not make a recursive call is the
Base case
The cases in a recursive method that make recursive calls are the
Recursive cases
The factorial of a nonnegative integer is the ________ of all the integers from 1 up to and including the integer.
Product
Computing factorials lends itself to recursion because
Computing the factorial of any number relies on computing the factorial of a simpler case
In a recursive method, the case in which no recursive call is needed is the
Base case
After using the statement p = n.indexOf(‘A’); if p contains 5, then
There is an ‘A’ in string n
Recursion can be successfully used to
Solve mathematical problems and to create visual patterns
Recursive approach can be used to
Display characters on consecutive lines where each is one space further to the right than the previous one
You can substitute a recursive solution to a problem for an iterative one
Only if the iterative solution contains at least one if statement