跳至内容

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.

  1. Base case: the condition that stops recursion.
  2. 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:

  1. Stack space is limited and easily overflows (MLE).
  2. Inefficient.