Skip to content
All apps

Call Tree

About this app

Your own Python as a growing call tree: real Python 3.13 runs in the browser (Pyodide, served by heyprof itself), and every function call becomes a node with its arguments, local variables and return value. The tree grows depth-first, the running node is filled, the waiting ones form the call stack beside it, and return values only appear on the way back up. Eight examples from factorial via Hanoi to merge sort, steps per call or per line, predictions, and exceptions that travel up through the frames.

With explain mode: an AI tutor walks you through the app, points out what matters in the scene and answers your questions.

Every call is a node

When a function calls another function or itself, a new call arises with a frame and local variables of its own. Drawing every call as a node below its caller gives the call tree. Python builds it depth-first: a call finishes before the next one beside it begins. That is why return values arise on the way back up. The call stack is only ever the path from the root to the node that is running right now.

What the app shows

On the left is the Python code with the current line; in the middle the call tree grows node by node. The running call is filled, waiting calls are outlined, finished calls show their return value below them. On the right is the call stack with the local variables of every frame, and what just changed is highlighted. Eight examples show typical recursions: factorial, sum of a list, binary digits, Fibonacci, all words of L and R, the Tower of Hanoi, quicksort and merge sort.

Try your own code

Under Edit you can write your own code. It runs as real Python 3.13 directly in the browser (Pyodide), without a server, and never leaves your device. The step size switches between call and return and every single line. On request, the app asks for the value before a call that started calls of its own returns. Exceptions show how an error is passed up frame by frame.

Frequently asked questions

What is a call tree?
A call tree shows every function call of a program run as a node, connected to the call that started it. For fib(5) with if n < 2: return n there are 15 nodes, because every call from n = 2 upwards starts two more. Equal arguments give separate nodes: fib(2) appears three times.
What is the difference between the call tree and the call stack?
The call tree contains all calls of the whole run. At any moment, the call stack holds only the calls that are not finished yet: the path from the root to the running call. For fib(5) the tree has 15 nodes, but the stack has at most five function frames above the main program.
In which order do recursive calls run in Python?
One after another, depth-first. A call starts its first sub-call and waits until it is completely done before it starts the second. Nodes therefore appear from top to bottom and from left to right, return values from the bottom up.
Does my code run on a server?
No. The app loads Python as WebAssembly (Pyodide, about 12 MB) from heyprof itself and runs the code in the browser. The limits are 400 calls, 150 calls on top of each other, 6000 steps and 8 seconds; input() is not available.

Subject: Computer science

More from Computer science

A VisuApp by heyprof: interactive, free in your browser, no sign-up. What is a VisuApp? · All apps