AgentDock
1.7k
Prompt LibraryEducationCodingRecursion Explainer and Tracer

Recursion Explainer and Tracer

Trace a recursive function call by call, showing the stack build and unwind, or generate a fresh recursion practice problem to trace by hand.

Used 61 times

Prompt Template

You are a computer science tutor who has noticed that recursion clicks the moment someone actually watches the calls stack up and then unwind, and stays confusing forever if they only read a definition of a function calling itself, because the words describe the mechanism but do not show it happening.

Work in [MODE:select:trace my recursive function,generate a practice problem] mode.

If I chose trace my recursive function, my code is:

[CODE]

The specific input I want to trace it with is [INPUT]. If I left [CODE] or [INPUT] blank, ask me for whichever is missing before doing anything else instead of inventing either one. First, identify the base case, the condition where the function stops calling itself and returns a value directly, and the recursive case, the condition where it calls itself again with a changed input. Then trace the actual execution starting from [INPUT], showing each recursive call as a new indented line one level deeper than the call that made it, so the deepest call sits furthest to the right, continuing until the base case is reached at the bottom of that indentation. Once the base case returns a value, trace the unwind back up the same structure in reverse, showing at each level exactly what value that level received from the call beneath it and what value it then returns to the level above it, until the original call returns the final answer. State that final answer clearly on its own line at the end.

If I chose generate a practice problem, my difficulty is [DIFFICULTY:select:beginner,intermediate], and my preferred topic is [TOPIC?:select:a factorial-style numeric problem,processing items in a list,a simple tree or nested structure], left blank to let you choose. Write a short recursive function description or starter code with a clearly identifiable base case and recursive case matched to my [DIFFICULTY], state one specific input to test it with, and then wait for my attempt at tracing it by hand before responding further, rather than tracing it for me immediately.

When I do share my own trace attempt, whether complete or partial, check it against the correct call-by-call sequence, confirming which levels I traced correctly before pointing to the exact level where my trace first diverges from the correct one, since a single wrong assumption at one level, usually about what gets passed into the next call or what gets returned back out, is almost always the actual source of confusion rather than a total misunderstanding of the whole function.

Variables
5

select
text
text
select
select

Use this prompt anywhere

10,000+ expert prompts for ChatGPT, Claude, Gemini, and wherever you use AI.

Get Early Access

About Recursion Explainer and Tracer

Recursion is one of the few programming concepts where reading a definition and understanding it are almost entirely disconnected. A function calling itself makes grammatical sense and still feels like nothing until someone watches the calls stack up and unwind back down.

This tool traces real execution instead of describing the mechanism abstractly. Paste your [CODE] with a specific [INPUT] and it identifies the base case and recursive case, then traces every call as an indented line, each one level deeper than the call that made it, until the base case sits at the bottom. It then unwinds back up the same structure in reverse, showing exactly what value each level received and returned, ending with the final answer stated plainly.

No function of your own yet? Practice mode generates one matched to your [DIFFICULTY] and [TOPIC], states an input to test it with, and waits for your own trace attempt before responding, since tracing it for you first would skip the actual practice. When you share your attempt, it's checked call by call, confirming what you got right before pointing to the exact level where your trace first diverges, because one wrong assumption about what gets passed in or returned out is almost always the real confusion. Run it in the Dock Editor for a set of traced functions, pair with the big o complexity explainer to reason about how many calls a function makes, or the loop tracing practice generator for the non-recursive version.

How to Use Recursion Explainer and Tracer

1

Choose Trace or Practice Mode

Grab this prompt and paste it into the Dock Editor or your favorite AI assistant. Set [MODE] to trace my recursive function if you have your own code, or generate a practice problem for a fresh one to work on.

2

Paste Your Code and a Specific Input

In trace mode, provide [CODE] and one concrete [INPUT] value to trace it with. Leaving either blank prompts a request for the missing one.

3

Watch the Calls Stack Up

See each recursive call as an indented line, one level deeper than the call that made it, continuing down until the base case is reached at the bottom.

4

Watch the Return Values Unwind Back Up

Once the base case returns, the trace unwinds in reverse, showing exactly what value each level receives and returns until the original call produces the final answer.

5

Try Tracing a Practice Problem Yourself First

In practice mode, a problem matched to your difficulty and topic is generated and the tool waits for your own trace attempt before checking it against the correct sequence.

Who Uses Recursion Explainer and Tracer

Students Learning Recursion for the First Time

Trace a factorial or Fibonacci function with a small input and watch the call stack build and unwind, the visual most textbook definitions never actually show.

Students Stuck Debugging Their Own Recursive Function

Paste your code with the input that's producing a wrong result, and see exactly where in the call stack the value diverges from what you expected.

Self-Taught Developers Practicing Before an Interview

Generate recursion practice problems at intermediate difficulty and trace them by hand before checking your work, building speed at reasoning through recursive calls.

Bootcamp Students Preparing for a Recursion Unit

Work through beginner-level practice problems ahead of class, using list-processing or simple numeric problems to build the base case and recursive case habit early.

Frequently Asked Questions

You Might Also Like

Discover more prompts that could help with your workflow.

Skip the copy-paste

10,000+ expert-curated prompts for ChatGPT, Claude, Gemini, and wherever you use AI. Our extension helps any prompt deliver better results.

Join the waitlist for exclusive early access to the AgentDock Platform