Recursion

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

Head recursion

A function makes it recursive call and then performs some more calculations

Direct Recursion

A method invoking itself.

Indirect Recursion

A method that invokes another method, which invokes another, etc. until eventually the original method is invoked again.

Recursion

A programming technique in which a method can call itself in order to fulfill its purpose. In some situations a recursive definition can be an appropriate way to express a concept.

Tail recursion

All calculations happen first and then recursive call is the last thing that happens

What happens during recursive programming?

Each call sets up a new stack frame, with new parameters and new local variables. When the method completes, control returns to the method that invoked it.

Recursion vs. Iteration

Every tail recursive solution has a corresponding iterative solution

Recursive Definitions

Need to establish 2 things: base case: create a non-recursive definition as a "base" recursive case: create a definition in terms of itself, changing it somehow (usually towards the base case).

Recursion trees

Used to visualize what happens when a recurrence is iterated.

Infinite Recursion

When a recursive definition doesn't have a base case or the recursive case doesn't move towards a base case and there is no way to terminate the recursive path. This will cause a stack overflow.


Ensembles d'études connexes

Business strategy Exam 1 Self Study Questions

View Set

Common Core ELA 11 (3rd Unit Test Review)

View Set

Hematology II Week 2 obj: Immune Vs. Non-Immune Hemolytic Anemia

View Set

Health Assessment- PrepU Chapter 11 Assessing Culture

View Set

evolve Ch 17 Somatic symptom disorders pre/post/NCLEX

View Set