Recursion —
Making the invisible visible.
Recursion is one of the most powerful and most feared concepts in programming. Stop simulating it in your head — watch the call stack build up, see every frame, and watch it unwind. Frame by frame. Step by step.
What is Recursion?
Recursion is when a function calls itself to solve a smaller version of the same problem. The idea is elegant — but watching it happen in your head is exhausting. When does the base case trigger? How does each call get its own variables? In what order do results get passed back up? LearnBug makes every frame visible so you stop guessing and start understanding.
Why it trips people up
Most learners get recursion wrong because it's invisible. You read the code, it looks fine, but you can't see what's happening inside each call. LearnBug changes that — paste your own recursive code, run it, and watch every call push onto the stack and every return value bubble back up.
Everything recursion, visualized
Each lesson lets you run your own Python code and watch execution step by step.
Factorial Visualization
The classic entry point to recursion. Watch n! call itself down to the base case and bubble every result back up.
Fibonacci Visualization
Watch two recursive branches grow simultaneously. See why naive Fibonacci is slow and exactly how memoization fixes it.
Call Stack Explained
The foundation of all recursion understanding. Watch each function call push a frame and each return pop one off.
Base Case vs Recursive Case
What stops infinite recursion? Watch the base case trigger, understand why it's non-negotiable, and see what happens when you forget it.
Tower of Hanoi
The ultimate recursion problem. Watch disks move step by step and see how 2ⁿ−1 recursive calls solve the puzzle.
Recursion vs Iteration
Same result, completely different execution. Run both side by side and see which uses more memory and why.
Merge Sort via Recursion
See recursion power a real sorting algorithm. Watch arrays split in half and merge back in sorted order.
Backtracking Visualization
Try, fail, undo — and try again. Watch backtracking explore decision trees and retreat when a path is wrong.
RecursionError — Depth Exceeded
What exactly happens when your recursion has no base case? Watch the stack overflow frame by frame and understand Python's 1000-limit.
What you'll understand after these lessons
Run your own recursive code on LearnBug
Paste your code — bugs and all. Watch exactly where your logic breaks.