Algorithms are step-by-step procedures for solving problems with predictable behavior as input grows. In practice, algorithm choice is a tradeoff between runtime, memory usage, implementation complexity, and failure modes under real workloads.

Complexity analysis (Big O) is the primary tool for comparing algorithms without benchmarking. It captures growth rate: O(n log n) sorting scales to millions of items where O(n²) does not. But Big O ignores constant factors, cache behavior, and real-world input distributions — so production decisions combine theoretical analysis with profiling on representative data.

Concrete example: for repeated membership checks in a large list of ids, sorting once and using binary search gives fast lookups with low memory overhead. For one-off checks on unsorted data, a linear scan is usually simpler and can be faster overall because there is no preprocessing cost.

Algorithms as system-design mechanisms

System-design diagrams often hide the algorithm inside a box labelled “cache,” “scheduler,” or “database.” Naming the mechanism exposes the cost you are accepting:

MechanismSystem useCost or failure boundary
HashingCache keys, partition selection, deduplicationCollisions require equality checks; changing a naive modulo shard count remaps most keys
Consistent hashingDistributing keys across changing node setsReduces remapping; virtual nodes or another weighted ownership scheme can reduce skew, which still requires load observation
Trees and prefix searchDatabase indexes, routing tables, autocompleteShape and storage model determine update cost and range behavior
Graph traversalDependency analysis, routing, recommendationsCycles require visited-state; dense graphs can dominate memory
Heap-backed priority queuesScheduling, timers, top-k selectionEfficient best-item access does not provide sorted iteration
Bloom filtersSkipping absent database or object-store readsFalse positives perform unnecessary work; false negatives are forbidden by construction
Token bucketsRate limiting with bounded burstsA shared bucket needs atomic coordination; per-node buckets only approximate a global limit
ConsensusReplicated metadata and leader electionSafety requires quorum communication; a partition that cannot form a quorum loses progress while the quorum side can continue

The visual is a topic inventory. Its priority stars are editorial, not a workload-independent ranking; use the mechanism, invariant, and failure boundary above to decide what a design actually needs.

Questions

References

5 items under this folder.