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
- Work after the call: the loop runs the way back
- Nothing after the call: the arguments become the next values
- The accumulator: carry the answer down
- One pair, measured: depth and time
- Three questions before you choose
- When recursion wins
- The judge's view: depth and time are both limits