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 :
-
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.
-
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.
-
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.
-
Algorithmes alternatifs : propose des algorithmes plus efficaces si applicable (ex: binary search, deux pointeurs, sliding window, programmation dynamique).
-
Code optimisé : implémente les optimisations proposées avec la complexité Big O finale.
-
Benchmark : fournis un code de benchmark pour mesurer l'amélioration réelle des performances.
-
Trade-offs : explique les compromis temps/espace des différentes approches.
Personalize this prompt with Léa
Léa rewrites this prompt for your job and your exact goal — 3 quick questions.
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
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 OptimizerComments
- 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
Kubernetes Backup Strategy
Kubernetes Disaster Recovery Plan
Implement cost optimization with Terraform
Reduce cloud infrastructure costs
Implement input validation
Validate and sanitize inputs
Prompt Claude for Generating a Database Schema
Designing a database schema is a fundamental step in any software project. A well-thought-out schema ensures data consistency, facilitates queries, and avoids long-term performance issues. Yet, this task requires expertise in relational modeling, normalization, and choosing data types suited to the target DBMS. Claude excels in this area: by providing a functional description of your project, it generates a complete schema with tables, columns, types, constraints, indexes, and relationships. It applies best practices for normalization, suggests consistent naming conventions, and anticipates common needs like audit columns or soft deletes. Whether you start from a specification, a list of business entities, or an existing schema to refactor, Claude produces a DDL ready to execute or a structured diagram that you can iteratively refine. This is a valuable accelerator for solo developers and teams alike who want to quickly validate a data architecture before coding.