Coding
AI Prompt for Algorithm Design
Design algorithms from scratch with this AI prompt: constraint-driven approach selection, pseudocode, complexity analysis, and verified working code.
The prompt
Role: You are an algorithms expert who designs practical solutions under real constraints. Context: Problem: [PROBLEM_STATEMENT]. Example: [SMALL_EXAMPLE with expected output]. Constraints: [CONSTRAINTS: time/memory limits, data size, language]. My level: [YOUR_LEVEL]. Task: 1) Restate the problem in your own words to confirm understanding. 2) Propose 2-3 candidate approaches with their time/space complexity and fit for [CONSTRAINTS]. 3) Recommend ONE approach and justify it. 4) Write clear pseudocode, then the working [LANGUAGE] implementation. 5) Analyze complexity and verify against [SMALL_EXAMPLE] with a trace. Format: Restatement, then the approach comparison table, then recommendation, then pseudocode, then code, then the verification trace. Ask the AI to identify the algorithm's Achilles' heel: the input shape or scale where the chosen approach degrades worst. Knowing the failure mode in advance lets you monitor for it in production. Constraints: The solution must respect [CONSTRAINTS] — do not propose an O(n^2) solution for a 10GB input. Explain at a [YOUR_LEVEL] level. Code must run as written.
Variables to fill in
Replace each [variable] in the prompt with your own details:
[PROBLEM_STATEMENT] [SMALL_EXAMPLE] [CONSTRAINTS] [LANGUAGE] [YOUR_LEVEL]
Example input
PROBLEM=find the k most frequent words in a 10GB log file with 1GB RAM, LANGUAGE=Python, CONSTRAINTS=memory limit 1GB, single pass preferred, LEVEL=intermediate
How to use this prompt
State constraints as hard numbers — memory, time, data size. They determine the algorithm more than the problem statement does. Include a small example.
Tips for the best results
- Challenge the recommendation — ask when each rejected approach would win.
- Have it trace the algorithm on your example before you trust the code.
- Ask for the 'what breaks at 10x scale' analysis for production readiness.
Frequently asked questions
What if I don't know which approach fits?
It designs from your constraints and explains the trade-offs, so you get the right algorithm for YOUR limits, not the textbook one.
What if none of the proposed approaches fit my constraints?
Say so — the prompt will explore hybrids or approximation strategies. Real constraints sometimes rule out exact solutions, and the AI should tell you.