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

Adapt this prompt

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 :

[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é).

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 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). The [CONTEXT] 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 [LEVEL] 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. Usage tip: 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.

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.

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

💻DeveloppementIntermediateAll AIs

Set up distributed tracing

Implement distributed tracing

570
💻DeveloppementIntermediateAll AIs

Set up semantic versioning automation

Automate semantic versioning

515
💻DeveloppementIntermediateAll AIs

Generate a code coverage report plan

Plan test coverage improvements

625
💻DeveloppementIntermediateAll AIs

Create a complete REST API

Quickly bootstrap a new API endpoint

446