3.7.19 · D1Algorithm Paradigms

Foundations — Randomized algorithms — Las Vegas, Monte Carlo

3,073 words14 min readBack to topic

This page assumes nothing. If you have never seen , , , or , start here. Every symbol used on the parent note is unpacked below, in an order where each idea stands on the previous one.


0. What is a "random variable"? (the seed of everything)

Before symbols, a picture. Imagine rolling a die. The number that lands up is not fixed — it depends on chance. A quantity like this is called a random variable: a number whose value is decided by an act of chance.

Figure — Randomized algorithms — Las Vegas, Monte Carlo
Figure s01 — A fair die's outcome has six possible values, each a bar of height . There is no single "the value" of ; instead there is a whole spread, and the orange arrow highlights that this spread — not one number — is what a random variable really is.

  • Las Vegas: the running time is a random variable; the answer is fixed-correct.
  • Monte Carlo: the answer is the random variable; the time is fixed.

1. Events and probability — "how often does this happen?"

Before we can measure chance, we need to name the thing whose chance we measure.

Picture it as a slice of a full pie. The whole pie is "everything that could happen" and has area . Your event is a wedge; its area is the probability.

The multiply rule is exactly why the parent's confidence-boosting works: independent wrong runs each of chance give a joint chance .

Deeper foundations for these rules live in Probability and Expectation.


2. Independence — "one flip tells you nothing about the next"

Figure — Randomized algorithms — Las Vegas, Monte Carlo
Figure s02 — Two coin flips drawn as separate coins with a dotted "no influence" arrow between them. Because flip 2 cannot feel flip 1, their joint chance is the product of the single-flip chances — the picture behind .


3. The (summation) symbol — "add up a whole list"

We will need to add up many chances, so let us earn the symbol before using it.

Picture a row of boxes, one per term, and as a rake sweeping them all into one pile.


4. Expectation — "the long-run average value"

Now the single most important symbol on the parent page — and note it is built on , which we just introduced.

Picture the possible values as weights placed on a ruler, each weight sized by its probability. is the balance point where the ruler tips level.

Figure — Randomized algorithms — Las Vegas, Monte Carlo
Figure s03 — Each possible value of is a bar whose position is the value and whose height is its probability. The orange fulcrum sits at — the exact point where the loaded ruler balances. This is why we call the expectation the "centre of gravity" of the distribution.

Compare against worst-case thinking in Amortized vs Expected Analysis.


5. Indicator variable — "a yes/no turned into a 1/0"


6. The geometric distribution & — "how many tries until it works?"

Figure — Randomized algorithms — Las Vegas, Monte Carlo
Figure s04 — The bars show : the chance the first success arrives on try . They shrink geometrically because each earlier try had to fail first. The orange dashed line marks the balance point — the average number of tries.


7. The exponential and the bound


8. Logarithm , — "the undo button for exponentials"

Picture as a shrinking ruler: multiplying the input only adds a little to the output. That slow growth is why is small even for huge .


9. Binomial coefficient — "how many pairs?"


10. Markov's inequality — "big overshoots are rare"


Prerequisite map

Random variable

Probability Pr

Independence multiply rule

Union bound

Expectation E of X

Linearity of expectation

Geometric distribution 1 over p

Indicator variable

Summation sigma

Harmonic sum ln n

Exponential e to x

Bound 1 minus x below e

Logarithm ln

Error boosting k runs

Las Vegas analysis

Markov inequality

LV to MC conversion

Karger min cut

n choose 2

Monte Carlo boosting

Randomized algorithms


Equipment checklist

Read each question, answer in your head, then reveal.

What is an "event" and how do we write "A and B"?
An event is a yes/no statement about a random outcome; "A and B" is written , the overlap of both.
What does mean in plain words?
The event is true about of the time if you repeat the experiment forever.
When may you multiply two probabilities together?
Only when the two events are independent (one doesn't affect the other): .
State the union bound and when it's useful.
; it bounds the chance that at least one of many bad events happens, without needing independence.
What is intuitively, and which symbol is it built from?
The long-run average / balance point of ; built from the summation .
State linearity of expectation and why dependence doesn't matter.
; it just regroups the same summed numbers, so it never asks how the variables interact.
An indicator is on event , else . What is ?
.
You retry until success, each try succeeds with prob . Expected tries, and the one-line reason?
; a failure resets you to the start (memoryless), giving .
Why is true?
is the tangent line of the convex curve at , and a convex curve stays above its tangents.
What does undo, and where does the topic use it?
It undoes (exponents); used to solve for and to get .
What is and where does it appear?
The number of unordered pairs ; the reciprocal of Karger's single-run success probability.
State Markov's inequality in words.
A non-negative variable exceeds times its average with probability at most .

See it all assembled on the parent: 3.7.19 Randomized algorithms — Las Vegas, Monte Carlo (Hinglish). Applications live in QuickSort, Quickselect, Primality Testing, and Min-Cut and Max-Flow.