Recursion Basics
Recursive functions.
What is Recursion?
Recursion is when a function calls itself to solve a smaller version of the same problem. It is a natural fit for functional programming, replacing many loops with self-referential definitions.
Two Essential Parts
Every correct recursive function needs:
- A base case that stops the recursion.
- A recursive case that moves toward the base case.
Without a reachable base case, recursion runs forever.
All lessons in this course
- Recursion Basics
- The tailrec Annotation
- Accumulator Pattern
- Trampolining