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

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

Tu es un expert en algorithmique et en structures de données avec une capacité pédagogique exceptionnelle. Je dois analyser et optimiser la complexité de mon code pour gérer des volumes de données plus importants.

**Code à analyser :**
```
[COLLER_LE_CODE]
```

**Contexte :**
- Langage : [EX: Python, JavaScript, Java, Go]
- Volume de données actuel : [EX: 10 000 éléments]
- Volume cible : [EX: 1 000 000 éléments]
- Contraintes de temps d'exécution : [EX: < 100ms pour une réponse API]
- Contraintes mémoire : [EX: max 512MB RAM disponible]

Analyse la complexité et propose des optimisations :

1. **Analyse Big O actuelle** : calcule la complexité temporelle et spatiale de chaque fonction avec explication ligne par ligne. Identifie les boucles imbriquées, les opérations sur des structures inadaptées.

2. **Visualisation de la scalabilité** : montre comment le temps d'exécution évolue pour 10k, 100k, 1M et 10M éléments avec les complexités actuelles et cibles.

3. **Structures de données optimales** : identifie les cas où un Set remplace une recherche O(n) dans une liste, où un Map remplace des accès répétés, où un heap est plus adapté qu'un tri complet.

4. **Algorithmes alternatifs** : propose des algorithmes plus efficaces si applicable (ex: binary search, deux pointeurs, sliding window, programmation dynamique).

5. **Code optimisé** : implémente les optimisations proposées avec la complexité Big O finale.

6. **Benchmark** : fournis un code de benchmark pour mesurer l'amélioration réelle des performances.

7. **Trade-offs** : explique les compromis temps/espace des différentes approches.

Why this prompt works

<p>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.</p><p>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.</p><p>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.</p>

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.

Learn more

Check the full skill on Prompt Guide to master this technique from A to Z.

View on Prompt Guide

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Similar Prompts

💻DeveloppementIntermediateAll AIs

Optimize Your Web Application Frontend Performance

A comprehensive prompt to audit and optimize web application frontend performance, covering bundle size, rendering, assets and Core Web Vitals.

0104
💻DeveloppementAdvancedClaude

Debug a Production Error

Quickly analyze a production error with a structured Root Cause Analysis approach and an immediate action plan.

47211
💻DeveloppementIntermediateGemini

Create a CLI Tool with Node.js

Create a professional Node.js CLI tool with Commander.js, Inquirer, visual feedback, and npm publishing.

23225
💻DeveloppementIntermediateClaude

Complete Code Review for Pull Requests

Get an exhaustive code review covering quality, performance, security, and maintainability for any language.

34240