Short answer: Reservoir sampling draws k items uniformly from a stream of unknown length. The first k items fill the reservoir. When item i arrives, with i counted from 1, it replaces a random reservoir slot with probability k/i. Algorithm R uses one random number per item and O(k)…
Category: Randomization
How RANSAC fits a model to inliers
Short answer: RANSAC fits a geometric model when many points are outliers. It draws the smallest sample that determines the model, fits, and counts how many points agree within a threshold. After enough trials it refits on the largest inlier set. The number of trials needed to see at…
How Fisher-Yates shuffles with one swap per index
Short answer: The Fisher-Yates shuffle, in the modern inside-out or the usual in-place form, produces each permutation of an array with equal probability. The in-place loop walks i from the end down to 1 and swaps i with a uniformly chosen index j in 0..i, inclusive. That is n−1…
