跳转至

Recursion

Recursion

来自 Problem Solving with Algorithm and Data Structures Using Python,Release 3.0, Chapter 4, Page 117 学习笔记。

Definition

Recursion is a method of solving problems that involves breaking a problem down into smaller and smaller subproblems until you get into a small enough problem that it can be solved trivially. Usually recursion involves a function calling itself.

A recursive function is a function that calls itself.

The Three Laws of Recursion

  • A recursive algorithm must have a base case.
  • A recursive algorithm must change its state and move toward the base case.
  • A recursive algorithm must call, recursively