Algorithm dossier
- Category: Hashing
- Worst-case complexity: O(n)
- Approach: Randomised
- Data structure: Array
- First formalised: 1930s
Why this snippet is Fisher-Yates Shuffle
Why Fisher-Yates. Walk the array right-to-left. At each step, swap the current element with a *uniformly random* element from the unshuffled prefix [0..i]. The result is a uniform permutation — every one of n! orderings has probability 1/n!. Common bug. Using Math.floor(Math.random() * a.length) (instead of * (i + 1)) biases the distribution toward the back of the array. Subtle and untested-for in most shipped code.
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.