We are taught that computers are precise machines: same input, same output, every time. So it feels almost like cheating to learn that some of the fastest and simplest algorithms ever written deliberately flip coins.
A randomized algorithm makes random choices as it runs. Two runs on the very same input can take different paths — and sometimes even give different answers. That sounds like a bug, but used carefully it is a superpower: randomness can dodge the worst case, shrink the code, or solve a problem far faster than any known deterministic recipe.
The art is in what you trade. Some randomized algorithms are always correct but their running time varies. Others are blazing fast but carry a tiny, controllable chance of being wrong. Understanding that trade-off is the whole game.
Comments
Loading comments...