Chapter 4 - Recursion

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

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 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.

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!)

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 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

Chapter 10: Principles of Fluid and Electrolytes

View Set

Regression Models Assignment and Quiz 90%

View Set

The Skeletal System #1 + Labeling Of Human Skeleton

View Set

Module 5 Reviewing the Basics Quiz

View Set

Economics II: Microeconomics- Graded Exam 1

View Set

Final Exam Chapter 31: Assessment and Management of Patients With Hypertension

View Set

Intro to Business chapter 1- test review

View Set

Chapter 9: Human Resource Management Smartbook/Learnsmart, MGT 300 CHAPTER 9 (SMARTBOOK), MGT 301 exam 3, MGMT 3000 9.1-9.3, MGT 300: Chapter 9

View Set