본문으로 건너뛰기
cccskills
무료GitHub에 공개

complexity-analyzer

Automated Big-O complexity analysis of code and algorithms. Performs static analysis of loop structures, recursive call trees, space complexity estimation, and amortized analysis with detailed derivation documents.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(2)

  • SKILL.md7.4 KB
  • README.md7.1 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

complexity-analyzer

A specialized skill for automated analysis of algorithm time and space complexity, providing Big-O notation analysis, detailed derivations, and optimization recommendations.

Purpose

Analyze code and algorithms to determine:

  • Time complexity (Big-O, Big-Omega, Big-Theta)
  • Space complexity (auxiliary and total)
  • Amortized complexity for data structure operations
  • Complexity derivation with step-by-step reasoning
  • Optimization opportunities and bottleneck identification

Capabilities

Core Analysis Features

  1. Static Analysis

    • Loop structure analysis (nested loops, dependent bounds)
    • Recursive call tree analysis
    • Function call graph traversal
    • Branch condition impact analysis
  2. Complexity Types

    • Time Complexity: Worst, average, and best case analysis
    • Space Complexity: Stack space, heap allocations, auxiliary space
    • Amortized Analysis: Aggregate, accounting, and potential methods
    • Recurrence Relations: Master theorem, substitution method
  3. Output Formats

    • Big-O notation with detailed derivation
    • Complexity comparison tables
    • Visual complexity graphs
    • Optimization recommendations

Supported Languages

  • Python (primary)
  • C++ (full support)
  • Java (full support)
  • JavaScript/TypeScript (full support)
  • Go, Rust, C (partial support)

Integration Options

MCP Servers

AST MCP Server - Advanced code structure analysis:

# Provides AST parsing and complexity analysis
npm install -g @angrysky56/ast-mcp-server

Code Analysis MCP - Natural language code exploration:

# Deep code understanding with data flow analysis
npm install -g code-analysis-mcp

Web-Based Tools

Usage

Analyze Code Complexity

# Analyze a Python function
complexity-analyzer analyze --file solution.py --function two_sum

# Analyze C++ code with detailed derivation
complexity-analyzer analyze --file solution.cpp --verbose

# Compare multiple implementations
complexity-analyzer compare --files impl1.py impl2.py impl3.py

Example Analysis

Input Code:

def find_pairs(arr, target):
    n = len(arr)
    result = []
    for i in range(n):           # O(n)
        for j in range(i+1, n):  # O(n-i) iterations
            if arr[i] + arr[j] == target:
                result.append((i, j))
    return result

Analysis Output:

Time Complexity: O(n^2)
- Outer loop: n iterations
- Inner loop: (n-1) + (n-2) + ... + 1 = n(n-1)/2 iterations
- Total: O(n^2)

Space Complexity: O(k) where k = number of pairs found
- result array grows with matches
- Worst case: O(n^2) if all pairs match

Optimization Suggestion:
- Use hash table for O(n) time complexity
- Trade space for time: O(n) space

Output Schema

{
  "analysis": {
    "function": "string",
    "language": "string",
    "timeComplexity": {
      "notation": "O(n^2)",
      "bestCase": "O(1)",
      "averageCase": "O(n^2)",
      "worstCase": "O(n^2)",
      "derivation": [
        "Step 1: Outer loop runs n times",
        "Step 2: Inner loop runs (n-1), (n-2), ..., 1 times",
        "Step 3: Total = sum from 1 to n-1 = n(n-1)/2",
        "Step 4: Simplify to O(n^2)"
      ]
    },
    "spaceComplexity": {
      "notation": "O(n)",
      "auxiliary": "O(n)",
      "total": "O(n)",
      "breakdown": {
        "input": "O(n) - input array",
        "result": "O(k) - output pairs",
        "variables": "O(1) - loop counters"
      }
    },
    "recommendations": [
      {
        "type": "optimization",
        "description": "Use hash table approach",
        "newComplexity": "O(n) time, O(n) space",
        "tradeoff": "Space for time"
      }
    ]
  },
  "metadata": {
    "analyzedAt": "ISO8601 timestamp",
    "confidence": "high|medium|low"
  }
}

Analysis Patterns

Loop Analysis

PatternComplexityExample
Single loopO(n)for i in range(n)
Nested independentO(n*m)for i in n: for j in m
Nested dependentO(n^2)for i in n: for j in range(i)
LogarithmicO(log n)while n > 0: n //= 2
Nested logO(n log n)for i in n: j=1; while j<n: j*=2

Recursion Analysis

PatternRecurrenceComplexity
LinearT(n) = T(n-1) + O(1)O(n)
BinaryT(n) = T(n/2) + O(1)O(log n)
Divide & ConquerT(n) = 2T(n/2) + O(n)O(n log n)
ExponentialT(n) = 2T(n-1) + O(1)O(2^n)

Master Theorem

For recurrence T(n) = aT(n/b) + f(n):

CaseConditionComplexity
1f(n) = O(n^c) where c < log_b(a)O(n^(log_b(a)))
2f(n) = O(n^c) where c = log_b(a)O(n^c log n)
3f(n) = O(n^c) where c > log_b(a)O(f(n))

Integration with Processes

This skill enhances:

  • complexity-optimization - Identify and fix complexity bottlenecks
  • leetcode-problem-solving - Verify solution complexity
  • algorithm-implementation - Validate implementation efficiency
  • code-review - Complexity-focused code review

Common Complexity Classes

ComplexityNameExample
O(1)ConstantArray access, hash lookup
O(log n)LogarithmicBinary search
O(n)LinearArray traversal
O(n log n)LinearithmicMerge sort, heap sort
O(n^2)QuadraticNested loops, bubble sort
O(n^3)CubicMatrix multiplication (naive)
O(2^n)ExponentialSubsets, recursive fibonacci
O(n!)FactorialPermutations

Error Handling

ErrorCauseResolution
PARSE_ERRORInvalid syntaxCheck code syntax
UNSUPPORTED_CONSTRUCTComplex control flowSimplify or annotate
RECURSIVE_DEPTHDeep recursionProvide base case hints
AMBIGUOUS_BOUNDSDynamic loop boundsAnnotate with constraints

Best Practices

  1. Annotate Constraints: Provide variable ranges for accurate analysis
  2. Isolate Functions: Analyze one function at a time
  3. Consider Input Distribution: Specify if average case differs from worst
  4. Review Derivations: Verify step-by-step reasoning
  5. Test with Benchmarks: Validate theoretical analysis empirically

References

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Provide implementations of advanced data structures

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

a5c-ai/babysitter1.9천2026년 9월 17일 업데이트

Fresh adversarial code review with binary PASS/FAIL verdicts, evidence citations, and anchoring bias prevention via fresh reviewer spawning.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

a5c-ai/babysitter1.9천2026년 9월 17일 업데이트

WASM-based instant code transforms for simple tasks, achieving 352x speedup over LLM inference with zero cost.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

a5c-ai/babysitter1.9천2026년 9월 17일 업데이트

Coordinate Crew (persistent) and Polecat (transient) agents using Gas Town's hook-based work distribution and GUPP principle.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

a5c-ai/babysitter1.9천2026년 9월 17일 업데이트

Generate visual representations of algorithm execution

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

a5c-ai/babysitter1.9천2026년 9월 17일 업데이트

Hierarchical coordination and drift detection with frequent checkpoints, shared memory coherence validation, role specialization enforcement, and short task cycles.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

a5c-ai/babysitter1.9천2026년 9월 17일 업데이트

a5c-ai의 스킬 모두 보기

이 스킬의 문제 신고