Recursion · 1 of 3
Recursive functions
Write a recursive function from its base case and its smaller call, follow its frames on the call stack, count its calls and its depth, and store repeated answers in a memo.
- Algorithms, Chapter 1: Recursion Recursion as handing a simpler instance of the problem to someone else, the Tower of Hanoi with its move count, and recursion trees (this page's call trees) for adding up the work of all the calls. Parts of this page adapt this chapter's text, licensed CC BY 4.0 (creativecommons.org/licenses/by/4.0), with changed wording, examples and code. jeffe.cs.illinois.edu (opens in a new tab)
- Josephus Problem The recurrence of the circle game, a faster O(k \log n) version for small k, and the closed form for k = 2. cp-algorithms.com (opens in a new tab)
- sys.setrecursionlimit What Python's recursion limit protects against, and the warning about setting it too high. docs.python.org (opens in a new tab)