P
💻DeveloppementAdvancedAll AIs

Analyze and Optimize Algorithmic Complexity

Analyze the Big O complexity of your algorithms and optimize them with appropriate data structures and more efficient algorithms.

Paste in your AI

Adapt this prompt

Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.

Help me work out how my code will perform on larger inputs. Explain the reasoning as you go, as an algorithms and data structures instructor would.

Code to analyze:

[paste the code]

Language: [e.g., Python, JavaScript, Java or Go]
Current input size: [e.g., 10,000 items]
Target input size: [e.g., 1,000,000 items]
Time limit: [e.g., an API response in under 100 ms]
Memory limit: [e.g., 512 MB of RAM]

  1. Walk through each function line by line and derive its time and space complexity in Big O notation. Point out nested loops and operations that are costly because of the data structure involved.
  2. Plot or tabulate how runtime grows at 10,000, 100,000, 1 million and 10 million items. Compare the current and target complexities. If you estimate actual times, state the assumptions.
  3. Look for places where a set could replace an O(n) scan through a list for a membership check, a map could replace repeated scans for the same keys or a heap could save sorting the entire input.
  4. Consider alternative algorithms where they fit, such as binary search, two pointers, a sliding window or dynamic programming.
  5. Implement the changes and give the resulting time and space complexity.
  6. Write a benchmark I can run to compare both versions on the same inputs.
  7. Explain the trade-offs. Where would I spend more memory to save time?

Personalize this prompt with Léa · AI assistant

Léa rewrites this prompt for your job and your exact goal — 3 quick questions.

Why this prompt works

This prompt is particularly effective because it requests a line-by-line complexity analysis, forcing the AI to reason explicitly about each operation rather than giving an intuitive answer. This granularity allows pinpointing exactly the line or data structure causing the bottleneck. Scalability visualization (performance at 10k, 100k, 1M elements) is a powerful communication tool for convincing teams to invest in optimization: the difference between O(n squared) and O(n log n) seems abstract, but seeing '100 seconds vs 0.3 seconds for 1M elements' makes the urgency concrete and tangible. The section on time/space trade-offs is often omitted in algorithmic optimization discussions, yet it's a critical dimension: an O(1) time solution requiring O(n) space may be unusable in a memory-constrained environment. Engineering is always about trade-offs.

Use Cases

Optimizing algorithms for large data volumesTechnical interview preparationIdentifying performance bottlenecks

Expected Output

Detailed Big O analysis, scalability visualization, optimized data structures, refactored code, and comparison benchmark.

Improve this prompt

Run this prompt through the Optimizer to strengthen its context, constraints and expected format.

Improve this prompt with the Optimizer

Comments

Be the first to comment on this prompt.

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Go further

Similar Prompts

💻DeveloppementIntermediateClaude

Task brief for Claude Code: frame a feature end to end

Brief template to delegate a complete feature to Claude Code: goal, starting point, constraints, definition of done, working rules and recap format.

1680
💻DeveloppementIntermediateClaude

Write a project's CLAUDE.md: the brief Claude Code reads at every session

Turns your project description into a dense CLAUDE.md: commands, structure, conventions, pitfalls, off-limits areas and situations where the agent must ask before acting.

639
💻DeveloppementAdvancedAll AIs

Design a Secure Webhook API

Design a webhook API with event subscriptions, signed deliveries, retry limits, and a delivery log your support team can inspect.

411
💻DeveloppementIntermediateAll AIs

Generate Storybook Stories for UI Components

Generate Storybook stories for a UI component, with visual variants, interactive controls, interaction tests, and MDX documentation.

473