An algorithm is a finite procedure that turns an input into an output. Choosing one means deciding which costs matter for the workload: running time, memory, implementation risk, or behavior on hostile input.

Complexity analysis (Big O) compares growth rates before any code is benchmarked. An O(n log n) sort can remain practical at input sizes where O(n²) work does not. Big O says nothing about constant factors or cache behavior, though, and it cannot predict the data a production system will receive. The final choice still needs measurements on representative inputs.

Consider membership checks against a large list of IDs. Repeated queries can justify sorting once and using binary search. A single query usually cannot: the preprocessing costs more than a plain linear scan saves.

Algorithms Inside Systems

System-design diagrams hide algorithms inside boxes labelled “cache,” “scheduler,” or “database.” Naming the mechanism makes its cost and failure boundary visible.

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

computer science algorithms

The visual is a topic inventory, not a universal priority ranking. A design decision depends on the mechanism’s invariant and where it fails under the actual workload.

References