Solvequill Blog · coding · 4 min read · 2 views

Recursion: base case first, cleverness later

Understand recursive functions by naming the stopping point before expanding calls.

Published:

Recursion becomes much less mysterious when you ask one question first: when does it stop?

The main idea

Write the base case, then describe how each call makes the input smaller or simpler.

A short example

Factorial stops at or ; every other call moves one step closer to that base case.

Check while you solve

  • Find the base case.
  • Find the smaller input.
  • Trace one small example, such as `factorial(3)`.

Turn your own question into an explanation video

Type the question or upload a photo; Solvequill produces a narrated video that walks through the solution step by step.

Open Solvequill

Keep reading