DevTools Logo
All posts

Algorithms and Safety Nets: Big-O, Graphs, Hashes, Secrets

September 5, 2026 · DevTools

algorithms
graphs
hashing
security
regex

Choosing an algorithm and shipping it safely are two halves of the same job. These five tools cover both: the Big-O Complexity Comparator and Birthday Paradox Hasher quantify cost and collision risk, the Graph Shortest Path Lab traces routing algorithms step by step, and the .env Secret Leak Linter plus Batch Regex Replace Simulator keep refactors and config files from leaking or breaking things.

Why growth curves cross sooner than you expect

The comparator evaluates eight classes — O(1), O(log n), O(n), O(n log n), O(n²), O(n³), O(2ⁿ), O(n!) — at concrete input sizes with a default table of 10, 100, 1000, and 1,000,000. Values cap at Number.MAX_SAFE_INTEGER ("≥ 9.0 quadrillion"), exactly where factorial and exponential rows explode. Curve points and SVG paths support linear and log-scale views, showing why O(n log n) looks linear at small n and O(n²) falls off a cliff.

nO(n log n)O(n²)O(2ⁿ)
10~331001,024
100~66410,0001.27 × 10³⁰
1,000~9,9661,000,000capped

The lesson: constants matter below n ≈ 100, but the class dominates everything above it. Sort with O(n log n), reserve O(n²) for tiny inputs, and treat anything exponential as "needs memoization or a different approach".

Collisions, shortest paths, and negative weights

The birthday tool computes P(at least one shared b-bit hash) for n records. Bit sizes clamp to 16–512; small inputs use the exact log1p product (up to 100,000 records), large ones switch to the Poisson approximation λ = n² / 2^(b+1). It also reports the 50%-collision threshold near √(2 ln 2 · 2^b) — about 23 people for 365 "birthdays", or roughly 2⁶⁴ records for a 128-bit hash.

The graph lab runs Dijkstra, A* (with zero or Euclidean heuristics over node coordinates), and Bellman-Ford on directed or undirected graphs, emitting visit / relax / complete steps with per-node distances. Two rules matter: Dijkstra refuses graphs with negative weights, and Bellman-Ford relaxes for V−1 passes then flags a reachable negative cycle explicitly. Unreachable goals return Infinity with an empty path rather than a guess.

Lint secrets and preview refactors before touching files

The env linter parses KEY=VALUE lines (including export prefixes, quoted values, and # comments) and flags syntax errors, invalid names, and empty values. Then it inspects each value: AKIA… AWS keys, gh[pousr]_ GitHub tokens, sk- API tokens, -----BEGIN PRIVATE KEY----- blocks, and JWT shapes are errors; values with length ≥ 20 and Shannon entropy ≥ 4.2 bits raise a high-entropy warning; changeme-style placeholders are informational. It also generates a KEY=-only template for safe sharing.

// Rule ordering matters: later rules see earlier rules' output
Rule 1:  pattern "console\.log\(.*\);"  ->  ""       // strip debug logs
Rule 2:  pattern "TODO:"                 ->  "FIXME:" // retag uniformly

The regex simulator applies ordered rules to virtual files without mutating anything, counting matches via matchAll for global patterns (exactly one for non-global, matching String.replace semantics) and reporting per-file line diffs, total matches, and changed-file counts. An invalid pattern fails fast with Rule N: invalid regular expression. Preview first, apply once.

Try Them