CMSC250

Combinatorics

Combinatorics

Counting
Permutations
Combinations

Counting

Combinatorics: hard to define, but has to do with counting

Counting is easy

Counting is easy

How many letters in the English Alphabet?

How many characters in the string "COUNT"?

How many 3 character strings can be made from "COUNT"?

Counting is (somewhat) easy

How many letters in the English Alphabet?

How many characters in the string "COUNT"?

How many 3 character strings can be made from "COUNT"?

Counting is (somewhat) easy

How many values can 3 bits represent?

How many values can a byte represent?

How many values can a byte with 3 '1's represent?

Counting is (somewhat) easy hard

How many values can 3 bits represent?

How many values can a byte represent?

How many values can a byte with 3 '1's represent?

Counting

Counting is (somewhat) easy hard

But we have rules to help make it easy

Note: we will be counting events, or actions

Multiplication rule of Counting

If we have some event $A$ which has $x$ number of ways of occurring, and we have some event $B$ which has $y$ number of ways of occurring, then there are $xy$ ways of both A and B occurring

Multiplication rule of Counting

Event 1: Flip a coin, Event 2: roll a 6-sided dice

How many outcomes are possible?

$2 \cdot 6$
$\{H1,H2,H3,H4,H5,H6,T1,T2,T3,T4,T5,T6\}$

Multiplication rule of Counting

Event 1: Choose a letter of the alphabet
Event 2: Choose a letter of the alphabet

How many 2 character strings exist?

$26 \cdot 26$

Multiplication rule of Counting

Event 1: Choose a letter of the alphabet
Event 2: Choose a letter of the alphabet

Event 3: Choose a letter of the alphabet

How many 3 character strings exist?

$26 \cdot 26 \cdot 26$

Multiplication rule of Counting

How many 4-bit strings exist?

$2 \cdot 2 \cdot 2 \cdot 2$

Addition rule of Counting

If we have some event $A$ which has $x$ number of ways of occurring, and we have some event $B$ which has $y$ number of ways of occurring, and only one event can occur, then there are $x + y$ ways of either (but not both) events occurring

Addition rule of Counting

Event 1: Flip a coin, Event 2: roll a 6-sided dice

How many outcomes are possible?

$2 + 6$
$\{H,T,1,2,3,4,5,6\}$

Addition rule of Counting

Event 1: Choose a letter, Event 2: Choose a digit

How many outcomes are possible?

$26 + 10$

Event 1: Choose an alphanumeric value
Event 2: Choose an alphanumeric value

How many Alphanumeric Strings of size 2?

$(26 + 10) \cdot (26 + 10)$

How many alphabetic strings of length 2 and 4 exist?

$(26 \cdot 26) + (26 \cdot 26 \cdot 26 \cdot 26)$

Permutations

Recall: How many characters in the string "COUNT"?

How many strings are anagrams of "COUNT"?

_ _ _ _ _

5 options for first character

Recall: How many characters in the string "COUNT"?

How many strings are anagrams of "COUNT"?

T _ _ _ _

4 options for second character

Recall: How many characters in the string "COUNT"?

How many strings are anagrams of "COUNT"?

T O _ _ _

3 options for third character

Recall: How many characters in the string "COUNT"?

How many strings are anagrams of "COUNT"?

T O N _ _

2 options for fourth character

Recall: How many characters in the string "COUNT"?

How many strings are anagrams of "COUNT"?

T O N C _

1 options for fifth character

Recall: How many characters in the string "COUNT"?

How many strings are anagrams of "COUNT"?

T O N C U


Recall: How many characters in the string "COUNT"?

How many strings are anagrams of "COUNT"?

T O N C U

$5 \cdot 4 \cdot 3 \cdot 2 \cdot 1 = 5!$

Recall: How many characters in the string "COUNT"?

How many strings are anagrams of "COUNT"?

T O N C U

$5 \cdot 4 \cdot 3 \cdot 2 \cdot 1 = 5!$

Assumptions: no repetitions, use all characters

How many 3 character strings can be made from "COUNT"?

_ _ _

5 options for first character

How many 3 character strings can be made from "COUNT"?

T _ _

4 options for second character

How many 3 character strings can be made from "COUNT"?

T O _

3 options for third character

How many 3 character strings can be made from "COUNT"?

T O N


How many 3 character strings can be made from "COUNT"?

T O N

$5 \cdot 4 \cdot 3$

How many 4 character strings can be made from "COUNT"?

_ _ _ _

$5 \cdot 4 \cdot 3 \cdot 2$

How many 2 character strings can be made from "COUNT"?

_ _

$5 \cdot 4$

How many 2 character strings can be made from "COUNT"?

_ _

$5 \cdot 4$

Pattern?

Pattern?

4 Character strings = $5 \cdot 4 \cdot 3 \cdot 2$

3 Character strings = $5 \cdot 4 \cdot 3$

2 Character strings = $5 \cdot 4$

Arrangements of size $k$ taken from a set of size $n$ can be represented as
$\frac{n!}{(n-k)!} = P(n,k)$

Arrangements of size $k$ taken from a set of size $n$ can be represented as
$\frac{n!}{(n-k!)} = P(n,k)$

Note: No repetitions: "CCO" is not allowed, and all characters in "COUNT" are unique

Note: Order matters: "COU" $\neq$ "OUC"

Examples

How many ATM Pins exist?: $10^4$

How many ATM Pins with no repeated digits exist?: $\frac{10!}{(10-4)!}$

How many 3 character strings of "Justin" exist?: $\frac{6!}{(6-3)!}$

How many 5 unique character strings exist?$\frac{26!}{(26-5)!}$

Combinations

What if order did not matter?

How many values can a byte with 3 '1's represent?

How many anagrams from the string: $00000111$

However: $1_01_11_20_00_10_20_30_4 = 1_11_01_20_00_10_20_30_4$

What if order did not matter?

How many values can a byte with 3 '1's represent?

How many anagrams from the string: $00000111$

$00000111 = ABCDEFGH$

However: $1_01_11_20_00_10_20_30_4 = 1_11_01_20_00_10_20_30_4$

However: $FGHABCDE = GFHABCDE$

How many values can a byte with 3 '1's represent?

$00000111 = ABCDEFGH$

However: $FGHABCDE = GFHABCDE$

$FGHx,FHGx,GFHx,GHFx,HFGx,HGFx$, where $x= ABCDE$, is the same

Permutations of $FGH = 3!$

How many values can a byte with 3 '1's represent?

$00000111 = ABCDEFGH$

Permutations of $FGH = 3!$

The Number of subsets of size $k$ from a set of size $n$ can be represented as
$\frac{n!}{k!(n-k)!} = \frac{P(n,k)}{k!} = C(n,k) = {n \choose k}$

Examples

How many ways can I create a group of 4 from 10 people?: $C(10,4)$

How many bytes with 6 '1's exist?: $C(8,6)$

${n \choose 1}$: n

${n \choose n}$: 1

12 people: forming a team of 5, but 2 people stick together?: $C(10,3) + C(10,5)$