Algorithms — Visual Learning

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.

9Visual lessons
PythonLanguage
Freein beta

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.

YouTube — Recursion Explained Visually
📺 Drop your YouTube embed here — recursion call stack walkthrough
LearnBug — Recursion in action
🖼 Add a screenshot of factorial/fibonacci running on LearnBug
9 Lessons

Everything recursion, visualized

Each lesson lets you run your own Python code and watch execution step by step.

n!

Factorial Visualization

The classic entry point to recursion. Watch n! call itself down to the base case and bubble every result back up.

Base CaseCall StackReturn Values

Fibonacci Visualization

Watch two recursive branches grow simultaneously. See why naive Fibonacci is slow and exactly how memoization fixes it.

BranchingMemoizationTree Recursion

Call Stack Explained

The foundation of all recursion understanding. Watch each function call push a frame and each return pop one off.

Stack FramesLIFOFunction Scope

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.

Base CaseRecursionErrorTermination

Tower of Hanoi

The ultimate recursion problem. Watch disks move step by step and see how 2ⁿ−1 recursive calls solve the puzzle.

Classic ProblemDivide & Conquer2ⁿ Complexity

Recursion vs Iteration

Same result, completely different execution. Run both side by side and see which uses more memory and why.

PerformanceSpace ComplexityComparison

Merge Sort via Recursion

See recursion power a real sorting algorithm. Watch arrays split in half and merge back in sorted order.

Divide & ConquerO(n log n)Sorting

Backtracking Visualization

Try, fail, undo — and try again. Watch backtracking explore decision trees and retreat when a path is wrong.

Decision TreePruningPermutations

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.

Error DebugStack OverflowPython Limit
Key Concepts

What you'll understand after these lessons

When the base case triggers
See the exact moment recursion stops and why it's non-negotiable.
How each call gets its own scope
Watch separate variable states live inside every frame on the stack.
The order results bubble up
See return values passed back up the chain step by step.
Why missing a base case breaks everything
Watch a RecursionError build in real time — and know how to fix it.
Tree recursion vs linear recursion
See how Fibonacci branches vs how factorial chains down.
Memory cost of deep recursion
Understand space complexity by watching the stack grow.

Run your own recursive code on LearnBug

Paste your code — bugs and all. Watch exactly where your logic breaks.

Open Playground →