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.
Sign in to read
This lesson is free, with an account
An account costs nothing and opens every lesson in this track that is not marked Pro, on every device you read on.
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