analyze-complexity
/analyze-complexity
Use when reviewing or choosing code on a hot path or over user data — estimate Big-O and amortized cost, and decide when O(n²) is a bug versus a style point.
- Author
- velimirmueller ↗
- Repository
- ai-development-skills ↗
- Licence
- MIT
- Last repository change
- 23.10.2026
Assessment and security
- Files in this package
- 1
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 0
No signals detected. Repository changed on 23.10.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
What it does and when to use it
Use when reviewing or choosing code on a hot path or over user data — estimate Big-O and amortized cost, and decide when O(n²) is a bug versus a style point.
Original author description
Use when reviewing or choosing code on a hot path or over user data — estimate Big-O and amortized cost, and decide when O(n²) is a bug versus a style point.
How it works
- Growth order
- 1. Audit (change nothing)
- 2. Decide whether it matters
- 3. Distinguish average from worst and amortized
- Verify
- When to deviate
SKILL.md preview
--- name: analyze-complexity description: Use when reviewing or choosing code on a hot path or over user data — estimate Big-O and amortized cost, and decide when O(n²) is a bug versus a style point. --- # Analyze Complexity Estimates the growth order of code so a review can tell a real performance bug from a style nit. It is the "measure before optimizing" companion to [engineering-principles.md](../../core/_shared/engineering-principles.md). ## Growth order `O(1) < O(log n) < O(n) < O(n log n) < O(n²) < O(2ⁿ)`. A comparison sort cannot beat `Ω(n log n)`. ## 1. Audit (change nothing) ```bash cat .claude/stack-profile.md 2>/dev/null | head -20 grep -rn "for\|while\|sort\|find\|filter\|map" --include="*.ts" --include="*.rs" --include="*.go" --include="*.py" . 2>/dev/null | head -30 ``` Find the loop that depends on the size of user data, and name its order: a nested loop over the same collection is `O(n²)`; a loop that halves its range is `O(log n)`; a loop that sorts then scans is `O(n log n)`. Watch for a call inside the loop that hides another loop (a `.find` inside a `for`). ## 2. Decide whether it matters - The input is bounded (a form with five fields, a fixed set of options) → the order is a style point. - The input is user data or grows unbounded (rows, messages, search results) → the order is a bug when it is `O(n²)` or worse, or when a linear scan repeats inside a loop (N+1: a query or scan per element, O(n) → O(n²)). - The code is on a hot path (per request, per render) → measure before changing; a trace is the evidence. ## 3. Distinguish average from worst and amortized - **Average vs worst**: quicksort averages `O(n log n)` but is `O(n²)` worst-case on already-sorted input without a good pivot; hash lookup is `O(1)` average but `O(n)` worst on a bad hash. - **Amortized**: a dynamic array's append is `O(1)` amortized even though one in every N doubles and costs `O(n)`; the rare cost is spread across the many cheap ones. ## Verify State the order of the changed code, name the input it grows with, and cite the number (a profile, a trace, or the data size) that decided bug-vs-style. A second pass confirms no loop hidden inside the loop. ## When to deviate - Fix a known algorithmic mistake (N+1, quadratic over user data) without a profile — it is a bug, not a guess. See [engineering-principles.md](../../core/_shared/engineering-principles.md). - Bounded input: optimising it is noise; keep the readable version.
Versions
The database has no other skills named analyze-complexity.
Database snapshot: 13.11.2026 · package version 3132f924c0bd (SHA-256 digest of the entire package)
Downloads in the last 30 days: 2 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 100time-complexity
Estimate Big-O time complexity of code via static analysis (tree-sitter MCP). Use when: complexity, big-o, performance, hotspot, time complexity, analyze complexity. - 100code-complexity-analysis
Analyzes source code to assess performance using algorithmic complexity (time and space) plus a machine-aware cost model (memory hierarchy, branches, ILP, SIMD, parallelism). Identifies bottlenecks and recommends algorithmic, data-structure, and constant-factor optimizations.… - 100algorithms
Use when selecting algorithms, analyzing complexity, or reasoning about data structure choices. Covers Big-O notation, space vs time tradeoffs, amortized analysis, and algorithmic problem-solving strategy based on Knuth's "The Art of Computer Programming." USE FOR: algorithm… - 100cost-estimate
Estimate the cost of a task before starting it. Analyzes task complexity, predicts token usage, and compares cost across all Claude models. Use when user says 'estimate cost', 'how much will this cost', 'cost estimate', or '/cost-estimate'. - 100algorithmic-complexity-review
Algorithmic complexity (Big-O) review — finding nested loops, N+1 queries, exponential recursion, quadratic string builds, and other accidental complexity blowups. Covers Python, JavaScript/TypeScript, Java, Go, and similar languages. Use whenever writing, reviewing, or… - 100scan
Use when the user says 'scan project', 'estimate', 'how much to charge', or needs codebase complexity analysis.