What is recursion?

18-minute lesson · module-recursion-01

You are previewing this course as a guest

Read anything and run any exercise you like. It all runs in your own browser, so nothing here is saved: no XP, no progress, and the AI tutor needs an account. Sign in and your work starts counting.

Sign in

What is recursion?

18-minute lesson · module-recursion-01

  • Define recursion as a function that calls itself on a smaller input.
  • Identify the base case that stops the recursion.
  • Identify the recursive case that moves toward the base case.
  • Trace a simple recursive function such as factorial or countdown by hand.

Source attribution

Status: adapted

How to Think Like a Computer Scientist: Interactive Edition source · Recursion / What Is Recursion / The Three Laws of Recursion

Adaptation notes. Reading rewritten in our voice; the three-laws framing is the chapter's but the wording and examples (factorial, countdown-to-list) are ours. Hidden tests check the base case and several recursive cases.

License notes. Original chapter is GNU FDL 1.3 (Brad Miller, David Ranum, and the upstream Elkner/Downey/Meyers text). No verbatim text reproduced.