skills/43-wentorai-research-plugins/skills/domains/cs/algorithms-complexity-guide/SKILL.md
Analyze algorithm complexity and computational efficiency for research
npx skillsauth add brycewang-stanford/Awesome-Agent-Skills-for-Empirical-Research algorithms-complexity-guideInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
A skill for analyzing algorithm complexity and computational efficiency in research contexts. Covers asymptotic notation, common complexity classes, NP-completeness, amortized analysis, and strategies for presenting algorithmic contributions in papers.
O(f(n)) -- Upper bound (worst case, "at most")
T(n) is O(f(n)) if T(n) <= c * f(n) for large n
Omega(f(n)) -- Lower bound (best case, "at least")
T(n) is Omega(f(n)) if T(n) >= c * f(n) for large n
Theta(f(n)) -- Tight bound (exact asymptotic growth)
Both O(f(n)) and Omega(f(n))
Common growth rates (slowest to fastest):
O(1) < O(log n) < O(sqrt(n)) < O(n) < O(n log n) < O(n^2) < O(n^3) < O(2^n) < O(n!)
def estimate_runtime(n: int, complexity: str) -> dict:
"""
Estimate practical runtime for common complexities.
Args:
n: Input size
complexity: Complexity class string
"""
import math
complexities = {
"O(1)": 1,
"O(log n)": math.log2(max(n, 1)),
"O(n)": n,
"O(n log n)": n * math.log2(max(n, 1)),
"O(n^2)": n ** 2,
"O(n^3)": n ** 3,
"O(2^n)": 2 ** min(n, 40), # Cap to avoid overflow
}
operations = complexities.get(complexity, n)
# Assuming ~10^9 operations per second
seconds = operations / 1e9
return {
"input_size": n,
"complexity": complexity,
"estimated_operations": operations,
"estimated_time": (
f"{seconds:.2e} seconds"
if seconds < 60
else f"{seconds / 60:.1f} minutes"
if seconds < 3600
else f"{seconds / 3600:.1f} hours"
),
"feasible": operations < 1e12 # Roughly 1000 seconds
}
P: Problems solvable in polynomial time
Examples: Sorting, shortest path, MST, linear programming
NP: Problems verifiable in polynomial time
(Given a solution, can check it quickly)
Examples: SAT, TSP, graph coloring, subset sum
NP-Complete: The "hardest" problems in NP
If any one is in P, then P = NP
Proven via reduction from a known NP-complete problem
NP-Hard: At least as hard as NP-complete
Not necessarily in NP (may not even be decision problems)
Examples: Optimization versions of NP-complete problems
PSPACE: Solvable with polynomial space (possibly exponential time)
Examples: QBF, certain game-theoretic problems
To prove problem X is NP-complete:
1. Show X is in NP:
- Given a certificate (proposed solution), verify it in poly time
2. Reduce a known NP-complete problem Y to X:
- Construct a polynomial-time transformation f
such that Y has solution iff f(Y) has solution in X
- Common starting problems: SAT, 3-SAT, Vertex Cover,
Hamiltonian Path, Subset Sum
For divide-and-conquer algorithms, solve recurrences:
Master Theorem: T(n) = a * T(n/b) + O(n^d)
Case 1: d < log_b(a) -> T(n) = O(n^(log_b(a)))
Case 2: d = log_b(a) -> T(n) = O(n^d * log n)
Case 3: d > log_b(a) -> T(n) = O(n^d)
Examples:
Merge Sort: T(n) = 2T(n/2) + O(n) -> O(n log n) [Case 2]
Binary Search: T(n) = T(n/2) + O(1) -> O(log n) [Case 2]
Strassen: T(n) = 7T(n/2) + O(n^2) -> O(n^2.81) [Case 1]
Amortized analysis provides the average cost per operation over
a worst-case sequence of operations.
Methods:
- Aggregate method: Total cost / number of operations
- Accounting method: Assign "credits" to cheap operations
- Potential method: Define a potential function
Example: Dynamic array (ArrayList)
Most insertions: O(1)
Occasional resize: O(n)
Amortized cost per insertion: O(1)
(The expensive resizes are rare enough that the average stays constant)
% Use the algorithm2e or algorithmicx package in LaTeX
\begin{algorithm}[H]
\caption{Description of Algorithm}
\label{alg:myalgorithm}
\KwIn{Input description}
\KwOut{Output description}
initialization\;
\While{condition}{
compute something\;
\If{condition}{
action\;
}
}
\Return result\;
\end{algorithm}
1. Problem definition (formal, with input/output specification)
2. Related work and existing approaches with their complexities
3. Algorithm description (pseudocode + English explanation)
4. Correctness proof (invariants, termination argument)
5. Complexity analysis (time and space, worst/average/amortized)
6. Experimental evaluation:
- Comparison with baselines on standard benchmarks
- Runtime scaling with input size (empirical vs. theoretical)
- Real-world datasets in addition to synthetic ones
7. Discussion of practical considerations (constants, cache behavior)
When you encounter NP-hard problems in your research, consider: polynomial-time approximation algorithms (with provable approximation ratios), heuristics (greedy, local search, simulated annealing), fixed-parameter tractable (FPT) algorithms if a relevant parameter is small, integer linear programming (ILP) solvers for moderate-size instances, or restricting to special cases where the problem becomes tractable (e.g., trees, planar graphs).
development
Conduct rigorous thematic analysis (TA) of qualitative data following Braun and Clarke's (2006) six-phase framework. Use whenever the user mentions 'thematic analysis', 'TA', 'Braun and Clarke', 'qualitative coding', 'identifying themes', or asks for help analysing interviews, focus groups, open-ended survey responses, or transcripts to identify patterns. Also trigger for questions about inductive vs theoretical coding, semantic vs latent themes, essentialist vs constructionist epistemology, building a thematic map, or writing up a qualitative findings section. Covers all six phases, the four upfront analytic decisions, the 15-point quality checklist, and the five common pitfalls. Produces a Word document write-up and an annotated thematic map. Does NOT cover IPA, grounded theory, discourse analysis, conversation analysis, or narrative analysis — use a different method for those.
development
Guide users through writing a systematic literature review (SLR) following the PRISMA 2020 framework. Use this skill whenever the user mentions 'systematic review', 'systematic literature review', 'SLR', 'PRISMA', 'PRISMA 2020', 'PRISMA flow diagram', 'PRISMA checklist', or asks for help writing, structuring, or auditing a literature review that follows reporting guidelines. Also trigger when the user asks about inclusion/exclusion criteria for a review, search strategies for databases like Scopus/WoS/PubMed, study selection processes, risk of bias assessment, or narrative synthesis for a review paper. This skill covers the full PRISMA 2020 checklist (27 items), produces a Word document manuscript in strict journal article format, generates an annotated PRISMA flow diagram, and enforces APA 7th Edition referencing throughout. It does NOT cover meta-analysis or statistical pooling. By Chuah Kee Man.
testing
Performs placebo-in-time sensitivity analysis with hierarchical null model and optional Bayesian assurance. Use when checking model robustness, verifying lack of pre-intervention effects, or estimating study power.
data-ai
Fit, summarize, plot, and interpret a chosen CausalPy experiment. Use after the causal method has been selected, including when configuring PyMC/sklearn models and scale-aware custom priors.