##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
Sample space, events, P(A or B), P(A and B), complement rule, and independent vs dependent events.
(The Goal)
(All possible outcomes)
(Individual results)
(Subsets of the sample space)
(Favorable over total)
(Probability of rolling > 4)
(Always between 0 and 1)
(Probability of "not A")
(At least one head in 3 flips)
(A or B happens)
(P(A or B) formula)
(A and B both happen)
(Card draw probabilities)
(Cannot happen together)
(Rolling 2 or 5)
(One does not affect the other)
(P(A and B) for independent events)
(Two dice rolls)
(One affects the other)
(Probability given something happened)
(Cards without replacement)
(Works for dependent events)
(Knowledge check)
(Average outcome over many trials)
(Weighted average)
(Fair six-sided die)
(Different probabilities)
(Why probability matters)
(Using probability for speed)
(Birthday paradox in hash tables)
(Read statement)
(36 outcomes)
(Sum equals 7)
(P = 1/6)
(Read statement)
(Easier to count no match)
(Multiply probabilities)
(Why it is surprising)
(LeetCode 528)
(Convert weights to ranges)
(Build cumulative array)
(Find the range)
(Python code)
(Knowledge check)
(Apply what you learned)
Uniform random selection
Reservoir sampling idea
The pseudocode
Fair randomization
The standard solution
The code
summary
Weighted random selection
Converting weights to ranges
Finding the target range
The code
summary
Reservoir sampling variant
Fair selection in one pass
The code
summary
What we learned