Coding
AI Prompt for Choosing Data Structures
Choose the right data structure with this AI prompt: operation-based analysis, complexity comparison, and a clear recommendation for your use case.
The prompt
Role: You are a data structures expert who matches structures to problems methodically. Context: Problem: [PROBLEM_DESCRIPTION]. Language: [LANGUAGE]. Operations needed (with frequency): [OPERATIONS, e.g. insert: 10k/sec, lookup by key: 100k/sec, range query: rare] Scale: [SCALE]. Other constraints: [CONSTRAINTS: memory limits, persistence, ordering needs]. Task: 1) List 3 candidate data structures and their complexity for EACH of my operations (a table). 2) Analyze against my operation frequencies — the structure that wins is the one fast at what I do MOST. 3) Recommend ONE structure with clear reasoning. 4) Show the [LANGUAGE] implementation sketch or standard-library choice. 5) Note when I should REVISIT this choice (what change in workload flips the answer). Format: Operation-complexity table first, then analysis, then recommendation, then implementation, then the revisit triggers. Constraints: Decide based on MY workload, not generic advice. Consider [LANGUAGE]'s standard library first — custom structures need justification. Mention memory overhead, not just time.
Variables to fill in
Replace each [variable] in the prompt with your own details:
[PROBLEM_DESCRIPTION] [LANGUAGE] [OPERATIONS] [SCALE] [CONSTRAINTS]
Example input
PROBLEM=leaderboard for 1M players: insert score, get top 100, get player rank, LANGUAGE=Python, OPS_FREQUENCY=inserts 10k/sec, reads 1k/sec
How to use this prompt
List operations with their frequencies — the right structure depends on which operations dominate. Include the scale; it rules out naive choices.
Tips for the best results
- Weight by frequency — a structure slow at a rare op but fast at the common one usually wins.
- Ask for the revisit triggers; workloads evolve and choices should too.
- Have it estimate memory at your scale, not just Big-O.
Frequently asked questions
Is there a formula for choosing?
It maps your operations to structures by their complexity, then recommends based on YOUR operation mix — that is the correct method.
What if two structures tie on complexity?
Break ties with memory overhead, implementation risk, and your language's standard library. The prompt's revisit triggers tell you when to re-evaluate.