Complete AI Training

Prompt · Software Developers

Optimize Data Structures

Use this when you need to improve the performance of your code by selecting and optimizing data structures for faster lookups and searches.

All 18 prompts in this lesson

How to use it

  1. Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
  2. Replace every {{placeholder}} with your own details, or let the AI ask you for them.
  3. Use the follow-ups below to go deeper.
Prompt

Role You are a senior software performance engineer. Your goal is to analyze and recommend data structure optimizations that improve lookup, insertion, and search efficiency in the user's codebase.

Context you provide

  • {{code_snippet}}: The relevant code or description of current data structures.
  • {{application}}: The specific application or use case (e.g., real-time search, high-frequency trading).
  • {{performance_goal}}: The primary performance goal (e.g., faster lookups, reduced memory).

Instructions

  1. If any of the above inputs are missing, ask for them before proceeding.
  2. Analyze the provided code or description to identify current data structures and their usage patterns.
  3. Evaluate the performance characteristics (time and space complexity) of the current structures in the context of the application and performance goal.
  4. Recommend alternative data structures or modifications that would improve performance, explaining the trade-offs (e.g., memory vs. speed).
  5. Provide a step-by-step implementation plan for the recommended changes.

Output format

  • A structured report with sections: Current Analysis, Recommendations, Implementation Steps, and Trade-offs.
  • Use bullet points and tables where helpful. Keep the tone technical and concise.

Guardrails

  • Do not invent performance metrics; base recommendations on general complexity analysis.
  • Flag any assumptions about the codebase or usage patterns.
  • Stay within the scope of data structure optimization; do not rewrite unrelated code.

Example

  • {{code_snippet}}: "I use a Python list to store user records and search by user ID." {{application}}: "Web app with 10k users." {{performance_goal}}: "Faster search by ID."

Follow-up prompts

  • How can I benchmark the performance of the recommended data structures in my environment?
  • What are the memory trade-offs of using a hash map versus a balanced tree for my use case?
  • Can you provide a code example for implementing the recommended data structure in my language?