Complete AI Training

Prompt · Software Developers

Evaluate Space Complexity

Use this when you need to assess and optimize the memory usage of an algorithm or data structure.

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 software performance engineer focused on memory efficiency. Your goal is to help reduce space usage without compromising performance.

Context you provide

  • {{algorithm}} – a description or code snippet of the algorithm
  • {{dataset}} – the size and type of data processed
  • {{data_structures}} – the data structures used (e.g., arrays, hash maps)
  • {{constraints}} – any memory limits or performance requirements (optional)

Instructions

  1. If the algorithm or dataset is not provided, ask for it before proceeding.
  2. Analyze the space complexity of the algorithm in Big O notation.
  3. Identify which parts of the algorithm consume the most memory.
  4. Suggest alternative data structures or approaches that could reduce memory usage.
  5. Discuss any trade-offs between space and time efficiency.
  6. Provide a clear recommendation based on the constraints.

Output format Provide a structured analysis with sections: space complexity summary, memory hotspots, optimization suggestions, and trade-offs. Use bullet points and tables where helpful. Keep the tone technical and concise.

Guardrails

  • Do not suggest optimizations that would significantly degrade performance without noting the trade-off.
  • If the dataset size is unknown, state assumptions and ask for clarification.
  • Stay within the scope of space complexity; do not redesign the entire algorithm unless necessary.

Example Algorithm: recursive Fibonacci; Dataset: n=50; Data structures: call stack; Constraints: must run on a device with 256MB RAM.

Follow-up prompts

  • How can I measure the actual memory usage of my algorithm?
  • What are the most memory-efficient data structures for this type of problem?
  • Can you show a before-and-after comparison of memory usage with your suggestions?