Uploaded by siddaarth2

CS70 Cheatsheet

advertisement
CS 70
Cheatsheet
Note 1 (Propositional Logic)
•
•
•
•
𝑃 =⇒ 𝑄 ≡ ¬π‘ƒ ∨ 𝑄
𝑃 =⇒ 𝑄 ≡ ¬π‘„ =⇒ ¬π‘ƒ
¬(𝑃 ∧ 𝑄) ≡ ¬π‘ƒ ∨ ¬π‘„
¬(𝑃 ∨ 𝑄) ≡ ¬π‘ƒ ∧ ¬π‘„
Note 7 (Modular Artithmetic)
•
•
•
•
• π‘₯ −1 (modular inverse) exists mod π‘š if and only if gcd(π‘₯, π‘š) = 1
𝑃 ∧ (𝑄 ∨ 𝑅) ≡ (𝑃 ∧ 𝑄) ∨ (𝑃 ∧ 𝑅)
• Extended Euclidean Algorithm:
𝑃 ∨ (𝑄 ∧ 𝑅) ≡ (𝑃 ∨ 𝑄) ∧ (𝑃 ∨ 𝑅)
π‘₯ 𝑦 bπ‘₯/𝑦c π‘Ž 𝑏
¬(∀π‘₯𝑃(π‘₯)) ≡ ∃π‘₯¬π‘ƒ(π‘₯)
– new π‘Ž = old 𝑏 j k
¬(∃π‘₯𝑃(π‘₯)) ≡ ∀π‘₯¬π‘ƒ(π‘₯)
35 12
2
−1 3 answer
– new 𝑏 = π‘Ž − 𝑏 𝑦π‘₯
12 11
1
1 −1
– if gcd(π‘₯, 𝑦) = 1, then π‘Ž =
11 1
11
0 1
π‘₯ −1 mod 𝑦, 𝑏 = 𝑦 −1 mod π‘₯
start
1 0
Note 2/3 (Proofs)
• Direct proof
• Proof by contraposition
• Proof by cases
• Proof by induction
– Base case (prove smallest case is true)
– Inductive hypothesis (assume 𝑛 = π‘˜ true for weak induction, assume 𝑛 ≤ π‘˜ true for strong induction)
– Inductive step (prove 𝑛 = π‘˜ + 1 is true)
• Pigeonhole principle
– Putting 𝑛 + π‘š balls in 𝑛 bins =⇒ ≥ 1 bin has ≥ 2 balls
Note 4 (Sets)
gcd
• 𝒫(𝑆) = powerset/set of all subsets; if |𝑆| = π‘˜, |𝒫(𝑆)| = 2 π‘˜
• One to one (injection); 𝑓 (π‘₯) = 𝑓 (𝑦) =⇒ π‘₯ = 𝑦
• Onto (surjection); (∀𝑦∃π‘₯)( 𝑓 (π‘₯) = 𝑦); “hits" all of range
• Bijection: both injective and surjective
Note 5 (Countability & Computability)
• Countable if bijection to N
• Cantor-Schroder-Bernstein Theorem: bijection between 𝐴 and 𝐡 if
there exists injections 𝑓 : 𝐴 → 𝐡 and 𝑔 : 𝐡 → 𝐴
• Cantor diagonalization: to prove uncountability, list out possibilities,
construct new possibility different from each listed at one place (ex.
reals ∈ (0, 1), infinite binary strings, etc)
• 𝐴 ⊆ 𝐡 and 𝐡 is countable =⇒ 𝐴 is countable
• 𝐴 ⊇ 𝐡 and 𝐴 is uncountable =⇒ 𝐡 is uncountable
• Infinite cartesian product sometimes countable (∅ × ∅ × · · · ), sometimes
uncountable ({0, 1}∞ )
• Halting Problem: can’t determine for every program whether it halts
(uncomputable)
• Reduction of TestHalt(P, x) to some task (here, TestTask)
– define inner function that does the task if and only if P(x) halts
– call TestTask on the inner function and return the result in
TestHalt
Note 6 (Graph Theory)
• 𝐾 𝑛 has 2 edges
• Handshaking lemma: total degree = 2𝑒
• Trees: (all must be true)
– connected & no cycles
– connected & has 𝑛 − 1 edges (𝑛 = |𝑉 |)
– connected & removing an edge disconnects the graph
– acyclic & adding an edge makes a cycle
• Hypercubes:
– 𝑛-length bit strings, connected by an edge if differs by exactly 1 bit
– 𝑛-dimensional hypercube has 𝑛2𝑛−1 edges, and is bipartite (even
vs odd parity bitstring)
• Eulerian walk: visits each edge once; only possible if connected and
all even degree or exactly 2 odd degree
• Eulerian tour: Eulerian walk but starts & ends at the same vertex;
only possible if all even degree and connected
• Planar graphs
– 𝑣+ 𝑓 = 𝑒+2
P𝑓
– 𝑖=1 𝑠𝑖 = 2𝑒 where 𝑠𝑖 = number of sides of face 𝑖
– 𝑒 ≤ 3𝑣 − 6 if planar (because 𝑠𝑖 ≥ 3)
– 𝑒 ≤ 2𝑣 − 4 if planar for bipartite graphs (because 𝑠𝑖 ≥ 4)
– nonplanar if and only if the graph contains 𝐾5 or 𝐾3,3
– all planar graphs can be colored with ≤ 4 colors
𝑛(𝑛−1)
• Chinese Remainder Theorem:
– find bases 𝑏 𝑖 that are ≡ 1 mod π‘š 𝑖 and ≡ 0 mod π‘š 𝑗 for 𝑗 ≠ 𝑖
Q
→ 𝑏 𝑖 = 𝑐 𝑖 (𝑐−1
𝑖≠ 𝑗 π‘š 𝑗
𝑖 modQπ‘š 𝑖 ) where 𝑐 𝑖 =
P
– π‘₯ ≡ π‘Ž 𝑖 𝑏 𝑖 (mod
π‘šπ‘– )
Q
– solution is unique mod π‘š 𝑖
– π‘š 𝑖 must be pairwise relatively prime in order to use CRT
Note 8 (RSA)
• Scheme: for primes 𝑝, π‘ž, find 𝑒 coprime to ( 𝑝 − 1)(π‘ž − 1)
– public key: 𝑁 = π‘π‘ž and 𝑒
– private key: 𝑑 = 𝑒 −1 mod ( 𝑝 − 1)(π‘ž − 1)
– encryption of message π‘š: π‘š 𝑒 (mod 𝑁) = 𝑦
– decryption of encrypted message 𝑦: 𝑦 𝑑 (mod 𝑁) = π‘š
• Fermat’s Little Theorem (FLT): π‘₯ 𝑝 ≡ π‘₯ (mod 𝑝), or π‘₯ 𝑝−1 ≡ 1
(mod 𝑝) if π‘₯ coprime to 𝑝
• Prime Number Theorem: πœ‹(𝑛) ≥ ln𝑛𝑛 for 𝑛 ≥ 17, where πœ‹(𝑛) = # of
primes ≤ 𝑛
• Breaking RSA if we know 𝑑:
– we know 𝑑𝑒 − 1 = π‘˜ ( 𝑝 − 1)(π‘ž − 1), where π‘˜ ≤ 𝑒 because
𝑑 < ( 𝑝 − 1)(π‘ž − 1)
– so 𝑑𝑒−1
π‘˜ = π‘π‘ž − 𝑝 − π‘ž − 1; π‘π‘ž = 𝑁, so we can find 𝑝, π‘ž because we
know 𝑑, 𝑒, π‘˜
Note 9 (Polynomials)
• Property 1: nonzero polynomial of degree 𝑑 has at most 𝑑 roots
• Property 2: 𝑑 + 1 pairs of points (π‘₯𝑖 distinct) uniquely defines a polynomial of degree at most 𝑑
• Lagrange Interpolation:
Q
π‘₯−π‘₯
– Δ𝑖 (π‘₯) = 𝑖≠ 𝑗 π‘₯𝑖 −π‘₯𝑗𝑗
P
– 𝑃(π‘₯) = 𝑖 𝑦 𝑖 Δ𝑖 (π‘₯)
• Secret Sharing (normally under 𝐺𝐹 ( 𝑝)):
– 𝑃(0) = secret, 𝑃(1), . . . , 𝑃(𝑛) given to all people
– 𝑃(π‘₯) = polynomial of degree π‘˜ − 1, where π‘˜ people are needed to
get the secret
• Rational Root Theorem: for 𝑃(π‘₯) = π‘Ž 𝑛 π‘₯ 𝑛 + · · · + π‘Ž 0 , the roots of 𝑃(π‘₯)
𝑝
that are of the form π‘ž must have 𝑝 | π‘Ž 0 , π‘ž | π‘Ž 𝑛
Note 10 (Error Correcting Codes)
• Erasure Errors: π‘˜ packets lost, message length 𝑛; need to send 𝑛 + π‘˜
packets because 𝑃(π‘₯) of degree 𝑛 − 1 needs 𝑛 points to define it
• General Errors: π‘˜ packets corrupted, message length 𝑛; send 𝑛 + 2π‘˜
packets
• Berlekamp Welch:
– 𝑃(π‘₯) encodes message (degree 𝑛 − 1)
– 𝐸 (π‘₯) constructed so that roots are where the errors are (degree π‘˜);
coefficients unknown
– 𝑄(π‘₯) = 𝑃(π‘₯)𝐸 (π‘₯) (degree 𝑛 + π‘˜ − 1)
– substitute all (π‘₯𝑖 , π‘Ÿ 𝑖 ) into 𝑄(π‘₯𝑖 ) = π‘Ÿ 𝑖 𝐸 (π‘₯𝑖 ), make system of equations
𝑄 ( π‘₯)
– solve for coefficients; 𝑃(π‘₯) = 𝐸 ( π‘₯)
1
CS 70
Cheatsheet
Note 11 (Counting)
• 1st rule of counting: multiply # of ways for each choice
• 2nd rule of counting: count ordered arrangements, divide by # of
ways
to get unordered
to order
𝑛!
• π‘›π‘˜ = π‘˜!(𝑛−π‘˜)!
= # ways to select π‘˜ from 𝑛
• Stars and bars:
𝑛 objects, π‘˜ groups → 𝑛 stars, π‘˜ − 1 bars
𝑛+π‘˜−1
→ 𝑛+π‘˜−1
π‘˜−1 =
𝑛
• Zeroth rule of counting: if bijection between
𝐴 and 𝐡, then | 𝐴| = |𝐡|
P
• Binomial theorem: (π‘Ž + 𝑏) 𝑛 = π‘›π‘˜=0 π‘›π‘˜ π‘Ž π‘˜ 𝑏 𝑛−π‘˜
𝑛−2
𝑛 π‘˜
• Hockey-stick identity: π‘˜+1
= 𝑛−1
π‘˜ + π‘˜ +···+ π‘˜
P
(−1) π‘˜
• Derangements: 𝐷 𝑛 = (𝑛 − 1)(𝐷 𝑛−1 + 𝐷 𝑛−2 ) = 𝑛! π‘›π‘˜=0 π‘˜!
• Principle of Inclusion-Exclusion: | 𝐴1 ∪ 𝐴2 | = | 𝐴1 | + | 𝐴2 | − | 𝐴1 ∩ 𝐴2 |
More generally, alternate add/subtract
all
√
𝑛combinations
• Stirling’s approximation: 𝑛! ≈ 2πœ‹π‘› 𝑛𝑒
Note 12 (Probability Theory)
• Sample points = outcomes
• Sample space = Ω = all possible outcomes
• Probability space: (Ω, P(πœ”)); (sample space, probability function)
P
• 0 ≤ P(πœ”) ≤ 1, ∀πœ” ∈ Ω; πœ” ∈٠𝑃(πœ”) = 1
1 , ∀πœ” ∈ Ω
• Uniform probability: P(πœ”) = |Ω|
P
• P( 𝐴) = πœ” ∈ 𝐴 P(πœ”) where 𝐴 is an event
# sample points in 𝐴
| 𝐴|
• If uniform: P( 𝐴) = # sample points in Ω = |Ω|
• P( 𝐴) = 1 − P( 𝐴)
Note 13 (Conditional Probability)
πœ”)
• P(πœ” | 𝐡) = P(
𝑃 (𝐡) for πœ” ∈ 𝐡
𝐴∩𝐡)
→ P( 𝐴 ∩ 𝐡) = P( 𝐴 | 𝐡) P(𝐡)
• P( 𝐴 | 𝐡) = P(P(𝐡)
• Bayes’ Rule:
P(𝐡 | 𝐴) P( 𝐴)
P(𝐡 | 𝐴) P( 𝐴)
.
P( 𝐴 | 𝐡) =
=
P(𝐡)
P(𝐡 | 𝐴) P( 𝐴) + P(𝐡 | 𝐴) P( 𝐴)
• Total Probability Rule (denom of Bayes’ Rule):
𝑛
𝑛
∑︁
∑︁
P(𝐡) =
P(𝐡 ∩ 𝐴𝑖 ) =
P(𝐡 | 𝐴𝑖 ) P( 𝐴𝑖 )
𝑖=1
𝑖=1
for 𝐴𝑖 partitioning Ω
• Independence: P(
S𝐴 ∩ 𝐡) = P(P𝐴) P(𝐡) or P( 𝐴 | 𝐡) = P( 𝐴)
𝑛 𝐴 ≤ 𝑛 P( 𝐴 )
• Union bound: P 𝑖=1
𝑖
𝑖
𝑖=1
Note 16 (Geometric/Poisson Distributions
• Geometric distribution: P(𝑋 = 𝑖) = exactly 𝑖 trials until success with
probability 𝑝; use 𝑋 − 1 for failures until success
– Memoryless Property: P(𝑋 > π‘Ž + 𝑏 | 𝑋 > π‘Ž) = P(𝑋 > 𝑏); i.e.
waiting > 𝑏 units has same probability, no matter where we start
• Poisson distribution: πœ† = average $ of successes in a unit of time
– 𝑋 ∼ Pois(πœ†), π‘Œ ∼ Pois(πœ†) independent: 𝑋 + π‘Œ ∼ Pois(πœ† + πœ‡)
– 𝑋 ∼ Bin(𝑛, πœ†π‘› ) where πœ† > 0 is constant, as 𝑛 → ∞, 𝑋 → Pois(πœ†)
Note 20 (Continuous Distributions)
• Probability density function:
– ∫𝑓 𝑋 (π‘₯) ≥ 0 for π‘₯ ∈ R
∞
– −∞ 𝑓 𝑋 (π‘₯) dπ‘₯ = 1
∫π‘₯
• Cumulative density function: 𝐹𝑋 (π‘₯) = P(𝑋 ≤ π‘₯) = −∞ 𝑓 𝑋 (𝑑) d𝑑,
d 𝐹 (π‘₯)
𝑓 𝑋 (π‘₯) = dπ‘₯
𝑋
∫∞
• Expectation: E[𝑋] = −∞ π‘₯ 𝑓 𝑋 (π‘₯) dπ‘₯
∫∞
• LOTUS: E[𝑔(𝑋)] = −∞ 𝑔(π‘₯) 𝑓 𝑋 (π‘₯) dπ‘₯
• Joint distribution: P(π‘Ž ≤ 𝑋 ≤ 𝑏, 𝑐 ≤ π‘Œ ≤ 𝑑)
– ∫𝑓 π‘‹π‘Œ ∫(π‘₯, 𝑦) ≥ 0, ∀π‘₯, 𝑦 ∈ R
∞ ∞
– −∞ −∞ 𝑓 π‘‹π‘Œ (π‘₯, 𝑦) dπ‘₯ d𝑦 = 1
∫∞
• Marginal distribution: 𝑓 𝑋 (π‘₯) = −∞ 𝑓 π‘‹π‘Œ (π‘₯, 𝑦) d𝑦; integrate over all 𝑦
• Independence: 𝑓 π‘‹π‘Œ (π‘₯, 𝑦) = 𝑓 𝑋 (π‘₯) π‘“π‘Œ (𝑦)
π‘“π‘‹π‘Œ ( π‘₯,𝑦)
𝑓𝑋 ( π‘₯)
• Conditional probability: 𝑓 𝑋 | 𝐴 (π‘₯) = P(
π‘“π‘Œ ( 𝑦)
𝐴) , 𝑓 𝑋 |π‘Œ (π‘₯ | 𝑦) =
• Exponential distribution: continuous analog to geometric distribution
– Memoryless property: P(𝑋 > 𝑑 + 𝑠 | 𝑋 > 𝑑) = P(𝑋 > 𝑠)
– Additionally, P(𝑋 < π‘Œ | min(𝑋, π‘Œ ) > 𝑑) = P(𝑋 < π‘Œ )
– If 𝑋 ∼ Exp(πœ† 𝑋 ), π‘Œ ∼ Exp(πœ†π‘Œ ) independent, then
𝑋
min(𝑋, π‘Œ ) ∼ Exp(πœ† 𝑋 + πœ†π‘Œ ) and P(𝑋 ≤ π‘Œ ) = πœ†π‘‹πœ†+πœ†
π‘Œ
• Normal distribution (Gaussian distribution)
2
2
– If 𝑋 ∼ N (πœ‡ 𝑋 , πœŽπ‘‹ ), π‘Œ ∼ N (πœ‡π‘Œ , πœŽπ‘Œ ) independent:
𝑍 = π‘Žπ‘‹ + π‘π‘Œ ∼ N (π‘Žπœ‡ 𝑋 + π‘πœ‡π‘Œ , π‘Ž 2 πœŽπ‘‹2 + 𝑏 2 πœŽπ‘Œ2 )
P𝑛
𝑋𝑖 , all 𝑋𝑖 iid with mean πœ‡,
• Central Limit Theorem: if 𝑆 𝑛 = 𝑖=1
variance 𝜎 2 ,
𝑆𝑛
𝜎2
𝑆 𝑛 − π‘›πœ‡
≈ N πœ‡,
;
≈ N (0, 1).
√
𝜎
𝑛
𝜎 𝑛
Note 17 (Concentration Inequalities, LLN)
]
• Markov’s Inequality: P(𝑋 ≥ 𝑐) ≤ E[𝑋
𝑐 , if 𝑋 nonnegative, 𝑐 > 0
Note 14 (Random Variables)
• Bernoulli distribution: used as an indicator RV
• Binomial distribution: P(𝑋 = 𝑖) = 𝑖 successes in 𝑛 trials, success
probability 𝑝
– If 𝑋 ∼ Bin(𝑛, 𝑝), π‘Œ ∼ Bin(π‘š, 𝑝) independent, 𝑋 +π‘Œ ∼ Bin(𝑛+π‘š, 𝑝)
• Hypergeometric distribution: P(𝑋 = π‘˜) = π‘˜ successes in 𝑁 draws w/o
replacement from size 𝑁 population with 𝐡 objects (as successes)
• Joint distribution: P(𝑋 = π‘Ž, π‘Œ = 𝑏)
P
• Marginal distribution: P(𝑋 = π‘Ž) = 𝑏 ∈𝐡 P(𝑋 = π‘Ž, π‘Œ = 𝑏)
• Independence: P(𝑋 = π‘Ž, π‘Œ = 𝑏) = P(𝑋 = π‘Ž) P(π‘Œ = 𝑏)
P
• Expectation: E[𝑋] = π‘₯ ∈X π‘₯ P(𝑋 = π‘₯)
P
• LOTUS: E[𝑔(𝑋)] = π‘₯ ∈X 𝑔(π‘₯) P(𝑋 = π‘₯)
• Linearity of expectation: E[π‘Žπ‘‹ + π‘π‘Œ ] = π‘Ž E[𝑋] + 𝑏 E[π‘Œ ]
• 𝑋, π‘Œ independent: E[π‘‹π‘Œ ] = E[𝑋] E[π‘Œ ]
Note 15 (Variance/Covariance)
• Variance: Var(𝑋) = E[(𝑋 − πœ‡) 2 ] = E 𝑋 2 − E[𝑋] 2
– Var(𝑐𝑋) = 𝑐2 Var(𝑋), Var(𝑋 +π‘Œ ) = Var(𝑋) + Var(π‘Œ ) + 2 Cov(𝑋, π‘Œ )
– if indep: Var(𝑋 + π‘Œ ) = Var(𝑋) + Var(π‘Œ )
• Covariance: Cov(𝑋, π‘Œ ) = E[π‘‹π‘Œ ] − E[𝑋] E[π‘Œ ]
Cov(𝑋 ,π‘Œ )
• Correlation: Corr(𝑋, π‘Œ ) = πœŽπ‘‹ πœŽπ‘Œ , always in [−1, 1]
• Indep. implies uncorrelated (Cov = 0), but not other way around, ex.
(
𝑋=
1
−1
𝑝 = 0.5
,
𝑝 = −0.5
ο£±

1

ο£²

π‘Œ = −1


0
ο£³
𝑋 = −1, 𝑝 = 0.5
𝑋 = −1, 𝑝 = 0.5
𝑋=1
2
|π‘Œ | π‘Ÿ ]
• Generalized Markov: P(|π‘Œ | ≥ 𝑐) ≤ E[ π‘π‘Ÿ for 𝑐, π‘Ÿ > 0
Var(𝑋 )
• Chebyshev’s Inequality: P(|𝑋 − πœ‡| ≥ 𝑐) ≤ 𝑐 2 for πœ‡ = E[𝑋],
𝑐>0
√︁
– Corollary: P(|𝑋 − πœ‡| ≥ π‘˜πœŽ) ≤ π‘˜12 for 𝜎 = Var(𝑋), π‘˜ > 0
• Confidence intervals:
Var( 𝑝)
ˆ
– For proportions, P(| 𝑝ˆ − 𝑝| ≥ πœ€) ≤ πœ€ 2 ≤ 𝛿, where 𝛿 is the
confidence level (95% interval → 𝛿 = 0.05)
𝑝 (1− 𝑝)
– 𝑝ˆ = proportion of successes in 𝑛 trials, Var( 𝑝)
ˆ =
𝑛
1
– =⇒ 𝑛 ≥ 4πœ€ 2 𝛿
2
– For means, P 𝑛1 𝑆 𝑛 − πœ‡ ≥ πœ€ ≤ π‘›πœŽπœ€ 2 = 𝛿
P𝑛
– 𝑆 𝑛 = 𝑖=1 𝑋𝑖 , all 𝑋𝑖 ’s iid mean πœ‡, variance 𝜎 2
– =⇒ πœ€ = √𝜎 , interval = 𝑆 𝑛 ± √𝜎
𝑛𝛿
𝑛𝛿
– With CLT,
√
√ P(| 𝐴𝑛 − πœ‡| ≤ πœ€) = P
( 𝐴𝑛 −πœ‡) 𝑛
𝜎
πœ€ 𝑛
≤ 𝜎
√ πœ€ 𝑛
≈ 1 − 2Φ − 𝜎 = 1 − 𝛿.
2
Here, 𝐴𝑛 = 𝑛1 𝑆 𝑛 and CLT gives 𝐴𝑛 ≈ N πœ‡, πœŽπ‘› ; use inverse cdf
to get πœ€
• Law of large numbers: as 𝑛 → ∞, sample average of iid 𝑋1 , . . . 𝑋𝑛
tends to population mean
CS 70
Cheatsheet
Note 24 (Markov Chains)
• Markov chain = sequence of states
• 𝑋𝑛 = state at time step 𝑛
• X = state space (finite)
• πœ‹ 𝑛 = distribution of states at time step 𝑛
• Markov property (memoryless): P(𝑋𝑛+1 = 𝑖 | 𝑋𝑛 , 𝑋𝑛−1 , . . . , 𝑋0 ) =
P(𝑋𝑛+1 = 𝑖 | 𝑋𝑛 )
• Transition matrix (P): transition probabilities, from row to column
• πœ‹ 𝑛 = πœ‹0 P𝑛
• Invariant distribution: πœ‹ = πœ‹P; solve balance equations in addition to
P
πœ‹(𝑖) = 1
• Irreducible Markov chain: any state can be reached from any other
• All irreducible Markov chains have a unique invariant distribution:
∑︁
1 𝑛−1
1{π‘‹π‘š = 𝑖}.
πœ‹(𝑖) = lim
𝑛→∞ 𝑛
π‘š=0
That is, average time spent at state 𝑖 = πœ‹(𝑖)
• Periodicity: let 𝑑 (𝑖) = gcd{𝑛 > 0 : P(𝑋𝑛 = 𝑖 | 𝑋0 = 𝑖) > 0}
– If 𝑑 (𝑖) > 1, periodic with period 𝑑
– If 𝑑 (𝑖) = 1, aperiodic
– If irreducible, all states have the same 𝑑 (𝑖)
• Aperiodic irreducible Markov chains will always converge to the
invariant distribution
• Hitting time: # of steps before first reaching state 𝑖
– Let 𝛽( 𝑗) denote this value, starting at state 𝑗; set up system of
equations and solve
• P( 𝐴 before 𝐡): similarly, let 𝛼( 𝑗) denote this probability, starting at
state 𝑗; set up system of equations and solve (use TPR)
• Similar problems: let 𝑓 (𝑖) denote # of steps or probability, starting at
state 𝑖; set up equations and solve
• 2-state Markov chain:
π‘Ž
1−π‘Ž
1
2
1−𝑏
𝑏
𝑏
1−π‘Ž
π‘Ž
π‘Ž
P=
and πœ‹ = π‘Ž+𝑏 π‘Ž+𝑏
𝑏
1−𝑏
Other
• In CS70, naturals and whole numbers both include 0
𝑛
• Sum of finite geometric series: 1−π‘Ÿ
1−π‘Ÿ π‘Ž where π‘Ÿ is ratio, π‘Ž is first term,
𝑛 is number of terms
• Memoryless property independence: if 𝑋, π‘Œ both memoryless (i.e.
geometric or exponential), then min(𝑋, π‘Œ ) and max(𝑋, π‘Œ ) − min(𝑋, π‘Œ )
are
independent
P𝑛
P
P𝑛
• E 𝑆 2𝑛 = 𝑖=1
E 𝑋𝑖2 + 2 𝑖≠ 𝑗 E 𝑋𝑖 𝑋 𝑗 = 𝑖=1
E 𝑋𝑖2 , where
P𝑛
𝑆 𝑛 = 𝑖=1 𝑋𝑖 ; useful for variance of indicators
• Coupon Collector Problem:
– 𝑛 distinct items, each with equal probability; 𝑋𝑖 = # of tries before
𝑖th new item, given 𝑖 − 1 already
P
– 𝑆 𝑛 = 𝑋𝑖 = total tries before getting all items
– We have 𝑋𝑖 ∼ Geom( 𝑛−𝑖+1
𝑛 ) because 𝑖 − 1 old items, so 𝑛 − 𝑖 + 1
new items
– Hence,
𝑛
𝑛
𝑛 1
∑︁
∑︁
∑︁
𝑛
E[𝑆 𝑛 ] =
E[𝑋𝑖 ] =
=𝑛
≈ 𝑛(ln 𝑛 + 0.5772)
𝑖=1
𝑖=1 𝑛 − 𝑖 + 1
𝑖=1 𝑖
3
CS 70
Table 1: Common Discrete Distributions
Distribution
Parameters
PMF (P(𝑋 = π‘˜))
Uniform
Uniform(π‘Ž, 𝑏)
Bernoulli
Bernoulli( 𝑝)
1
𝑏−π‘Ž+1
(
1 𝑝
0 1− 𝑝
Binomial
Bin(𝑛, 𝑝)
𝑛 π‘˜
𝑝 (1 − 𝑝) 𝑛−π‘˜
π‘˜
Geometric
Geom( 𝑝)
𝑝(1 − 𝑝) π‘˜−1
Poisson
πœ† π‘˜ 𝑒 −πœ†
Pois(πœ†)
CMF (P(𝑋 ≤ π‘˜))
Expectation (E[𝑋])
π‘˜ −π‘Ž+1
𝑏−π‘Ž+1
π‘Ž+𝑏
2
Variance (Var(𝑋))
(𝑏 − π‘Ž
+ 1) 2
−1
12
𝐾 𝑁 −𝐾 π‘˜
𝑛−π‘˜
𝑁
𝑛
Hypergeometric(𝑁, 𝐾, 𝑛)
𝑋 ∈ [π‘Ž, 𝑏]
—
𝑝
𝑝(1 − 𝑝)
𝑋 ∈ {0, 1}
—
𝑛𝑝
𝑛𝑝(1 − 𝑝)
𝑋∈N
1 − (1 − 𝑝) π‘˜
1
𝑝
1− 𝑝
𝑝2
𝑋∈N
—
πœ†
πœ†
𝑋∈N
𝐾 (𝑁 − 𝐾)(𝑁 − 𝑛)
𝑁 2 (𝑁 − 1)
𝑋∈N
π‘˜!
Hypergeometric
Support
—
𝑛
𝐾
𝑁
𝑛
4
Distribution
Uniform
Exponential
Normal/Gaussian
PDF ( 𝑓 𝑋 (π‘₯))
Parameters
CDF (𝐹𝑋 (π‘₯) = P(𝑋 ≤ π‘₯))
Expectation (E[𝑋])
Uniform(π‘Ž, 𝑏)
1
𝑏−π‘Ž
π‘₯−π‘Ž
𝑏−π‘Ž
Exp(πœ†)
πœ†π‘’ −πœ†π‘₯
1 − 𝑒 −πœ†π‘₯
π‘Ž+𝑏
2
1
πœ†
Φ(π‘₯)
πœ‡
N (πœ‡, 𝜎 2 )
√
(π‘₯ − πœ‡) 2
exp −
2𝜎 2
2πœ‹πœŽ
1
Variance (Var(𝑋))
(𝑏
− π‘Ž) 2
12
1
πœ†2
𝜎2
Support
𝑋 ∈ [π‘Ž, 𝑏]
𝑋 ∈ [0, ∞)
𝑋∈R
Cheatsheet
Table 2: Common Continuous Distributions
Download