Permutations, traced one call at a time

There is no path list here: nums itself is rearranged. Call backtrack(start) picks the number for position start by swapping it in, fixes it, recurses for the next position, then swaps back so the array is ready for the next choice.

CALL
1 / 1

Code

The highlighted line runs next. The pill shows the live values in the running call.

Recursion tree

Hover a permutation in res to find its call

not called yet running now paused, waiting on a child call full permutation (saved) finished bold green numbers = fixed positions

Call stack

Top frame runs; the rest are paused

Variables

nums one array, rearranged in place by swaps

res

Keyboard: ← → step, Space play or pause. Use up to 4 distinct numbers. The tree has n! leaves, one per permutation; edge labels like 0↔2 name the swap.