All templates/DeepSeek

Code Complexity Analyzer

DeepSeek prompt for analyzing code complexity with line-by-line breakdown and optimization suggestions.

deepseekcomplexityalgorithmsoptimization
Edit View
Prompt
Analyze the time and space complexity of this code:

{{code}}

Provide:

1. **What the code does**: Plain English explanation of the algorithm

2. **Time complexity analysis**:
   - Identify each loop, recursive call, and built-in operation
   - For each: what's the iteration count in terms of input size?
   - Combine to get overall Big-O
   - Show the derivation (not just the answer)
   - Best case / Average case / Worst case

3. **Space complexity analysis**:
   - Stack space (recursion depth)
   - Heap allocations (arrays, objects, hash maps)
   - In-place vs extra space
   - Overall Big-O space

4. **Complexity breakdown by line**:
   | Line(s) | Operation | Time | Space |
   Mark the bottleneck line(s) with ⚠️

5. **Optimization opportunities**:
   - Can we reduce time complexity? How?
   - Can we trade space for time (or vice versa)?
   - Are there unnecessary operations?
   - Would a different data structure help?

6. **Comparison**: If optimized, show:
   | Version | Time | Space | Tradeoff |
   - Original
   - Optimized approach 1
   - Optimized approach 2

Include the optimized code if the improvement is significant.

Save this prompt to your library

Organize, version, and access your best prompts across ChatGPT, Claude, and Cursor.