1.
Definition
Randomized Algorithm is an algorithm that uses random numbers
to make decisions during execution.
The randomness affects:
o The path taken by the algorithm
o The running time
o Sometimes the output
Even for the same input, different runs may behave differently.
2. Why Randomized Algorithms are Used
To avoid worst-case inputs crafted by adversaries.
To achieve good average performance.
To simplify complex deterministic logic.
Useful when deterministic solutions are:
o Too slow
o Too complicated
o Hard to analyze
3. Types of Randomized Algorithms
3.1 Las Vegas Algorithms
Always produce the correct answer
Running time is random
Performance measured by expected time
Example:
o Randomized Quick Sort
3.2 Monte Carlo Algorithms
Running time is fixed
Answer may be incorrect with small probability
Error probability can be reduced by repeating the algorithm
Example:
o Randomized primality testing
4. Randomized vs Deterministic Algorithms
Determinis
Aspect Randomized
tic
Always
Output May vary
same
Running
Fixed Expected
time
Usually
Worst-case Can be bad
avoided
Complex Simpler
Simplicity
logic design
5. Key Concepts
5.1 Random Variable
A variable whose value depends on randomness.
Used to analyze:
o Running time
o Probability of correctness
5.2 Expected Value
Average outcome over many executions.
Used instead of worst-case analysis.
5.3 Probability of Error
Especially important for Monte Carlo algorithms.
Usually very small and controllable.
6. Common Examples
6.1 Randomized Quick Sort
Randomly selects a pivot
Expected time complexity:
o O(n log n)
Avoids worst-case O(n²) seen in deterministic quicksort.
6.2 Randomized Selection (Kth smallest element)
Finds median or order statistics.
Expected time:
o O(n)
6.3 Randomized Primality Test
Determines if a number is prime.
Fast and reliable with high probability.
7. Advantages
Simple implementation.
Efficient in practice.
Resistant to worst-case inputs.
Often faster than deterministic counterparts.
8. Disadvantages
Non-deterministic behavior.
Harder to debug.
Small probability of incorrect results (Monte Carlo).
Requires good random number generation.
9. Applications
Sorting and searching.
Cryptography.
Machine learning.
Distributed systems.
Computational geometry.