Algorithm dossier
- Category: Sort
- Worst-case complexity: O(n)
- Approach: Iterative
- Data structure: Array
- First formalised: 1950s
Why this snippet is Counting Sort
Why counting sort. Builds an index-into-bucket structure c where c[v] is the count of times v appears in the input, then drains the buckets in key order. No comparisons — the sort lives in the indexing. Trade-off. Linear-time *in n + k* where k is the value range. Beats n log n lower bound for comparison sorts by not comparing. Useless if values aren't bounded small integers.
How to read a redacted algorithm
Algodle strips identifier names so the snippet has to be read for its shape: the control flow, the data structures it manipulates, the order in which it visits its input. Loops with two pointers crawling toward each other are usually search or partition. A recursion that splits its input in half and recurses on both halves is divide-and-conquer. A priority queue plus graph traversal is almost certainly Dijkstra, Prim, or A*. Six hint columns — category, complexity, approach, data structure, era — let you triangulate even when the snippet itself is opaque.