Short answer: The Boyer-Moore majority vote finds a candidate that is the only value that could be a strict majority of an array, using one counter and one candidate. It scans once. On a match it increments. On a mismatch it decrements. At zero it takes the current value…
Category: Sequences
How Floyd’s cycle algorithm meets a tortoise and a hare
Short answer: Floyd’s cycle-finding algorithm detects a cycle in a sequence defined by x, f(x), f(f(x)), … with two pointers and no stored history. The tortoise advances one step and the hare two. If there is a cycle, they meet. The meeting point is then used to find the…
How Brent’s cycle search resets on powers of two
Short answer: Brent’s cycle algorithm finds a cycle in a sequence x, f(x), f(f(x)), … with constant memory. A hare walks alone. Whenever the distance since the last reset is a power of two, the tortoise jumps to the hare and the search length doubles. When the hare lands…
