- Tutorials
- DSA Tutorial
- Recursion
Recursion
2 lessonsAbout 12 minutesIntermediate
This part of the DSA Tutorial runs from Recursion Explained through to Turning Recursion Into Iteration. There are 2 lessons here, and working through them takes about 12 minutes at a steady pace.
It follows on from Linked Lists, so finish that first if you have not already — the examples below assume you are comfortable with it.
Each lesson below says what it covers before you open it. Read them in order the first time; afterwards this page works as a index you can jump back into when you need to check one thing.
- 1Recursion ExplainedRecursion is a function calling itself with a smaller input. Learn the base case, the call stack, why stack overflow happens in JavaScript, and when a loop is the better answer.
- 2Turning Recursion Into IterationAny recursive function can be rewritten as a loop with an explicit stack. Learn when you must — deep inputs, stack overflow — and how to do the conversion in JavaScript.
