09 Basic Counting

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 32

Basic Counting

Lecture 9: December 20
Sum Rule

A B

If sets A and B are disjoint, then


|A  B| = |A| + |B|

• Class has 43 women, 54 men, so total enrollment = 43 + 54 = 97

• 26 lower case letters, 26 upper case letters, and 10 digits,


so total characters = 26+26+10 = 62
Product Rule

Given two sets A and B, the Cartisean product

If |A| = m and |B| = n, then


|A  B| = mn.

A = {a, b, c, d}, B = {1, 2, 3}


A  B = {(a,1),(a,2),(a,3),
(b,1),(b,2),(b,3),
(c,1),(c,2),(c,3),
(d,1),(d,2),(d,3) }

If there are 4 men and 3 women, there are

4  3  12 possible married couples.


Product Rule: Counting Strings

The number of length-4 strings from alphabet B ::= {0,1}

= |B  B  B  B|

= 2 · 2 · 2 · 2 = 24

The number of length-n strings from an alphabet of size m is mn.


Example: Counting Passwords

How many passwords satisfy the following requirements?

• between 6 & 8 characters long

• starts with a letter

• case sensitive

• other characters: digits or letters

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

Pn :: length n passwords


 L L  D
n 1
Example: Counting Passwords

L  L  D
n 1 n 1
 L  LD

 L  L  D 
n 1

 52  62n 1

The set of Passwords: P  P6  P7  P8


P  P6  P7  P8
 52  625  52  626  52  627
 186125210680448
 19  1014
At Least One Seven

How many # 4-digit numbers with at least one 7?

Method 1: count by 1st occurrence of 7:

7xxx + o7xx + oo7x + ooo7

103 + 9·102 + 92·10 + 93 = 3439

(counting by partitioning)

Method 2: |4-digit numbers with at least one 7|=

|4-digit numbers| - |those with no 7s|

= 104 – 94
= 3439
(counting the complement)
Defective Dollars

A dollar is defective if some digit appears


more than once in the 6-digit serial number.

How common are nondefective dollars?


Defective Dollars

How common are nondefective dollars?

10 possible choices for the first digit,


9 possible choices for the second digit, and so on…

So, there are 10x9x8x7x6x5


= 151200 serial number with all its digit different

There are totally 106 = 1000000 serial numbers.

So, only about 15% of dollars are nondefective.


Generalized Product Rule

Q a set of length-k sequences. If there are:

n1 possible 1st elements in sequences,

n2 possible 2nd elements for each first entry,

n3 possible 3rd elements for each 1st & 2nd,

then,
|Q| = n1 · n2 · n3 · … · nk
Permutations

A permutation of a set S is a sequence that


contains every element of S exactly once.

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)

How many permutations of an n-element set are there?


Permutations

How many permutations of an n-element set are there?

• There are n choices for the first element.

• For each of these, there are n − 1 remaining choices for


the second element.

• For every combination of the first two elements, there


are n − 2 ways to choose the third element, and so forth.

• Thus, there are a total of


n · (n − 1) · (n − 2) · · · 3 · 2 · 1 = n!
permutations of an n-element set.

n
n 
Stirling’s formula: n! ~ 2πn  
e
Combinations

How many subsets of k elements of an n-element set?

• There are n choices for the first element.

• For each of these, there are n − 1 remaining choices for


the second element.

• There are n – k + 1 remaining choices for the last element.

• Thus, there are a total of


n · (n − 1) · (n − 2) · · · (n – k + 1) to choose k elements.
Splitting into 2 Sets

How many n-bit sequences contain k zeros and (n − k) ones?

Once the positions of k zeros are fixed,


the positions of (n-k) ones are fixed.

How many ways to split 12 people into 3 groups of 4 people?


Poker Hands

There are 52 cards in a deck.


Each card has a suit and a value.

4 suits (♠ ♥ ♦ ♣)
13 values (2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A)

Five-Card Draw is a card game in which each player


is initially dealt a hand, a subset of 5 cards.

How many different hands?


Example 1: Four of a Kind

A Four-of-a-Kind is a set of four cards with the same value.

How many different hands contain a Four-of-a-Kind?


Example 1: Four of a Kind

A hand with a Four-of-a-Kind is completely


described by a sequence specifying:
1. The value of the four cards.
2. The value of the extra card.
3. The suit of the extra card.

There are 13 choices for (1), 12 choices for (2), and 4 choices for (3).
By generalized product rule, there are 13x12x4 = 624 hands.

Only 1 hand in about 4165 has a Four-of-a-Kind!


Example 2: Full House

A Full House is a hand with three cards of one value and two cards of another value.

How many different hands contain a Full House?


Example 2: Full House

There is a bijection between Full Houses and sequences specifying:


1. The value of the triple, which can be chosen in 13 ways.
2. The suits of the triple, which can be selected in (4 3) ways.
3. The value of the pair, which can be chosen in 12 ways.
4. The suits of the pair, which can be selected in (4 2) ways.

By generalized product rule, there are

Only 1 hand in about 634 has a Full House!


Example 3: Two Pairs

How many hands have Two Pairs; that is,


two cards of one value, two cards of another value,
and one card of a third value?
Example 3: Two Pairs

1. The value of the first pair, which can be chosen in 13 ways.


2. The suits of the first pair, which can be selected (4 2) ways.
3. The value of the second pair, which can be chosen in 12 ways.
4. The suits of the second pair, which can be selected in (4 2) ways
5. The value of the extra card, which can be chosen in 11 ways.
6. The suit of the extra card, which can be selected in 4 ways.

Number of Two pairs =

Double
Count!

So the answer is
Example 4: Every Suit

How many hands contain at least one card from every suit?

1. The value of each suit, which can be selected in 13x13x13x13 ways.


2. The suit of the extra card, which can be selected in 4 ways.
3. The value of the extra card, which can be selected in 12 ways.

Double count!

So the answer is 134x4x12/2 = 685464


Binomial Theorem

We can compute the coefficients by simple counting arguments.

n times

Each term corresponds to selecting 1 or x from each of the n factors.

ck is number of terms with exactly k x’s are selected from n factors.


Binomial Theorem

(1+X)0 = 1

(1+X)1 = 1 + 1X

(1+X)2 = 1 + 2X + 1X2

(1+X)3 = 1 + 3X + 3X2 + 1X3

(1+X)4 = 1 + 4X + 6X2 + 4X3 + 1X4


Binomial Coefficients

In general we have the following identity:

When x=1, y=1, it says that

When x=1, y=-1, it says that


Proving Identities

Direct proof:

Combinatorial proof: Number of ways to choose k items from n items

= number of ways to choose n-k items from n items


Finding a Combinatorial Proof

A combinatorial proof is an argument that establishes an


algebraic fact by relying on counting principles.
Many such proofs follow the same basic outline:

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:

•The LHS is number of ways to choose k elements from n+1 elements.


•Let the first element be x.
•If we choose x, then we need to choose k-1 elements
from the remaining n elements, and number of ways to do so is
•If we don’t choose x, then we need to choose k elements
from the remaining n elements, and number of ways to do so is
•This partitions the ways to choose k elements from n+1 elements,
therefore
Combinatorial Proof

Consider we have 2n balls, n of them are red, and n of them are blue.

The RHS is number of ways to choose n balls from the 2n balls.


To choose n balls, we can
- choose 0 red ball and n blue balls, number of ways =
- choose 1 red ball and n-1 blue balls, number of ways =
-…
- choose i red balls and n-i blue balls, number of ways =
-…
- choose n red balls and 0 blue ball, number of ways =

Hence number of ways to choose n balls is also equal to


More Combinatorial Proof

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.

You might also like