Chapter 3
Translated from Chinese by an LLM.
Recursion
Simply put, it is a function calling itself.
Two Conditions of Recursion
The base case and the recursive case - the two are exact opposites.
- Base case: the condition that stops recursion.
- Recursive case: the condition that continues recursion.
Stack
A stack is a First-In-Last-Out (FILO) data structure.
When a program runs, it has a call stack, call stack.
When a function is called, some memory is allocated and pushed onto the call stack; when the function ends, the memory is popped from the call stack.
Drawbacks:
- Stack space is limited and easily overflows (MLE).
- Inefficient.