All posts

algorithms

13 posts
ALGORITHMS

Bloom Filters: Probably Present, Definitely Useful

A Bloom filter answers 'have I seen this before?' using a fraction of the memory a real set would need — by allowing one specific kind of wrong answer. It's the data structure behind databases skipping disk reads they don't need.

ALGORITHMS

Hash Tables: The Real Cost of a Collision

Hash tables promise O(1) lookups, and then a benchmark shows them losing to a plain array. The gap between the textbook and reality is collisions, cache misses, and the resize you forgot about.

ALGORITHMS

Regex Engines: The NFA/Backtracking Split That Explains ReDoS

The same pattern runs in microseconds in Go and hangs for years in JavaScript, on the same input. The reason is a fork in engine design made in the 1970s — automata vs backtracking — and it's why one regex took Cloudflare's edge offline.

AI

Tokenizers: Why an LLM Can't Count the R's in Strawberry

Before a language model sees your text, a tokenizer chops it into subword pieces from a fixed vocabulary — and that boundary explains the model's weirdest failures: bad arithmetic, the strawberry problem, why code indentation matters, and why some languages cost 3x more.

NETWORKING

Longest Prefix Match: How Routers Decide in Nanoseconds

A core router matches each packet against ~1M CIDR prefixes and must pick the most specific — billions of times per second. The data structures behind that (tries, TCAM, poptrie lineage) and why 'most specific wins' shapes everything from BGP hijacks to your homelab VPN.

ALGORITHMS

Hash Functions: What Makes a Good One (and Why Yours Isn't)

Between 'sum the bytes' and SHA-256 lies the workhorse category: non-cryptographic hashes. What avalanche means, how hash quality turns into hash-table throughput, and why every language runtime switched to seeded hashing.

DISTRIBUTED-SYSTEMS

Rate Limiting: Token Buckets, Burst Math, and the 429 You Deserve

Fixed windows let 2x through at the boundary, token buckets are three lines of arithmetic, and the distributed version is a consistency problem wearing an ops costume. The algorithms, their failure modes, and what to return when you say no.

ALGORITHMS

Big-O in Practice: When the Constant Factor Eats the Asymptote

Binary search loses to linear scan on small arrays. Hash maps lose to sorted vectors. Big-O tells you how algorithms scale, not which one is faster — and on modern hardware the gap between those two questions is enormous.

DATABASES

How Query Planners Think: Costs, Cardinality, and Lies

SQL says what, the planner decides how — by estimating row counts through a chain of guesses and picking the cheapest of thousands of plans. When the estimate is wrong by 1000x, so is the plan. Reading EXPLAIN is learning to audit those guesses.

ALGORITHMS

Arrays vs Linked Lists: The Benchmark Textbooks Don't Run

The textbook says linked lists win at insertion, O(1) vs O(n). Run the benchmark and the array wins insertion-heavy workloads too — often by 10x. The memory hierarchy voted, and it didn't vote for pointers.

ALGORITHMS

What Your Language's sort() Actually Runs

Nobody ships textbook quicksort. Python runs Timsort, C++ runs introsort, and both are layered hybrids built around one insight: real-world data isn't random, and worst cases must be impossible.

DISTRIBUTED-SYSTEMS

Consistent Hashing: Surviving the Resize

hash(key) % N reshuffles nearly everything when N changes — a cache stampede with a math degree. Consistent hashing moves only 1/N of keys per node change, and virtual nodes fix the balance problem the elegant version hides.

FUNDAMENTALS

Recursion Is Just a Stack You Didn't Write

Every recursive call is a frame pushed onto the call stack — return address, saved registers, locals. See the frame layout once and stack overflows, tail calls, and the recursion-to-iteration transformation all become mechanical.