Computer Science
Forgetting the Base Case in Recursion
A student writes a recursive function that calls itself again but never handles the simplest input.
Quick check
Why students make it
Students focus on the repeating pattern and assume the function will naturally finish. They forget that recursion needs an explicit stopping condition.
The rule done right
Every recursive function needs at least one base case that returns a result without making another recursive call. The recursive step must move closer to that base case.
Related resources
- Recursion & Backtracking Cheat Sheet
- Recursion and Recursive Tree Structures Cheat Sheet
- Tree Traversal Reference Cheat Sheet
- Algorithms & Big-O Notation Cheat Sheet
- Dynamic Programming Patterns Cheat Sheet
- CS, Recursion and Base Cases Worksheet
- CS, Functions and Parameters Worksheet
- CS, Merge Sort and Quick Sort Algorithms Worksheet
- CS, Dynamic Programming, Memoization and Tabulation Worksheet
- Recursion & Call Stack Visualizer Tool
- Binary Tree Traversal Visualizer Tool
- Sorting Algorithm Visualizer Tool
- Debugging & Unit Testing Explorer Tool
- Recursion & Data Structures Lab Lab
- Data Structures & Tree Traversal Lab Lab
- Searching & Sorting Performance Lab Lab
- Debugging & Unit Testing Lab Lab