{{ summaryTitle }}
{{ summaryValue }}

{{ summaryLine }}

{{ badge.label }} {{ badge.value }}
{{ summaryAnnouncement }}

Process visual unavailable.

Recursion and backtracking trace inputs
Every preset uses a deterministic left-to-right depth-first order.
{{ valueHelp }}
{{ tracePositionLabel }}
Scrub the source, stack, process stage, and step inspector together.
Use the slider for fast scrubbing or the buttons for exact transitions.
The neutral default is off. Turn it on to spot recomputed Fibonacci calls in the inspector and ledger.
{{ highlight_repeats ? 'Enabled' : 'Disabled' }}
Step inspector
Event{{ currentStep.event }}
Source line{{ currentStep.source_line || 'Terminal' }}
Stack depth{{ currentStep.depth }}
Current transition
{{ currentStep.title }}

{{ currentStep.message }}

Repeated call
Active source line
  1. {{ line }} Current line
Call stack snapshot
  1. {{ index === currentStep.stack.length - 1 ? 'Top' : `Depth ${index + 1}` }} {{ frameLabel }}

The stack is empty after the terminal transition.

Terminal outcome {{ computation.values.final_result }}
{{ chartExportStatus }}

The chart renderer is unavailable. The exact depth values remain in the event ledger.

Step Event Depth Branch / call Explanation Copy
{{ row.step }} {{ row.event }} {{ row.depth }} {{ row.branch || row.stack[row.stack.length - 1] || 'Terminal' }} {{ row.message }}
{{ ledgerExportStatus }}

A recursive result can be correct while the route to it remains hard to follow. Each call pauses its caller, creates a new frame with its own local values, and either reaches a base case or makes another call. Only after the deeper call returns can the suspended work continue.

Backtracking adds choices to that cycle. A partial solution is extended in a fixed order, rejected when it violates a rule, and undone before the next choice is tried. Permutation generation explores every remaining symbol. N-Queens rejects squares that share a column or diagonal with a queen already placed.

Call frame
One active invocation with its local values and return point.
Base case
A condition that returns directly and stops that branch from recursing further.
Recursion tree
The branching structure of calls, including repeated calls that may compute the same subproblem again.
Undo
Restoring the previous partial state before another candidate is considered.

Call-stack depth and total work are different. Factorial follows one narrow chain, while direct Fibonacci repeats many smaller calls. Permutations and N-Queens can spend most of their work branching, rejecting, accepting, and undoing even when the active stack is not especially deep.

A bounded teaching trace is not a general debugger. It explains deterministic control flow for four fixed problems and small inputs. It does not execute arbitrary code, model language-specific stack memory, use memoization, or predict how a production compiler will optimize recursion.

How to Use This Tool:

Choose a recursion problem and input size before stepping through its calls, returns, and backtracking events.

  1. Choose Factorial, Fibonacci, Permutations, or N-Queens. Each preset follows a deterministic left-to-right depth-first order.
  2. Enter a value within the preset's teaching range: 0 to 7 for factorial or Fibonacci, 2 to 4 unique letters for permutations, or board size 3 or 4 for N-Queens.
  3. Move Trace position or use Previous step, Next step, and Jump to end. The source line, call stack, current event, and depth profile stay synchronized.
  4. Turn on Highlight repeated calls when studying direct Fibonacci. It marks recomputed call labels without changing the trace or final result.
  5. Read Step inspector for the current event and Event ledger for the full sequence. Use the terminal result together with call, choice, rejection, undo, solution, and repeat counts.

Interpreting Results:

The current depth is the number of active frames at the selected step. Maximum depth is the deepest point reached anywhere in the trace. Neither value equals the total number of calls or the algorithm's running time.

  • Call count measures frame entries; repeat count marks later visits to the same Fibonacci call label.
  • Choice count records explored branches; rejected count is specific to unsafe N-Queens squares.
  • Undo count records restored permutation or board choices; solution count records complete accepted results.

Repeated Fibonacci calls reveal recomputation, not a trace error. For backtracking, a large rejection or undo count is also expected: failed partial choices are the evidence that the remaining accepted solutions were reached by the stated rules.

Technical Details:

Every preset emits one ordered event stream. A call pushes a frame; base, branch, choose, reject, combine, accept, and undo events leave the stack in place; a return is recorded before its frame is removed. The trace ends with an empty stack and a completion event.

Rule Core:

Recursive and backtracking rules for each preset
Preset Stopping or acceptance rule Recursive step Order and undo
Factorial When n is 0 or 1, return 1. Compute factorial(n - 1), then multiply its return value by n. One descending branch; no choice or undo event.
Fibonacci When n is 0 or 1, return n. Complete Fibonacci(n - 1), then Fibonacci(n - 2), and add both returns. Left branch always completes before the right branch.
Permutations Accept the prefix when no symbols remain. Append each remaining symbol and recurse on the others. Candidates run left to right; each choice is undone before the next.
N-Queens Accept when one safe queen has been placed in every row. Try columns from left to right in the next row. Reject a shared column or diagonal; remove every accepted placement after its deeper search returns.

Mechanism Core:

Stack and branch behavior can be audited through the event sequence rather than inferred from the final answer.

Meaning of recursion and backtracking trace events
Event State change Evidence to watch
Call Push one labeled frame. Depth rises and the frame appears at the top of the stack.
Base or accept Finish a terminal branch. A direct value or complete solution is recorded.
Choose or branch Start the next deterministic child. The selected candidate or child call is named.
Reject Skip an unsafe N-Queens square. The board remains unchanged.
Undo Restore the previous partial permutation or board. The next sibling starts from the same parent state.
Return Record the result, then pop one frame. Control resumes in the caller.

The complete trace is capped at 500 events. Factorial and Fibonacci inputs stop at 7, permutations require distinct uppercase letters after normalization, and N-Queens is limited to sizes 3 and 4. These bounds keep exhaustive traces readable and prevent unbounded recursion.

Worked Examples:

Factorial of two

The trace calls factorial(2), descends to factorial(1), reaches the base value 1, returns to the suspended multiplication, combines 2 × 1, and finishes with 2. The verified trace contains eight events, two calls, and a maximum depth of two.

References:

  • Recursion, NIST Dictionary of Algorithms and Data Structures, entry modified 2013.
  • Backtracking, NIST Dictionary of Algorithms and Data Structures, entry modified 2021.