Recursion Visualizer: Call Stack and Recursion Tree

Recursion is hard to picture on paper. Paste a recursive function and press ▶ Explain: the call stack beside the variables shows every call in progress, and the recursion tree grows call by call, turning each box green with its return value when it finishes.

  • Live call stack: fact(4) on top of fact(5) on top of main()
  • Recursion tree: every call as a box, with the value it returns
  • The running call is highlighted; click any box to jump to that call
  • The line of code and the flowchart box light up at each step
  • Works for C, C++, Java, Python and JavaScript
  • Viva questions on base cases, stack depth and complexity

How it works

  1. Paste your recursive program and a small input
  2. Press ✦ Make flowchart
  3. Press ▶ Explain
  4. Watch the call stack and the 🌳 Recursion tree tab

Try it with

  • #include <stdio.h> int fact(int n) { if (n <= 1) return 1; return n * fact(n - 1); } int main() { printf("%d", fact(4)); return 0; }
  • def fib(n): if n < 2: return n return fib(n - 1) + fib(n - 2) print(fib(4))
  • static int sumDigits(int n) { if (n == 0) return 0; return n % 10 + sumDigits(n / 10); } public static void main(String[] args) { System.out.println(sumDigits(472)); }

Frequently asked questions

What is a recursion tree?

A diagram of every call a recursive function makes: each call is a box, its children are the calls it makes, and the value under each box is what it returns. For fib(4) it shows why the same values are computed more than once.

What does the call stack show?

The calls that are still running at that moment, newest on top, with their argument values. It grows as the function calls itself and shrinks as each call returns.

Is it free?

Yes. A dry run uses one free AI credit, and the three examples above open without signing up.

Can I export it?

Yes — PNG, SVG, PDF, PowerPoint with an editable slide, Mermaid code and draw.io. You can also share a live link or present it full screen.

Classic programs with flowchart, algorithm and code

Related tools

Try AI Flowchart free →