Chapter 4 - Recursion

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What is a base case? (1st law of recursion)

A base case is the condition that allows the algorithm to stop recursing. It is typically a problem that is small enough to solve directly.

How do you obey the 2nd Law of Recursion?

To obey the second law, we must arrange for a change of state that moves the algorithm toward the base case. A change of state means that some data that the algorithm is using is modified.

How do you obey the 3rd Law of Recursion?

To obey the third law, the algorithm must call itself, which is the very definition of recursion.

What are the Three Laws of Recursion?

1 - A recursive algorithm must have a base case. 2- A recursive algorithm must change its state and move toward the base case. 3- A recursive algorithm must call itself, recursively.

Knowing what our base is suggests that the overall algorithm will involve what three components?

1 - Reduce the original number to a series of single-digit numbers 2 - Convert the single digit-number to a string using a lookup. 3 - Concatenate the single-digit strings together to form the final result.

What is a stack frame?

A stack frame is allocated to handle the local variables of the function.

What is Recursion?

Recursion is a method of solving problems that involves breaking a problem down into smaller and smaller subproblems until you get to a small enough problem that it can be solved trivially. (WHEN AN ALGORITHM CALLS ITSELF!)

What are recursive calls?

We should think of recursive calls as solving smaller problems until we reach the point where the problem cannot get any smaller.


Ensembles d'études connexes

MIcroeconomics - Chapter 7 - Business and the Cost of Production

View Set

LUOA Module 3 Girl's health and PE

View Set

Chapter 20 - Remedies for Breach of Sales and Lease Contracts

View Set

healthcare finance ch 5 & 6 quiz

View Set

MedSurg Test 2: Cardiovascular & Peripheral Vascular

View Set

NU 112 Assessment Related To Electrolyte Balance

View Set