Chapter 18 Flashcards

1
Q

To have a method (directly or indirectly) call itself

Examples: Fibonacci, Factorials, Towers of Hanoi, etc

A

Recursive method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

When a recursive method is called to solve a problem, it actually is capable of solving only the _________ case or ______ case

A

Simplest, base

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Recursion: if the method is called with a base case, it returns a _____

A

Result

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Recursion: if it is a complex problem, it divides the problem into ____ pieces: _________

A

2

1 that the method knows how to do and a piece that it does not know

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Recursion: the method calls a ____ _____ to work on the smaller problem. Called a _____ call or _____ step

A

Fresh copy

Recursive call, recursion step

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

True or false

The recursive call/recursion step includes a return statement

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Recursion step executes while the original method call is still ____ (not finished executing)

A

Active

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

For the recursion to eventually terminate, each time the method calls itself with a simpler version of the original problem, the sequence of smaller and smaller problems must _____ on a base case

A

Converge

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Recursion: when the method recognizes the base case, it returns to the _____ ____ of the method. A sequence of returns ensues until the original method call returns the final result to the caller.

A

Previous copy

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

A recursive method may call another method, which may in turn make a call back to the recursive method

A

Indirect recursive call or indirect recursion

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Common example or recursion on a computer

Explain the base case

A

File-system directory

Base case occurs when a directory is reached that does not contain any subdirectories

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Either omitting the base case or writing the recursion step incorrectly so that it does not converge on the base case can cause a logic error known as _____ ________, where recursive calls are continuously made until memory is exhausted or the method-call stack overflows

A

Infinite recursion

How well did you know this?
1
Not at all
2
3
4
5
Perfectly