C FunctionsLesson 30Free preview
C Recursion
This lesson is part of C · All levels
Summary
Recursion is a technique where a function calls itself to break up a problem into smaller subproblems. Each recursion must have a base case as a stop condition, otherwise the program will be stuck in a stack overflow due to the continuous call. Recursion is particularly well suited to problems that are repetitive in nature, such as factorial, Fibonacci sequences, or tree structure searches. For ordinary problems, repetition is usually more memory-saving than recursion.
Key points
- Recursion requires a base case as a condition of termination
- Without a base case, the program experiences infinite recursion to stack overflow.
- Every recursive call adds a new frame to the call stack.
- Suitable for problems that are naturally recursive such as factorial and fibonacci
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.