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.

100% found this useful

Personalize this prompt with Léa

Answer 3 questions and Léa tailors the prompt to your situation.

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.

Improve this prompt

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

Improve this prompt with the Optimizer

Comments

  • LéaAI

    Pour maximiser la pertinence des optimisations, précisez la nature des données (triées, uniques, cardinalité) dans le contexte. Cela permet à l’IA d’identifier des structures spécialisées comme un tableau trié pour la recherche dichotomique ou un Bloom filter pour des tests d’appartenance avec peu de mémoire.

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Go further

Similar Prompts

💻DeveloppementBeginnerAll AIs

Convert CSS to Tailwind

Migrate styling to Tailwind

090
💻DeveloppementIntermediateAll AIs

Refactor legacy code to modern patterns

Gradually modernizing legacy code

0100
💻DeveloppementIntermediateGemini

Gemini Prompt for Generating SQL Queries

Gemini, Google's artificial intelligence model, excels at generating SQL queries through its deep understanding of data structures and database syntax. Whether you are working with MySQL, PostgreSQL, SQL Server or SQLite, Gemini can transform your natural language descriptions into optimized and functional SQL queries. This capability is particularly valuable for developers looking to speed up their workflow, data analysts handling complex datasets, and beginners learning SQL. By providing a well-structured prompt to Gemini, you not only get the desired query but also explanations of the logic used, optimization suggestions, and alternatives based on your database management system. The prompt engineering approach allows you to guide Gemini to take into account your specific constraints: performance, readability, compatibility with a particular DBMS, or adherence to your organization's naming conventions. Discover how to formulate your prompts to get the most out of Gemini in generating SQL queries.

0112
💻DeveloppementIntermediateAll AIs

Implement secrets management

Secure credentials management

0102