Awesome Reviewers

Reviewer · Algorithms

Justify algorithmic complexity

When implementing non-trivial algorithms (custom data structures, special-cased iteration, approximations, or reimplementations of well-known algorithms like merges, searches, or tree structures), prefer the simplest approach that meets the requirements, and only keep added complexity when it is backed by evidence.

Instruction

When implementing non-trivial algorithms (custom data structures, special-cased iteration, approximations, or reimplementations of well-known algorithms like merges, searches, or tree structures), prefer the simplest approach that meets the requirements, and only keep added complexity when it is backed by evidence.

  • Before special-casing logic (e.g. a distinct first-iteration path, or splitting storage into two code paths depending on cardinality), check whether a single, uniform mechanism (e.g. always using the heap, always reading the first value up front) would be simpler with negligible cost. If a reviewer asks “could we simplify this?”, answer with reasoning or a benchmark, not intuition alone.
  • When choosing between a simple algorithm (e.g. straight binary search) and a more complex one (e.g. galloping/exponential search), measure both on realistic input distributions and record the result in the PR/comments so the trade-off is auditable, e.g.: “galloping is 3-8x faster for small seek distances; binary search only catches up after ~100k elements forward, so we keep galloping.”
  • When an algorithm depends on invariants of its input (sorted order, normalized/non-overlapping ranges, uniform-length bitmaps, equal-weight rows), document that assumption explicitly in the function’s comment and verify it holds for every caller, rather than re-deriving or silently assuming it. If the assumption can break (e.g. rows of varying byte size, bitmaps of different lengths), either handle the general case or state the simplifying assumption and its limitation in code/flag docs.
  • When porting or reimplementing a known algorithm (e.g. a loser-tree merge), preserve its documented tie-breaking and edge-case semantics unless a behavior change is intentional and called out; an unexplained < vs <= swap is a correctness risk, not a style choice.
  • Prefer generalizing duplicated or ad hoc counter/rotation logic into one well-tested primitive (e.g. a single Reserve function) over maintaining several bespoke variants, since this reduces both complexity and the surface for divergent bugs.
  • For approximation or heuristic algorithms (e.g. uniform sampling, pruning optimizations), explicitly identify and test the edge cases where the simplifying assumption breaks down (skewed distributions, multi-clause interactions), and decide consciously whether to handle them, add a caveat in documentation, or accept the known limitation.

Example of the kind of question to ask during review: “Does this custom/complex implementation outperform a straightforward one enough to justify the extra code, and have we validated the assumptions it depends on?”