P
💻DeveloppementIntermediateAll AIs

Analyze Your Code Algorithmic Complexity Like an Expert

This prompt provides a complete analysis of source code algorithmic complexity, with Big O notation, bottleneck identification and concrete optimization recommendations.

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 analyse de complexité computationnelle. Analyse en profondeur la complexité algorithmique du code suivant :

```[LANGAGE]
[CODE_A_ANALYSER]
```

Contexte d'utilisation : [CONTEXTE] (ex : traitement de données massives, application temps réel, script ponctuel...)

Pour chaque fonction ou bloc logique significatif, fournis :

1. **Complexité temporelle (Time Complexity)** :
   - Notation Big O dans le pire cas (worst case)
   - Notation Big Omega dans le meilleur cas (best case)
   - Notation Big Theta pour le cas moyen (average case)
   - Justification ligne par ligne des boucles, récursions et appels imbriqués

2. **Complexité spatiale (Space Complexity)** :
   - Mémoire auxiliaire utilisée (hors input)
   - Structures de données temporaires créées
   - Profondeur de la pile d'appels si récursion

3. **Identification des goulots d'étranglement** :
   - Quelles parties du code dominent la complexité globale ?
   - Y a-t-il des opérations cachées coûteuses (ex : copie de liste, concaténation de chaînes, tri implicite) ?

4. **Recommandations d'optimisation** :
   - Propose une version optimisée du code avec une meilleure complexité
   - Explique le compromis temps/espace (time-space tradeoff) de chaque alternative
   - Indique les structures de données plus adaptées si pertinent (hash map, heap, arbre équilibré...)

5. **Tableau récapitulatif** :
   Présente un tableau comparant la version actuelle et la version optimisée (complexité temporelle, spatiale, et comportement estimé pour n = 100, 10 000 et 1 000 000 éléments).

Adapte ton niveau d'explication à un développeur de niveau [NIVEAU] (débutant / intermédiaire / avancé).

Why this prompt works

<p>This prompt transforms the AI into a rigorous algorithmic analyst. By providing your code and its usage context, you get a methodical breakdown of its time and space complexity, with all three standard notations (Big O, Big Omega, Big Theta).</p><p>The <strong>[CONTEXT]</strong> variable is essential: an O(n squared) algorithm may be perfectly acceptable for a one-off script on 50 elements, but catastrophic for real-time processing on millions of records. The <strong>[LEVEL]</strong> variable adapts the explanations — a beginner will receive analogies and step-by-step diagrams, while an advanced developer will get references to complexity classes and formal proofs.</p><p><strong>Usage tip:</strong> for optimal results, include the complete code (not just a snippet) and specify your environment constraints (limited memory, maximum acceptable latency). The AI can then propose time/space tradeoffs truly suited to your situation.</p>

Use Cases

Prepare for a technical interview by verifying solution complexityOptimize a query or process that becomes slow at scaleCompare multiple algorithmic approaches before choosing the best oneReview legacy code to identify performance bottlenecks

Expected Output

A structured analysis including detailed time and space complexity of each code block, a diagnosis of the most expensive parts, an optimized version with tradeoff explanations, and a comparative table of estimated performance at different input sizes.

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 SQL Queries and Boost Performance

A complete prompt to analyze, diagnose, and optimize your SQL queries with indexing and rewriting recommendations adapted to your database engine.

0171
💻DeveloppementIntermediateAll AIs

Debug Your Python Code with ChatGPT

A structured prompt to get a complete analysis of your Python bugs: identification, root cause explanation, commented fix, and prevention tips.

0154
💻DeveloppementIntermediateAll AIs

Automatically Generate Unit Tests with AI

Automatically generate an exhaustive unit test suite covering nominal cases, edge cases, and error cases for any source code.

0179
💻DeveloppementAdvancedAll AIs

Create a Complete REST API from A to Z

A complete prompt to generate a professional REST API with authentication, validation, documentation, and integrated tests.

0186