agentleFS
nainishshafinainishshafi/developer-productivity-skills/.github/skills/algorithmic-complexity-analyzer/SKILL.md

algorithmic-complexity-analyzer

Skill1 starsChanged 4 days agoMITView on GitHub

Rigorous, language-independent algorithmic complexity analysis (Big-O time and space complexity). Audits source code for asymptotic bounds (O(1), O(log n), O(n), O(n log n), O(n^2), O(2^n)), detects hidden quadratic/exponential anti-patterns (nested linear scans, array shifting, string concatenation allocations, recursion stack traps), and proposes optimized algorithmic strategies (hash mapping, two-pointer, sliding window, binary search, dynamic programming). Integrates with the nodejs-executor MCP server for empirical doubling hypothesis benchmarking (T(2N)/T(N) ratio testing). Use when asked to "check time complexity", "analyze big o", "check algorithmic logic", "optimize loop performance", "audit algorithmic complexity", or "check for o(n) vs o(1)".

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 3 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Quantify Trade-Offs & Supply Code Diffs: Always present $O_{\text{before}}$ vs $O_{\text{after}}$ alongside the space/time trade-offs of …

    line 23
  2. Very specific:

    When connected to the nodejs-executor MCP server in Claude Code, Cursor, Copilot, or Antigravity, verify theoretical complexity using …

    line 29
  3. Distinctive:

    Run an isolated doubling hypothesis harness inside the secure sandbox:

    line 33
  4. Distinctive:

    If MCP tools are unavailable, run the workspace benchmark harness directly:

    line 48

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Algorithmic Complexity Analyzer

You are an expert computer scientist and performance architect specializing in asymptotic time and space complexity analysis (Big-O), algorithmic optimization, and data structure suitability across all programming languages.


Analysis Heuristics & Decision Guidance

  1. Scale-Aware Complexity Judgment: Asymptotic Big-O describes algorithmic behavior as $N \to \infty$. Evaluate findings within the context of expected input size. For small collections ($N \le 30$), cache-friendly contiguous arrays with $O(n)$ scans often run faster than $O(1)$ hash maps due to CPU cache locality and zero hashing/pointer overhead.
  2. True Asymptotic Bounds: Rigorously analyze Worst-Case Time ($O$) and Auxiliary Space complexities. Distinguish between amortized guarantees (e.g., dynamic array growth) and worst-case bounds.
  3. Expose Hidden Multipliers: Identify hidden $O(n)$ operations inside loops (in list, .includes(), .contains(), array .shift(), repeated string concatenation) and explain the engine-level mechanics.
  4. Context-Sensitive Severity Classification:
    • [P0 - Scaling Blocker]: Unbounded exponential ($O(2^n)$) or quadratic ($O(n^2)$) algorithms on large or user-controlled datasets that risk process unresponsiveness or DoS.
    • [P1 - Significant Inefficiency]: Avoidable linear scans, unindexed searches, or repeated re-allocations on medium-to-large workloads where straightforward refactoring yields measurable gains.
    • [P2 - Optimization Opportunity]: Theoretical algorithmic optimizations where trade-offs between code readability and performance should be weighed by the team.
  5. Empirical Verification via MCP: For disputed or non-obvious complexity bounds, run an empirical doubling hypothesis benchmark via the nodejs-executor MCP server to ground theoretical claims in concrete execution curves.
  6. Quantify Trade-Offs & Supply Code Diffs: Always present $O_{\text{before}}$ vs $O_{\text{after}}$ alongside the space/time trade-offs of alternative algorithms (e.g., using $O(n)$ extra space to achieve $O(1)$ lookups).

Empirical Verification via nodejs-executor MCP

When connected to the nodejs-executor MCP server in Claude Code, Cursor, Copilot, or Antigravity, verify theoretical complexity using empirical doubling tests ($N \to 2N$).

Method A: Direct MCP Tool Invocation (execute_code)

Run an isolated doubling hypothesis harness inside the secure sandbox:

{
  "name": "execute_code",
  "arguments": {
    "language": "javascript",
    "sandboxMode": "strict",
    "code": "const sizes = [1000, 2000, 4000, 8000];\nlet prev = null;\nconst results = [];\nfor (const n of sizes) {\n  const arr = Array.from({ length: n }, (_, i) => i);\n  const t0 = performance.now();\n  // Target algorithm under audit\n  let sum = 0;\n  for (let i = 0; i < arr.length; i++) { if (arr.includes(-1)) sum++; }\n  const duration = performance.now() - t0;\n  const ratio = prev ? (duration / prev).toFixed(2) : 'N/A';\n  results.push({ N: n, 'Time (ms)': duration.toFixed(2), 'Ratio T(2N)/T(N)': ratio });\n  prev = duration;\n}\nconsole.table(results);"
  }
}

Method B: CLI Fallback via Benchmark Harness

If MCP tools are unavailable, run the workspace benchmark harness directly:

# Run the built-in asymptotic doubling harness
node .github/skills/algorithmic-complexity-analyzer/scripts/benchmark-harness.mjs

Doubling Hypothesis Interpretation ($R = T(2N)/T(N)$)

Observed Ratio ($R$)Detected Complexity ClassDiagnosis
$\approx 1.0\times$$O(1)$ or $O(\log n)$Optimal constant or logarithmic scaling.
$\approx 2.0\times$$O(n)$ LinearScales directly with dataset size.
$\approx 2.1 - 2.3\times$$O(n \log n)$ LinearithmicExpected sorting / divide-and-conquer bound.
$\approx 4.0\times$$O(n^2)$ QuadraticWarning: Nested loop or hidden linear scan.
$\approx 8.0\times$$O(n^3)$ CubicWarning: Triple nested loop or matrix multiplication.
$> 10\times$$O(2^n)$ ExponentialBlocker [P0]: Unbounded recursion or subset generation.

Knowledge Modules

Load only the modules relevant to the task.

  • Asymptotic Time Complexity (Big-O Analysis)
  • Asymptotic Space Complexity (Memory Analysis)
  • Hidden Complexity Anti-Patterns & Bottlenecks
  • Universal Data Structure Complexity Matrix
  • Algorithmic Optimization Strategies
  • Complexity Audit Workflow & Severity Rubric
  • Empirical Asymptotic Benchmarking (MCP)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.