Final Review Session
Counting 2 Ways Review
(Just everything they used for normal counting)
• Permutations: Number of ways to rearrange n objects: n!
n!
• Arrangements: Number of ways to rearrange k out of n total objects: (n−k)!
• Selections/Binomial
Coefficients: Number of ways to choose k out of n total objects:
n
n!
=
k
k!(n−k)!
• Addition Principle: Let X be a set and let U1 , . . . , Un be a partition of X for some
n ∈ N, such that each set Ui is finite. Then X is finite, and |X| = |U1 | + |U2 | + . . . + |Un |.
• Multiplication Principle: Let n ≥ 1 and m1 , m2 , . . . , mn ∈ N. Suppose for each i ∈ [n]
(i)
(i)
(i)
that we are given finite sets Xa1 ,...,ai−1 with |Xa1 ,...,ai−1 | = mi , where aj ∈ Xa1 ,...,aj−1 for
(2)
(n)
each j < i. Define P = {(a1 , a2 , . . . , an ) | a1 ∈ X (1) , a2 ∈ Xa1 , . . . , an ∈ Xa1 ,...,an−1 } Then
P is finite and |P | = m1 × m2 × . . . × mn .
• Stars and Bars: n indistinguishable items
in k distinguishable bins, when numbers in each
bin are nonnegative, there are n+k−1
ways,
and when numbers in each bin are positive,
k−1
n−1
there are k−1 ways.
Counting 2 Ways Problems
1. Show that for all n, k ≥ 2,
n
k
=
n−2
k−2
n−2
using C2W.
+ 2 n−2
k
k−1 +
Solution: LHS: choose subset of size k from [n]. RHS: partition on whether n and n − 1 in
the set. Our cases will be
(a) n and n − 1 both in the set: choose k − 2 remaining elements of subset from n − 2
remaining elements
(b) exactly one of n and n − 1 in the subset: 2-step process where first choose which of n
or n − 1 in subset, then choose k − 1 remaining elements of subset from n − 2 remaining
values. Cite MP.
(c) Neither of n or n − 1 in the subset: so choose all k elements of subset from remaining
n − 2 values.
Justify exhaustive and disjoint and cite AP.
2. Show that
x+y+z
k
=
Pk
i=0
Pk−i
j=0
x
i
y
j
z
k−i−j
using C2W.
Solution: Have three groups of people (X, Y , Z) with x, y and z people in each and want
to select subset of k people from all three groups combined.
LHS: select
RHS: partition first on i, the number of people from the subset that are from group X,
then as a subcase partition on j, the number of people from the subset that are from group
Y , then select i people from X, j people from Y , and finally the remaining k − i − j people
from Z.
n Pmin(k,m) n n−i n−k 3. Show that nk m
= i=0
i k−i m−i .
Solution: The set we are counting is the ways to choose two subsets from [n] of size k and
m respectively.
LHS: Choose two subsets from [n], K and M , one of size k and one of size m.
RHS: Partition on i, the number of elements that are in both subsets. i ranges from 0 (no
elements are shared) to min(k, m) where the smaller set is a subset of the other. In each
case, we first choose the i common elements. Then, we choose the remaining elements of set
K, which we have n − i options for to pick k − i elements. Finally, we choose the remaining
m − i people for set of M from the remaining n − k people.
= xy + x2 + y2 .
4. Show that x+y
2
Solution: You have x different gelato flavors and y different ice cream flavors. You can add
two different flavors of either gelato or ice cream to a cone. The set we will count is the
number of ways to do this.
LHS: You have x + y flavors in total. Choose 2.
RHS: Partition on whether you get just gelato, just ice cream, or a flavor of each.
(a) Just icecream: You choose 2 flavors from the y available.
(b) Just gelato: You choose 2 flavors from the x available.
(c) One of each: You choose a gelato flavor in x ways and then an icecream flavor in y
ways.
Countability Review
• Countably Infinite: A set X is countably infinite if there exists a bijection f : N → X
(or f : X → N).
• Countable/Uncountable: A set X is countable if it is finite or countably infinite, and
uncountable otherwise.
• Preserving Countability: Let X0 , X1 , . . . be countable sets and let n ∈ N. Then, the
following are countable:
Sn
i=0 Xi
S
– Countable union of countable sets: ∞
i=0 Xi
– Finite union of countable sets:
– Finite Cartesian product of countable sets:
Qn
i=0 Xi
• Known Countable Sets: N, Z, and Q are known countable sets.
• Known Uncountable Sets: {0, 1}N , R, and P(N) are known uncountable sets.
• Showing a set is Countable: Let C be a countable set. To show a set X is countable,
you can either:
– Find an injection f : X → C
– Find a surjection f : C → X
• Showing a set is Uncountable: Let U be an uncountable set. To show a set X is
uncountable, you can either:
– Find an injection f : U → X
– Find a surjection f : X → U
Countability Problems
1. If A is countable and B is uncountable, determine with proof whether B \ A is countable
or uncountable.
Solution: It is uncountable. If it were countable then (B \ A) ∪ A would be countable, as
the countable union (here we are looking at a finite union) of countable sets is countable.
2. From F23 Final: Let S ⊆ {0, 1}N be the set of all binary strings that have a finite number of
substrings of the form 11. For instnace, the string 1011011000... has exactly two substrings
of the form 11, so it is in S. Determine with proof if S is countable.
Solution: This set is uncountable.
f (b0 b1 b2 b3 b4 ...) = b0 0b1 0b2 0b3 0b4 0....
We can create an injection f : {0, 1}N → S via
Prove well defined. Since for any two adjacent bits i and i + 1, either i or i + 1 is odd.
Thus in the output f (b), one of i or i + 1 will be zero for any 0, and thus there are no 11
substrings. Zero is a finite amount of.
Show injective.
3. Also From F23 Final: Let S ⊆ {0, 1}N be the set of all binary strings that have NO
substrings of the form 11, and a FINITE number of substrings of the form 00. Determine
with proof if this S is countable.
Solution: This set is countable. This solution will separate the {1010..., 0101...} and S \
{1010..., 0101...}. Note that {1010..., 0101...} ⊆ S.
S
We can now define f : S \ {1010..., 0101...} → i∈N Ni via f (b) = {l0 , l1 , ..., lk } where li is
the first index of the ith substring of form 00. Prove well defined.
Prove injective: by function definition all substrings of form 00 must be in the same location.
Now need to prove all other bits are equal. Because we cannot have any additional 00
substrings besides those specified, and we cannot have any 11 substrings at all, all other
bits will have to alternate ...010101... in the same way to prevent them from occurring and
thus will be equal.
4. From F21 Final: Let C = {S ⊂ N+ : x ∈ S =⇒ 2x ∈
/ S}. For example {2} ∈ C but
{2, 4} ∈
/ C.
Solution: This set is uncountable. There are multiple possible approaches. The set
P({odd naturals}) is a subset of C, because ∀X ∈ P({odd naturals}), ∀x ∈ X, 2x ∈
/ X.
You can use an injection f : P(N) → C via f (S) = {2x + 1 : x ∈ S} (i.e. we force every
element in the set to be an odd number).
Prove well definedness and injectivity.
Probability Review
• Sample Space: A set of outcomes usually denoted Ω.
• Probability Measure: A function P : P(Ω) → [0, 1] mapping outcomes to probabilities.
• Probability Space: A tuple (Ω, P) containing a sample space and probability measure
that satisfies
(i) P[Ω] = 1
(ii) For E ⊆ Ω, P(E) =
P
ω∈E P({ω})
(ii*) AnSequivalentP
definition for (ii) is if E1 , E2 , ... ⊆ Ω with Ei ∩ Ej = ∅ for i ̸= j, then
∞
E
)
=
P( ∞
i
i=1
i=1 P(Ei ).
)
• Conditional Probability: For E, F ⊆ Ω, P(F ) ̸= 0, P(E | F ) = P(E∩F
P(F ) .
• Independence: E, F are independent iff P(E∩F ) = P(E)P(F ). Alternatively, if P(F ) ̸= 0,
this is true iff P(E) = P(E | F ).
• Mutually Exclusive: E, F are mutually exclusive iff E ∩ F = ∅.
• Binomial Distribution: Flip n coins, each
with probability p to land heads. Then the
probability we flip a total of k heads is nk pk (1 − p)n−k .
• Law of Total Probability: For some partition B1 , B2 , . . . Bn of the sample space Ω,
we have that P(A) = P(A ∩ B1 ) + P(A ∩ B2 ) + . . . + P(A ∩ Bn ). It also follows that
P(A) = P(A ∩ B) + P(A ∩ B c ).
• Bayes’ Theorem: For P(B), P(A) > 0, P(B | A) = P(A|B)P(B)
. From the Law of Total
P(A)
Probability and definition of conditional probability, an alternative is
P(B | A) =
P(A | B)P(B)
P(A | B)P(B) + P(A | B c )P(B c )
or if events B1 , B2 , . . . , Bn partition Ω, then
P(Bi | A) =
P(A | Bi )P(Bi )
P(A | B1 )P(B1 ) + P(A | B2 )P(B2 ) + . . . + P(A | Bn )P(Bn )
• Useful Facts: Let (ω, P) be a probability space. Let E, F ⊆ Ω.
1. P(∅) = 0
2. P(E c ) = 1 − P(E)
3. P(E ∪ F ) = P(E) + P(F ) − P(E ∩ F )
Probability Problems
1. Easy Bayes: An email site unrolls a new spam detection tool that correctly identifies a
spam email as spam with probability 80%. The probability that it labels a non-spam email
as spam is 20%. It is estimated that 40% of all emails are spam. If an email is detected as
spam, what is the probability it is actually spam?
Solution: Let S be the event an email is spam, and let D be the event an email is detected
as spam.
P(D | S)P(S)
P(D | S)P(S) + P(D | S c )P(S c )
4 2
·
= 4 25 51 3
5 · 5 + 5 · 5
8
=
11
P(S | D) =
2. Easy Binomial Distribution: You roll a fair 5-sided die 5 times. What is the probability
you roll an even number exactly twice? The sides of the die are numbered 1 through 5.
Solution: Let P = P[even number on a specific roll] = 25 since 2 and 4 are even.
We can treat this as a binomial distribution where we have 5 trials
and
2 our
probability of
3 3
success on a trial is 25 . The probability fo exactly 2 successes is 52 52
5 .
3. Stars and Bars Counting Outcomes: Elizabeth is decorating cookies for a Christmas party.
She has baked 500 indistinguishable cookies and has 6 frosting colors: red, green, blue,
white, pink and mocha mousse. She chooses a frosting color at random for each cookie.
What is the probability she ends up frosting exactly 100 cookies in red?
Solution: We can do this by counting the total number of outcomes, and the number of
outcomes where exactly 100 cookies in red.
To count the total number of outcomes, we canuse stars and bars with 500 indistinguishable
stars and 6 bins, so 5 bars. This gives us 505
total outcomes.
5
To count the outcomes with exactly 100 red cookies, we set aside 100 cookies to be frosted
in red, and then we use stars and bars to frost the remaining 400 cookies using green, blue,
white, pink or mocha mousse.
We can use stars and bars with 400 stars and 5 bins, so 4
404
bars. This gives us 4 .
So the probability is
(404
4 )
.
(505
5 )
4. Harder Bayes: You roll a fair 4-sided die twice. You lose $1 if your second roll is less than
your first. If you lost money, what is the probability you rolled a 2 on your first roll?
Solution: Let A1 be the event you roll a 1 on the first roll, A2 be the event you roll a 2,
A3 be the event you roll a 3, and A4 be the event you roll a 4. Let L be the event you lost
money on the second roll. Note that P[Ai ] = 41 ∀i ∈ [4] and that P[L | Ai ] = i−1
4 .
Now use Bayes’ Theorem with Law of Total Probability:
P[L | A2 ]P[A2 ]
P[L | A1 ]P[A1 ] + P[L | A2 ]P[A2 ] + P[L | A3 ]P[A3 ] + P[L | A4 ]P[A4 ]
1
1
4
1 42 1
1
= 0 1
1
3
+
4
4
4
4 + 4
4 + 4
4
1
=
6
P[A2 | L] =