09 Basic Counting
09 Basic Counting
09 Basic Counting
Lecture 9: December 20
Sum Rule
A B
= |B B B B|
= 2 · 2 · 2 · 2 = 24
• case sensitive
L ::= {a,b,…,z,A,B,…,Z}
D ::= {0,1,…,9}
Example: Counting Passwords
L ::= {a,b,…,z,A,B,…,Z}
D ::= {0,1,…,9}
P6 = L L D L D L D L D L D
L L D
5
L L D
n 1 n 1
L LD
L L D
n 1
52 62n 1
(counting by partitioning)
= 104 – 94
= 3439
(counting the complement)
Defective Dollars
then,
|Q| = n1 · n2 · n3 · … · nk
Permutations
For example, here are all six permutations of the set {a, b, c}:
(a, b, c) (a, c, b) (b, a, c)
(b, c, a) (c, a, b) (c, b, a)
n
n
Stirling’s formula: n! ~ 2πn
e
Combinations
4 suits (♠ ♥ ♦ ♣)
13 values (2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A)
There are 13 choices for (1), 12 choices for (2), and 4 choices for (3).
By generalized product rule, there are 13x12x4 = 624 hands.
A Full House is a hand with three cards of one value and two cards of another value.
Double
Count!
So the answer is
Example 4: Every Suit
How many hands contain at least one card from every suit?
Double count!
n times
(1+X)0 = 1
(1+X)1 = 1 + 1X
(1+X)2 = 1 + 2X + 1X2
Direct proof:
1. Define a set S.
2. Show that |S| = n by counting one way.
3. Show that |S| = m by counting another way.
4. Conclude that n = m.
Double counting
Proving Identities
Pascal’s Formula
Direct proof:
Proving Identities
Pascal’s Formula
Combinatorial proof:
Consider we have 2n balls, n of them are red, and n of them are blue.
Let S be all n-card hands that can be dealt from a deck containing
n red cards (numbered 1, . . . , n) and 2n black cards (numbered 1, . . . , 2n).
The right hand side = # of ways to choose n cards from these 3n cards.
The left hand side = # of ways to choose r cards from red cards x
# of ways to choose n-r cards from black cards
= # of ways to choose n cards from these 3n cards
= the right hand side.