Advanced Topic 46 of 51 Algorithms
Randomized Algorithms
Algorithms using random choices to achieve expected efficiency.
How it works
Randomized algorithms use random numbers to make choices, achieving good expected performance or simplicity. Las Vegas algorithms such as randomized quicksort always give the correct answer but have a random running time, while Monte Carlo algorithms such as Miller-Rabin primality testing run in bounded time but may err with a small probability that can be reduced by repetition.
Step-by-step walkthrough
- A randomized algorithm flips coins during execution.
- Quicksort picks a random pivot.
- Most choices give balanced splits.
- A bad pivot is rare and not tied to any particular input.
- Expected running time is O(n log n) for every input.
Where it is used
Randomized quicksort and quickselect, hashing, primality testing in cryptography, Monte Carlo simulation, load balancing, skip lists and sampling large datasets use randomness.
Common pitfall
Poor random number generators bias results or enable attacks, and security-critical uses need cryptographic randomness. Expected-time guarantees do not rule out slow individual runs. Testing is harder because failures are nondeterministic; record seeds to reproduce bugs. Do not assume independence when it does not hold.
Where it fits in the course
Randomized Algorithms is topic 46 of 51 in Algorithms, rated Advanced. It follows Huffman Coding. The next topic is Approximation Algorithms.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Algorithms quiz.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Algorithms quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Randomized Algorithms?
Where do people use Randomized Algorithms?
What is the most common mistake with Randomized Algorithms?
What should I learn before this topic?
How can I practice it?
Is Randomized Algorithms hard to learn?
How long does it take to learn Randomized Algorithms?
Which topics are related to Randomized Algorithms?
What should I study after Randomized Algorithms?
Related topics
- Huffman Coding (Algorithms)
- Approximation Algorithms (Algorithms)
- Rabin-Karp Algorithm (Algorithms)
- Amortized Analysis (Algorithms)
- Line Drawing Algorithms (Graphics, Vision & Media)
- Load Balancing Algorithms (Distributed Systems & Cloud)
- Wait-Free Algorithms (Concurrency & Parallelism)