Recursion Bug Debugger

Fix recursion issues including stack overflows and incorrect results

6/11/2026
Prompt
Help me debug issues with my recursive function.

**Programming Language:** {{LANGUAGE}}
**Recursive function:**
```{{LANGUAGE}}
{{CODE}}
```

**Problem:** {{PROBLEM}}
**Input that causes the issue:** {{INPUT}}
**Expected output:** {{EXPECTED}}
**Actual output/error:** {{ACTUAL}}

Please provide:
1. **Base Case Analysis**: Verify base case correctness
2. **Recursive Case Check**: Ensure progress toward base case
3. **Stack Trace**: Show recursive call stack for problematic input
4. **Termination Proof**: Verify the recursion will terminate
5. **Fixed Function**: Provide corrected recursive code
6. **Tail Recursion**: Convert to tail recursion if possible
7. **Iterative Alternative**: Provide iterative solution if appropriate
8. **Stack Optimization**: Techniques to prevent stack overflow

Or press ⌘C to copy

Variables (6)

Replace these placeholders with your own content before using the prompt.

[{LANGUAGE][{CODE][{PROBLEM][{INPUT][{EXPECTED][{ACTUAL]

Ready to use?

Copy and paste into your favorite AI tool

Test this prompt live

Try it in our AI Playground with Claude

Open Playground

Explore more Coding prompts

Browse Coding

Command Palette

Search for a command to run...