02: combinatorics - stanford universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and...

72
02: Combinatorics Lisa Yan and Jerry Cain September 16, 2020 1

Upload: others

Post on 16-Aug-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

02: CombinatoricsLisa Yan and Jerry CainSeptember 16, 2020

1

Page 2: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Quick slide reference

2

3 Permutations II 02a_permutations

17 Combinations I 02b_combinations_i

29 Combinations II 02c_combinations_ii

37 Buckets and The Divider Method LIVE

Todayโ€™s discussion thread: https://us.edstem.org/courses/2678/discussion/124109

Page 3: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Permutations II

3

02a_permutations

Page 4: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Summary of Combinatorics

4

Sort objects(permutations)

Distinct(distinguishable)

Counting tasks on ๐‘› objects

Choose ๐‘˜ objects(combinations)

Put objects in ๐‘Ÿbuckets

Page 5: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Sort ๐‘› distinct objects

5

# of permutations =

Page 6: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Summary of Combinatorics

6

Sort objects(permutations)

Distinct(distinguishable)

Somedistinct

Counting tasks on ๐‘› objects

Choose ๐‘˜ objects(combinations)

Put objects in ๐‘Ÿbuckets

๐‘›!

Page 7: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Sort semi-distinct objects

7

All distinct Some indistinct

๐‘›!Order ๐‘›distinct objects

Page 8: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Sort semi-distinct objectsHow do we find the number of permutations considering

some objects are indistinct?

By the product rule, permutations of distinct objects is a two-step process:

8

permutationsof distinct objects

permutationsconsidering some

objects are indistinct

Permutationsof just the

indistinct objectsร—=

Page 9: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Sort semi-distinct objects

9

permutationsof distinct objects

permutationsconsidering some

objects are indistinct=___________

How do we find the number of permutations consideringsome objects are indistinct?

By the product rule, permutations of distinct objects is a two-step process:

ร—Permutations

of just theindistinct objects

Permutationsof just the

indistinct objects

Page 10: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

General approach to counting permutationsWhen there are ๐‘› objects such that

๐‘›! are the same (indistinguishable or indistinct), and๐‘›" are the same, and

โ€ฆ๐‘›# are the same,

The number of unique orderings (permutations) is

๐‘›!๐‘›!! ๐‘›"!โ‹ฏ๐‘›#!

.

10

For each group of indistinct objects,Divide by the overcounted permutations.

Page 11: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Sort semi-distinct objects

How many permutations?

11

๐‘›!๐‘›!! ๐‘›"!โ‹ฏ๐‘›#!

Order ๐‘› semi-distinct objects

Page 12: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Summary of Combinatorics

12

Sort objects(permutations)

Distinct(distinguishable)

Somedistinct

Counting tasks on ๐‘› objects

Choose ๐‘˜ objects(combinations)

Put objects in ๐‘Ÿbuckets

๐‘›!๐‘›!

๐‘›"! ๐‘›#!โ‹ฏ๐‘›$!

Page 13: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Strings

How many orderings of letters are possible for the following strings?

1. BOBA

2. MISSISSIPPI

13

๐‘›!๐‘›!! ๐‘›"!โ‹ฏ๐‘›#!

Order ๐‘› semi-distinct objects

๐Ÿค”

Page 14: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Strings

How many orderings of letters are possible for the following strings?

1. BOBA

2. MISSISSIPPI

14

= !!#!= 12

= $$!$!!!!!#!

= 34,650

๐‘›!๐‘›!! ๐‘›"!โ‹ฏ๐‘›#!

Order ๐‘› semi-distinct objects

Page 15: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Unique 6-digit passcodes with six smudges

15

Total = 6!= 720 passcodes

How many unique 6-digit passcodes are possible if a phone password uses each of six distinct numbers?

๐‘›!๐‘›!! ๐‘›"!โ‹ฏ๐‘›#!

Order ๐‘› semi-distinct objects

Page 16: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Unique 6-digit passcodes with five smudges

16

How many unique 6-digit passcodes are possible if a phone password uses each of five distinct numbers?

Steps:1. Choose digit to repeat 5 outcomes2. Create passcode (sort 6 digits:

4 distinct, 2 indistinct)

Total = 5 ร— !!#!

= 1,800 passcodes

๐‘›!๐‘›!! ๐‘›"!โ‹ฏ๐‘›#!

Order ๐‘› semi-distinct objects

Page 17: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Combinations I

17

02b_combinations_i

Page 18: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Summary of Combinatorics

18

Sort objects(permutations)

Distinct(distinguishable)

Somedistinct

Distinct

Counting tasks on ๐‘› objects

Choose ๐‘˜ objects(combinations)

Put objects in ๐‘Ÿbuckets

๐‘›!๐‘›!

๐‘›"! ๐‘›#!โ‹ฏ๐‘›$!

Page 19: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Combinations with cakeThere are ๐‘› = 20 people.How many ways can we choose ๐‘˜ = 5 people to get cake?

19

Consider the following generative processโ€ฆ

Page 20: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Combinations with cakeThere are ๐‘› = 20 people.How many ways can we choose ๐‘˜ = 5 people to get cake?

20

1. ๐‘› people get in line

1 2 3 4 65 7 8 109

11 12 13 14 1615 17 18 2019

๐‘›! ways

Page 21: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Combinations with cakeThere are ๐‘› = 20 people.How many ways can we choose ๐‘˜ = 5 people to get cake?

21

2. Put first ๐‘˜in cake room

1. ๐‘› people get in line

1 way

1 2 3 4 65 7 8 109

11 12 13 14 1615 17 18 2019

๐‘›! ways

Page 22: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Combinations with cake

22

2. Put first ๐‘˜in cake room

1. ๐‘› people get in line

There are ๐‘› = 20 people.How many ways can we choose ๐‘˜ = 5 people to get cake?

6 7 8 109 11 12 13

14 15 16 17 18 2019

๐‘›! ways 1 way

Page 23: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Combinations with cake

23

๐‘˜! different permutations lead to

the same mingle

2. Put first ๐‘˜in cake room

1. ๐‘› people get in line

There are ๐‘› = 20 people.How many ways can we choose ๐‘˜ = 5 people to get cake?

3. Allow cake group to mingle

6 7 8 109 11 12 13

14 15 16 17 18 2019

๐‘›! ways 1 way

Page 24: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Combinations with cake

24

4. Allow non-cake group to mingle

3. Allow cake group to mingle

2. Put first ๐‘˜in cake room

1. ๐‘› people get in line

There are ๐‘› = 20 people.How many ways can we choose ๐‘˜ = 5 people to get cake?

6 7 8 109 11 12 13

14 15 16 17 18 2019

๐‘›! ways 1 way๐‘˜! different

permutations lead to the same mingle

Page 25: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Combinations with cake

25

4. Allow non-cake group to mingle๐‘› โˆ’ ๐‘˜ ! different

permutations lead to the same mingle

3. Allow cake group to mingle

2. Put first ๐‘˜in cake room

1. ๐‘› people get in line

There are ๐‘› = 20 people.How many ways can we choose ๐‘˜ = 5 people to get cake?

๐‘›! ways 1 way๐‘˜! different

permutations lead to the same mingle

Page 26: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Combinations

A combination is an unordered selection of ๐‘˜ objectsfrom a set of ๐‘› distinct objects.

The number of ways of making this selection is

๐‘›!๐‘˜! ๐‘› โˆ’ ๐‘˜ !

= ๐‘›! ร— 1 ร—1๐‘˜!ร—

1๐‘› โˆ’ ๐‘˜ !

=๐‘›๐‘˜

26

1. Order ๐‘›distinct objects

2. Take first ๐‘˜as chosen

3. Overcounted:any ordering of chosen group is same choice

4. Overcounted:any ordering of unchosen group is same choice

Page 27: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Combinations

A combination is an unordered selection of ๐‘˜ objectsfrom a set of ๐‘› distinct objects.

The number of ways of making this selection is

๐‘›!๐‘˜! ๐‘› โˆ’ ๐‘˜ !

= ๐‘›! ร— 1 ร—1๐‘˜!ร—

1๐‘› โˆ’ ๐‘˜ !

=๐‘›๐‘˜

Note: !

!"# = !#

27

Binomial coefficient

๐‘›๐‘˜

Page 28: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Probability textbooks

How many ways are there to choose 3 booksfrom a set of 6 distinct books?

28

ways63

=6!3! 3!

= 20

๐‘›๐‘˜

Choose ๐‘˜ of ๐‘› distinct objects

Page 29: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Combinations II

29

02c_combinations_ii

Page 30: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Summary of Combinatorics

30

Sort objects(permutations)

Distinct(distinguishable)

Somedistinct

Distinct

1 group ๐‘Ÿ groups

Counting tasks on ๐‘› objects

Choose ๐‘˜ objects(combinations)

Put objects in ๐‘Ÿbuckets

๐‘›๐‘˜๐‘›!

๐‘›!๐‘›"! ๐‘›#!โ‹ฏ๐‘›$!

Page 31: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

General approach to combinations

The number of ways to choose ๐‘Ÿ groups of ๐‘› distinct objects such thatFor all ๐‘– = 1,โ€ฆ , ๐‘Ÿ, group ๐‘– has size ๐‘›&, andโˆ‘&'!# ๐‘›& = ๐‘› (all objects are assigned), is

๐‘›!๐‘›!! ๐‘›"!โ‹ฏ๐‘›#!

=๐‘›

๐‘›!, ๐‘›", โ‹ฏ , ๐‘›#

31

Multinomial coefficient

Page 32: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Datacenters

32

A. !"#,%," = 60,060

B. !"#

$%

"" = 60,060

C. 6 โ‹… 1001 โ‹… 10 = 60,060D. A and BE. All of the above

Datacenter # machinesA 6B 4C 3

13 different computers are to be allocated to 3 datacenters as shown in the table:How many different divisions are possible?

๐‘›๐‘›!, ๐‘›", โ‹ฏ , ๐‘›#

Choose ๐‘˜ of ๐‘› distinct objects into ๐‘Ÿ groups of size ๐‘›!, โ€ฆ ๐‘›"

๐Ÿค”

Page 33: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Datacenters

33

A. !"#,%," = 60,060

B. !"#

$%

"" = 60,060

C. 6 โ‹… 1001 โ‹… 10 = 60,060D. A and BE. All of the above

Datacenter # machinesA 6B 4C 3

13 different computers are to be allocated to 3 datacenters as shown in the table:How many different divisions are possible?

๐‘›๐‘›!, ๐‘›", โ‹ฏ , ๐‘›#

Choose ๐‘˜ of ๐‘› distinct objects into ๐‘Ÿ groups of size ๐‘›!, โ€ฆ ๐‘›"

Page 34: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Datacenters

34

Datacenter # machinesA 6B 4C 3

13 different computers are to be allocated to 3 datacenters as shown in the table:How many different divisions are possible?

๐‘›๐‘›!, ๐‘›", โ‹ฏ , ๐‘›#

Choose ๐‘˜ of ๐‘› distinct objects into ๐‘Ÿ groups of size ๐‘›!, โ€ฆ ๐‘›"

A. !"#,%," = 60,060

Strategy: Combinations into 3 groupsGroup 1 (datacenter A): ๐‘›" = 6Group 2 (datacenter B): ๐‘›# = 4Group 3 (datacenter C): ๐‘›) = 3

Page 35: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Datacenters

35

A. !"#,%," = 60,060

Datacenter # machinesA 6B 4C 3

13 different computers are to be allocated to 3 datacenters as shown in the table:How many different divisions are possible?

๐‘›๐‘›!, ๐‘›", โ‹ฏ , ๐‘›#

Choose ๐‘˜ of ๐‘› distinct objects into ๐‘Ÿ groups of size ๐‘›!, โ€ฆ ๐‘›"

B. !"#

$%

"" = 60,060

Strategy: Combinations into 3 groupsGroup 1 (datacenter A): ๐‘›" = 6Group 2 (datacenter B): ๐‘›# = 4Group 3 (datacenter C): ๐‘›) = 3

Strategy: Product rule with 3 steps1. Choose 6 computers for A $%

&2. Choose 4 computers for B '

(3. Choose 3 computers for C %

%

Page 36: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Datacenters

36

A. !"#,%," = 60,060

Datacenter # machinesA 6B 4C 3

13 different computers are to be allocated to 3 datacenters as shown in the table:How many different divisions are possible?

๐‘›๐‘›!, ๐‘›", โ‹ฏ , ๐‘›#

Choose ๐‘˜ of ๐‘› distinct objects into ๐‘Ÿ groups of size ๐‘›!, โ€ฆ ๐‘›"

B. !"#

$%

"" = 60,060

Strategy: Combinations into 3 groupsGroup 1 (datacenter A): ๐‘›" = 6Group 2 (datacenter B): ๐‘›# = 4Group 3 (datacenter C): ๐‘›) = 3

Strategy: Product rule with 3 steps1. Choose 6 computers for A $%

&2. Choose 4 computers for B '

(3. Choose 3 computers for C %

%

Your approach will determine if you use binomial/multinomial coefficients or factorials.

Page 37: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

02: Combinatorics (live)Lisa YanSeptember 16, 2020

37

Page 38: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Reminders: Lecture withโ€ข Turn on your camera if you are able, mute your mic in the big roomโ€ข Virtual backgrounds are encouraged (classroom-appropriate)

38

Todayโ€™s discussion thread: https://us.edstem.org/courses/2678/discussion/124109

Page 39: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Summary of Combinatorics

39

Sort objects(permutations)

Distinct(distinguishable)

Somedistinct

Distinct

1 group ๐‘Ÿ groups๐‘›!

๐‘›"! ๐‘›#!โ‹ฏ๐‘›$!๐‘›๐‘˜

๐‘›๐‘›", ๐‘›#, โ‹ฏ , ๐‘›$

๐‘›!

Counting tasks on ๐‘› objects

Choose ๐‘˜ objects(combinations)

Put objects in ๐‘Ÿbuckets

Review

Page 40: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Summary of Combinatorics

40

Sort objects(permutations)

Distinct(distinguishable)

Somedistinct

Distinct

1 group ๐‘Ÿ groups

Indistinct?

Counting tasks on ๐‘› objects

Choose ๐‘˜ objects(combinations)

Put objects in ๐‘Ÿbuckets

๐‘›๐‘˜

๐‘›๐‘›", ๐‘›#, โ‹ฏ , ๐‘›$

๐‘›!๐‘›!

๐‘›"! ๐‘›#!โ‹ฏ๐‘›$!

Page 41: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Think Slide 42 is a question to think over by yourself (~1min).

Post any clarifications here or in chat!https://us.edstem.org/courses/2678/discussion/124109

41

๐Ÿค”(by yourself)

Page 42: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

A trick questionHow many distinct (distinguishable) ways are there to group 6 indistinct(indistinguishable) objects into 3 groups, where groups A, B, and C have sizes 1, 2, and 3, respectively?

42

A. !",$,%

B. !!"!$!%!

C. 0

D. 1E. Both A and BF. Something else

๐Ÿค”(by yourself)

Page 43: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

A trick questionHow many distinct (distinguishable) ways are there to group 6 indistinct(indistinguishable) objects into 3 groups, where groups A, B, and C have sizes 1, 2, and 3, respectively?

43

A. !",$,%

B. !!"!$!%!

C. 0

D. 1E. Both A and BF. Something else

A (fits 1) B (fits 2) C (fits 3)

Page 44: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Probability textbooks1. How many ways are there to choose 3 books

from a set of 6 distinct books?

44

๐‘›๐‘˜

Choose ๐‘˜ of ๐‘› distinct objectsReview

Page 45: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Think Slide 46 is a question to think over by yourself (~2min).

Post any clarifications here or in chat!https://us.edstem.org/courses/2678/discussion/124109

45

๐Ÿค”(by yourself)

Page 46: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Probability textbooks1. How many ways are there to choose 3 books

from a set of 6 distinct books?

2. What if we do not want to read both the 9th and 10th edition of Ross?

46

ways63

=6!3! 3!

= 20

A. !" โˆ’ !

# = 5 ways

B. !!"!"!#!

= 10

C. 2 โ‹… %# + %

" = 16

๐‘›๐‘˜

Choose ๐‘˜ of ๐‘› distinct objects

Ask: https://us.edstem.org/courses/2678/discussion/124109 ๐Ÿค”

D. !" โˆ’ %

& = 16

E. Both C and D

F. Something else

Page 47: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Probability textbooks1. How many ways are there to choose 3 books

from a set of 6 distinct books?

2. What if we do not want to read both the 9th and 10th edition of Ross?

47

ways63

=6!3! 3!

= 20

๐‘›๐‘˜

Choose ๐‘˜ of ๐‘› distinct objects

Strategy 1: Sum Rule

Page 48: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Probability textbooks1. How many ways are there to choose 3 books

from a set of 6 distinct books?

2. What if we do not want to read both the 9th and 10th edition of Ross?

48

ways63

=6!3! 3!

= 20

๐‘›๐‘˜

Choose ๐‘˜ of ๐‘› distinct objects

Strategy 2: โ€œForbidden methodโ€ (unofficial name)

Forbidden method: It is sometimes easier to exclude invalid cases than to include cases.

Page 49: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Interlude for jokes/announcements

49

Page 50: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Announcements

50

Problem Set #1

Out: todayDue: Friday 9/25, 1:00pmCovers: through Friday 9/18

Python tutorial (2 timeslots)

When: Friday 12:00-1:00am PTFriday 2:00-3:00pm PT

Recorded? yesNotes: to be posted online

Getting help

Ed discussion: find study buddies!Office hours: start todayhttps://web.stanford.edu/class/cs109/stanfo

rd/staff.html

Section sign-ups/Acquaintance form

Form released: later todayForm due: Saturday 5:00pm 9/19Results: latest Sunday

Page 51: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Buckets and The Divider Method

51

Page 52: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Summary of Combinatorics

52

Sort objects(permutations)

Distinct(distinguishable)

Somedistinct Distinct Indistinct

Distinct

1 group ๐‘Ÿ groups

Counting tasks on ๐‘› objects

Choose ๐‘˜ objects(combinations)

Put objects in ๐‘Ÿbuckets

๐‘›๐‘˜

๐‘›๐‘›", ๐‘›#, โ‹ฏ , ๐‘›$

๐‘›!๐‘›!

๐‘›"! ๐‘›#!โ‹ฏ๐‘›$!

Page 53: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Steps:1. Bucket 1st string2. Bucket 2nd string

โ€ฆ๐‘›. Bucket ๐‘›th string

๐‘Ÿ* outcomes

Balls and urns Hash tables and distinct strings

53

ssdfsskdfsd

viridian city

fooandbaz

boba

1 2 r

How many ways are there to hash ๐‘› distinct strings to ๐‘Ÿ buckets?

โ€ฆ

Page 54: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Summary of Combinatorics

54

Sort objects(permutations)

Distinct(distinguishable)

Somedistinct Distinct Indistinct

Distinct

1 group ๐‘Ÿ groups

Counting tasks on ๐‘› objects

Choose ๐‘˜ objects(combinations)

Put objects in ๐‘Ÿbuckets

๐‘›๐‘˜

๐‘›๐‘›", ๐‘›#, โ‹ฏ , ๐‘›$

๐‘Ÿ*๐‘›!๐‘›!

๐‘›"! ๐‘›#!โ‹ฏ๐‘›$!

Page 55: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Servers and indistinct requests

55

1 2 r

How many ways are there to distribute ๐‘› indistinct web requests to ๐‘Ÿ servers?

โ€ฆ

request

request

request

request

GoalServer 1 has ๐‘ฅ! requests,Server 2 has ๐‘ฅ" requests,โ€ฆServer ๐‘Ÿ has ๐‘ฅ# requests (the rest)

Page 56: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Simple example: ๐‘› = 3 requests and ๐‘Ÿ = 2 servers

56

Page 57: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Bicycle helmet salesHow many ways can we assign ๐‘› = 5 indistinct children to ๐‘Ÿ = 4 distinct bicycle helmet styles?

57

Page 58: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Bicycle helmet sales1 possible assignment outcome:

58

Goal Order ๐‘› indistinct objects and ๐‘Ÿ โˆ’ 1 indistinct dividers.

Consider the following generative processโ€ฆ

Page 59: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

The divider method: A generative proofHow many ways can we assign ๐‘› = 5 indistinct children to ๐‘Ÿ = 4 distinct bicycle helmet styles?

59

1. Make objects and dividers distinct0.

Goal Order ๐‘› indistinct objects and ๐‘Ÿ โˆ’ 1 indistinct dividers.

Page 60: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

The divider method: A generative proofHow many ways can we assign ๐‘› = 5 indistinct children to ๐‘Ÿ = 4 distinct bicycle helmet styles?

60

๐‘› + ๐‘Ÿ โˆ’ 1 !

1. Make objects and dividers distinct0.

Goal Order ๐‘› indistinct objects and ๐‘Ÿ โˆ’ 1 indistinct dividers.

1. Order ๐‘› distinct objects and ๐‘Ÿ โˆ’ 1distinct dividers

Page 61: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

The divider method: A generative proofHow many ways can we assign ๐‘› = 5 indistinct children to ๐‘Ÿ = 4 distinct bicycle helmet styles?

61

๐‘› + ๐‘Ÿ โˆ’ 1 !

2. Make ๐‘› objects indistinct

1. Make objects and dividers distinct0.

Goal Order ๐‘› indistinct objects and ๐‘Ÿ โˆ’ 1 indistinct dividers.

1. Order ๐‘› distinct objects and ๐‘Ÿ โˆ’ 1distinct dividers 1

๐‘›!

Page 62: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

The divider method: A generative proofHow many ways can we assign ๐‘› = 5 indistinct children to ๐‘Ÿ = 4 distinct bicycle helmet styles?

62

2. Make ๐‘› objects indistinct

1๐‘›!

1๐‘Ÿ โˆ’ 1 !

Goal Order ๐‘› indistinct objects and ๐‘Ÿ โˆ’ 1 indistinct dividers.

3. Make ๐‘Ÿ โˆ’ 1 dividers indistinct

๐‘› + ๐‘Ÿ โˆ’ 1 !

1. Order ๐‘› distinct objects and ๐‘Ÿ โˆ’ 1distinct dividers

1. Make objects and dividers distinct0.

Page 63: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

The divider method

The number of ways to distribute ๐‘› indistinct objects into ๐‘Ÿ buckets is equivalent to the number of ways to permute ๐‘› + ๐‘Ÿ โˆ’ 1 objects such that

๐‘› are indistinct objects, and๐‘Ÿ โˆ’ 1 are indistinct dividers:

63

Total = (๐‘› + ๐‘Ÿ โˆ’ 1)! ร—&!!

ร—&

("& !

๐‘› + ๐‘Ÿ โˆ’ 1๐‘Ÿ โˆ’ 1

= outcomes

Page 64: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Positive integer equations can be solved with the divider method.

Integer solutions to equationsHow many integer solutions are there to the following equation:

๐‘ฅ! + ๐‘ฅ" +โ‹ฏ+ ๐‘ฅ# = ๐‘›,

where for all ๐‘–, ๐‘ฅ& is an integer such that 0 โ‰ค ๐‘ฅ& โ‰ค ๐‘›?

64

๐‘› + ๐‘Ÿ โˆ’ 1๐‘Ÿ โˆ’ 1

Divider method(๐‘› indistinct objects, ๐‘Ÿ buckets)

Page 65: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Lecture withBreakout Rooms for working through lecture exercises

โ—ฆ We may incorporate some of these during lectureโ—ฆ You are always welcome to exit breakout rooms if you are more comfortable staying in the main room

65

Page 66: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Breakout Rooms

Introduce yourself!

Then check out the three questions on the next slide (Slide 67).Post any clarifications here:https://us.edstem.org/courses/2678/discussion/124109

Breakout Room time: 5 minutes

Weโ€™ll then all come back as a big group to go over our approach.

66

๐Ÿค”

Page 67: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

You have $10 million to invest in 4 companies (in $1 million increments).1. How many ways can you fully allocate your $10 million?2. What if you want to invest at least $3 million in company 1?3. What if you donโ€™t have to invest all your money?

67

Venture capitalists ๐‘› + ๐‘Ÿ โˆ’ 1๐‘Ÿ โˆ’ 1

Divider method(๐‘› indistinct objects, ๐‘Ÿ buckets)

๐Ÿค”

Page 68: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

You have $10 million to invest in 4 companies (in $1 million increments).1. How many ways can you fully allocate your $10 million?

68

Venture capitalists. #1 ๐‘› + ๐‘Ÿ โˆ’ 1๐‘Ÿ โˆ’ 1

Divider method(๐‘› indistinct objects, ๐‘Ÿ buckets)

Set up

๐‘ฅ+: amount invested in company ๐‘–๐‘ฅ+ โ‰ฅ 0

๐‘ฅ! + ๐‘ฅ" + ๐‘ฅ/ + ๐‘ฅ0 = 10Solve

Page 69: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

You have $10 million to invest in 4 companies (in $1 million increments).1. How many ways can you fully allocate your $10 million?2. What if you want to invest at least $3 million in company 1?

69

Venture capitalists. #2 ๐‘› + ๐‘Ÿ โˆ’ 1๐‘Ÿ โˆ’ 1

Divider method(๐‘› indistinct objects, ๐‘Ÿ buckets)

Set up

๐‘ฅ+: amount invested in company ๐‘–

๐‘ฅ! + ๐‘ฅ" + ๐‘ฅ/ + ๐‘ฅ0 = 10Solve

Page 70: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

You have $10 million to invest in 4 companies (in $1 million increments).1. How many ways can you fully allocate your $10 million?2. What if you want to invest at least $3 million in company 1?3. What if you donโ€™t have to invest all your money?

70

Venture capitalists. #3 ๐‘› + ๐‘Ÿ โˆ’ 1๐‘Ÿ โˆ’ 1

Divider method(๐‘› indistinct objects, ๐‘Ÿ buckets)

Set up

๐‘ฅ+: amount invested in company ๐‘–๐‘ฅ+ โ‰ฅ 0

๐‘ฅ! + ๐‘ฅ" + ๐‘ฅ/ + ๐‘ฅ0 โ‰ค 10โš  Solve

Page 71: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

Summary of Combinatorics

71

Counting tasks on ๐‘› objects

Sort objects(permutations)

Choose ๐‘˜ objects(combinations)

Put objects in ๐‘Ÿbuckets

Distinct(distinguishable)

Somedistinct Distinct Indistinct

Distinct

1 group ๐‘Ÿ groups

โ€ข Determine if objects are distinctโ€ข Use Product Rule if several steps โ€ข Use Inclusion-Exclusion if different cases

Page 72: 02: Combinatorics - Stanford Universityโ‚ฌยฆย ยท are the same (indistinguishable or indistinct), and ๐‘›2 are the same, and โ€ฆ ๐‘›๐‘Ÿ are the same, The number of unique orderings

Lisa Yan and Jerry Cain, CS109, 2020

See you next timeโ€ฆ

72