#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
🌳 FREE · STEP BY STEP

Recursion Tree Visualizer: Watch Recursion Unfold

Pick a function, set its inputs and replay every call and return, with call counts and the effect of memoisation.

  • 🔁 Replay calls in order
  • 🧠 Memoisation on or off
  • 📊 Calls and depth

How to use the Recursion Tree Visualizer

  1. 1. Choose a functionFibonacci, factorial, fast power, C(n, k), merge sort ranges or Tower of Hanoi. The code is shown.
  2. 2. Set inputsSmall inputs keep the tree readable; up to 400 calls can be drawn.
  3. 3. ReplayStep, play or drag the slider to watch calls open (blue), return (green) or come from the cache (purple).

Worked example: fib(5)

Plain fib(5) returns 5 but makes 15 calls, because fib(3) is computed twice and fib(2) three times. The deepest call stack is 5 frames, and the replay has 30 steps, one for each call and one for each return. Turn on memoisation and the same answer takes 9 calls, 3 of them answered straight from the cache, so the tree collapses to almost a straight line. That difference grows fast: plain fib(n) makes roughly 1.6ⁿ calls, while memoised fib(n) makes about 2n.

Other trees to try

  • Tower of Hanoi with 3 disks makes 15 calls and 7 moves (2³ − 1), with every level doubling.
  • Merge sort on 8 elements splits into ranges like [0,3] and [4,7]: 15 calls, 4 levels deep, which is where the log n in n log n comes from.
  • Fast power calls itself once per halving, so power(2, 13) takes only 5 calls.

Why recursion trees matter

Counting the nodes of the tree gives the running time, and the height gives the stack space. Seeing repeated sub-trees is the moment you know dynamic programming will help. Interviewers often ask candidates to draw this tree on a whiteboard before optimising, then to say how memoisation or a bottom-up table would remove the repeated work.

Frequently asked questions

Can I enter my own function?

Not yet. The six functions cover the common teaching examples. Running arbitrary code would need eval, which this site avoids.

Why is there a limit of 400 calls?

Larger trees can't be drawn clearly on a screen. Use memoisation or smaller inputs.

What do the colours mean?

Orange is the current call, blue is running, green has returned and purple came from the cache.

Is the recursion tree visualizer free?

Yes. Everything in the recursion tree visualizer works without signing up. The first time you ask for a result, we ask once for your name and WhatsApp number; after that the recursion tree visualizer and every other Uncodemy tool open straight away.

More free tools

See all free tools