CS 107: Chapter 13 - Recursion

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

overhead

All actions related to calling a module, including allocation of memory for parameters and local variables, storing the address of the program location where the controls return after the module terminates. In contrast, loops do not have such overhead.

T/F: 2. Some problems can be solved through recursion only.

False

T/F: 3. It is not necessary to have a base case in all recursive algorithms.

False

T/F: 4. In the base case, a recursive method calls itself with a smaller version of the original problem.

False

direct recursion

Recursive modules or functions that directly call themselves.

base case

The first case in which the problem can be solved with recursion. There must be at least one such case for recursion to be invoked.

depth of recursion

The number of times that a module calls itself. Typically, this is equal to n+1, where n = the total number of iterations passed through the module parameter. For example, for module message(5), the depth of iteration is 5+1 = 6.

1. A recursive module ____________________

c. calls itself

5. When a module explicitly calls itself it is called ____________________ recursion

c. direct

6. When module A calls module B, which calls module A, it is called ____________________ recursion

d. indirect

4. The part of a problem that is solved with recursion is the ____________________ case

d. iterative

recursive case

A case within a recursive solution that involves reducing the overall problem to a simpler problem of the same kind that can be solved by a recursive call

recursion

A module that calls itself. Note: A recursive module, much like a loop, needs to have a stop condition, otherwise the result will be an infinite loop.

Explain when a problem can be solved by recursion

A problem can be solved with recursion if it can be broken down into successive smaller problems that are identical to the overall problem.

T/F: 1. An algorithm that uses a loop will usually run faster than an equivalent recursive algorithm

True

3. The part of a problem that can be solved without recursion is the ____________________ case

a. base

8. Actions taken by the computer when a module is called, such as allocating memory for parameters and local variables, are referred to as ____________________

a. overhead

10. A recursive algorithm must ____________________ in the base case

a. solve the problem without recursion

2. A module called once from a program's main module, and then calls itself four times. The depth of recursion is ____________________

b. four

7. Any problem that can be solved recursively can also be solved with a ____________________

b. loop

9. A recursive algorithm must ____________________ in the recursive case

b. reduce the problem to a smaller version of the original problem


Kaugnay na mga set ng pag-aaral

Contracts Multiple Choice Questions

View Set

AP Euro- Chapter 12, European Society in the Age of the Renaissance

View Set

HLTH 231 Chapter 3 Review Questions

View Set

AQ Increased Intracranial Pressure

View Set

Supply Chain Management- Chapter 1

View Set

MGMT 300- Chapter 7 & 8 Adaptive Test Questions

View Set

Multiple Choice Questions Financial Management CH4

View Set