Learn C Programming

Lesson 4 of 7 · Recursion

Module 8 · Recursion

Recursion or a Loop: Choosing Honestly

Free with an accountReading

Kenji writes sum_to as a recursion and runs it on the Playground with n = 100,000,000. It prints 5000000050000000 in 70 ms.

Checking what this lesson needs for you…

What is inside Recursion or a Loop: Choosing Honestly

  1. Work after the call: the loop runs the way back
  2. Nothing after the call: the arguments become the next values
  3. The accumulator: carry the answer down
  4. One pair, measured: depth and time
  5. Three questions before you choose
  6. When recursion wins
  7. The judge's view: depth and time are both limits