= Count the object using the product n 1 n 2 n 3 . . . n k EE - - PowerPoint PPT Presentation

count the object using the product n 1 n 2 n 3 n k ee 90
SMART_READER_LITE
LIVE PREVIEW

= Count the object using the product n 1 n 2 n 3 . . . n k EE - - PowerPoint PPT Presentation

Goals: Probability CS 70 Tips The probability section in CS 70 usually means: I Lets you quantify uncertainty I One big topic , rather than many small topics I Concretely: has applications everywhere! I Try your best to stay up to date ; use


slide-1
SLIDE 1

Counting, Part I

CS 70, Summer 2019 Lecture 13, 7/16/19

1 / 29

Goals: Probability

I Lets you quantify uncertainty I Concretely: has applications everywhere! I Hopefully: learn techniques for reasoning about randomness and making better decisions logically I Hopefully: provides a new perspective on the world

2 / 29

CS 70 Tips

The probability section in CS 70 usually means: I One big topic, rather than many small topics

I Try your best to stay up to date; use OH! I Important to be comfortable with the basics

I Fewer “proofs,” more computations

I Emphasis on applying tools and problem solving I Lectures will be example-driven

I Practice, practice, practice!

3 / 29

A Familiar Question

How many bit (0 or 1) strings are there of length 3?

4 / 29

3

choices

bit

tf

  • ¥

¥

Choices, Choices, Choices...

A lunch special lets you choose one appetizer, one entre´ e, and

  • ne drink. There are 6 appetizers, 3 entre´

es, and 5 drinks. How many different meals could you possibly get?

5 / 29

App

Ent Drink

¥÷

.

90

The First Rule of Counting: Products

If the object you are counting: I Comes from making k choices I Has n1 options for the first choice I Has n2 options for second, regardless of the first I Has n3 options for the third, regardless of the first two I ...and so on, until the k-th choice = ⇒ Count the object using the product n1 × n2 × n3 × . . . × nk

6 / 29

EE

slide-2
SLIDE 2

Anagramming I

How many strings can we make by rearranging “CS70”? How many strings can we make by rearranging “ILOVECS70” if the numbers “70” must appear together in that order?

7 / 29

4×3×2×1=24

character

:

T

  • #

# 2 # 3 # 4

=

non

  • 17cm -27
  • 2-1
. . .

O

pretend 't 's

1

letter

.

characters

:
  • 8×-71
  • I
  • 8 !
  • Counting Functions

How many functions are there from {1, . . . , n} to {1, . . . , m}? Same setup, but m ≥ n. How many injective functions are there?

8 / 29

'

⇐ix.

÷

:

" . .

'

in

f ( N)

= MN

¥

'

m

"

( M

  • ND

!

Counting Polynomials

How many degree d polynomials are there modulo p? If d ≤ p, how many have no repeating coefficients?

9 / 29

Exactly

Pia '¥

. . .

=p

  • Dpd

÷

Exercise

.

When Order Doesn’t Matter: Space Team I

Among its 10 trainees, NASA wants to choose 3 to go to the

  • moon. How many ways can they do this?
10 / 29 =

lot

7 !

10

x

9

×

8=720

people

It

¥ ¥3

ABC ACB BAC }

6

retorting

  • ffs,z ,

7261=120

EEE

  • =3 !

Yt

CBA

When Order Doesn’t Matter: Poker I

In poker, each player is dealt 5 cards. A standard deck (no jokers) has 52 cards. How many different hands could you get?

11 / 29

O

52

51

SO 49

48=51

cards

  • 47 !

repetitions

¥93

!?¥}s

!

se

47 ! 5 !

The Second Rule of Counting: Repetitions

Say we use the First Rule–we make k choices. I Let A be the set of ordered objects. I Let B be the set of unordered objects. If there is an “m-to-1” function from A to B: = ⇒ Count A and divide by m to get |B|.

12 / 29
slide-3
SLIDE 3

Anagramming II

How many strings can we make by rearranging “APPLE”? How many strings can we make by rearranging “BANANA”?

13 / 29 12

A

= { anagrams
  • f

AP

, Pa

LE }

.

5 ! M

:

ftp.kp.EE

> APPLE M

  • -2

(B)

Hmt

  • -521=60
. I 1 2 23

IAI

  • 6 !

M

:

N 's

:

2 !

A 's :3 !

Total

:

243 !

IBI

⇒ tAmt=2÷ .

Binomial Coefficients

How many ways can we... I pick a set of 2 items out of n total? I pick a set of 3 items out of n total? I pick a set of k items out of n total?

14 / 29

I #

  • D

m

:

a

reps

.

J

cnn.IM?N-InDxIn-2

)

3 !

reps

y

ni

th

  • 3) ! 3 !

Mt

( n

  • K) ! K !

Binomial Coefficients

We often use n k

  • =

n! k!(n − k)! to represent the number of ways to choose k out of n items when

  • rder doesn’t matter.

We call this quantity “n choose k”. We also sometimes refer to these as “binomial coefficients.” Q: Using this definition, what does 0! equal?

15 / 29

Binomial Coefficients

Using this definition, what does 0! equal? Should we be surprised that n

k

  • =

n

n−k

  • ?
16 / 29
  • ( not 't

n?

=
  • h
.

'

aO

n ! n !

  • k ! ( n
  • K)!
  • In
  • K)! K !

T

in

  • k

members

ways

  • f

choosing

NOT

ON

K members For

team my

team !

Anagramming III

How many bit strings can we make by k 1’s and (n − k) 0’s?

17 / 29

1,12

. . . IKO , Oz . . . On
  • K
  • K

n

  • K

with

  • rdering
:

n !

Repetitions

:

I 's

:

k !

O 's

:

( n

  • k) !

> k ! ( n

  • K) !

⇒ Yin

  • Ik)

Coincidence?

Is there a relationship between:

  • 1. Length n bit strings with k 1’s, and
  • 2. Ways of choosing k items from n when order doesn’t matter?

Yes!

18 / 29 an
  • K

O'S

NO !! N

  • .
  • K

X 's

O

X

O

X

X n

  • K
O 's

bijection

b/w

xlo

strings

t

k

  • item

in

sets

2/0

slide-4
SLIDE 4

Putting It All Together: Space Team II

Among its 10 trainees, NASA wants to choose 3 to go to the moon, and 2 to go to Mars. They also don’t want anyone to do both missions. How many ways can they choose teams? If one member of the moon mission is designated as a captain, how many ways can they choose teams?

19 / 29

Ii

er

E) 6

"

Tars

Eoin Putting It All Together: Poker II

How many 5-card poker hands form a full house (triple + pair)? How many 5-card poker hands form a straight (consecutive cards), including straight flushes (same suit)? How many 5-card poker hands form two pairs?

20 / 29

④ Exercise

Sampling Without Replacement

How many ways can we sample k items out of n items, without replacement, if: I Order matters? I Order does not matter? We were able to use the First and Second rules of counting!

21 / 29

NIN

  • 1) Hn
  • 2) r

In

  • ktl )
  • =

Is

  • in
  • K) !

items

  • K

( YL)

( second

rule

  • f

counting) k !

  • rderings

per

set

.

Sampling With Replacement

How many ways can we sample k items out of n total items, with replacement, if: I Order matters? I Order does not matter? What can we do when order does not matter?

22 / 29

items

  • N×N_

X

. . .

I

  • _ Mk
  • K

Label items

I

, . . . ,N .

111

. . .

I

{ I

,

I

, . . . , I }

?

{ 1,1

, . . . ,24

Ek

repetitions

When Repetitions Aren’t Uniform: Splitting Money

Alice, Bob, and Charlie want to split $6 amongst themselves. First (naive and difficult) attempt: the “dollar’s point of view”

23 / 29

O

¥3

  • 3×3-+3×-3=36

Dollar

  • rderndoesnt#ter

because dollars

are indistinguishable

.

ABAAAAA#

Iufagyet

Ai ice b

AAAAA

7.

BA

AAA }

b

Yoaysget

9%5 I

④ CANNOT

Use

2nd

rule

!

When Repetitions Aren’t Uniform: Splitting Money

Second attempt: the “divider” point of view

24 / 29
  • ,

¥ffBob#azµ

,

6

  • 's

00→⑧A08⑧#z

pg

  • os.o.EE#80zNsswpfiiYhng$6

⇒ rearranging

qq.to#ARSANBARSf(8T)=&2.

slide-5
SLIDE 5

“Stars and Bars” Application: Sums to k

How many ways can we choose n (not necessarily distinct) non-negative numbers that sum to k? Food for thought: What if the numbers have to be positive?

25 / 29

negative

xi

set

.

"

with

replace

"
  • incest

f :p

. .

TINI

's

  • Yn
  • ites

!

@

integers

k!

Xi

Xz Xs

. . .

Xn

to

  • ,
  • of .co/.of.oofFYnBo' §

"

"

Isao

.

¥¥÷:

Summary

I k choices, always the same number of options at choice i regardless of previous outcome = ⇒ First Rule I Order doesn’t matter; same number of repetitions for each desired outcome = ⇒ Second Rule I Indistinguishable items split among a fixed number of different buckets = ⇒ Stars and Bars

26 / 29

Pick Your Strategy I

You have 12 distinct cards and 3 people. How many ways to: I Deal to the 3 people in sequence (4 cards each), and the

  • rder they received the cards matters?

I Deal to the 3 people in sequence (4 cards each), but order doesn’t matter?

27 / 29

Pick Your Strategy II

You have 12 distinct cards and 3 people. How many ways to: I Deal 3 piles in sequence (4 cards each), and don’t distinguish the piles? I The cards are now indistinguishable. How many ways to deal so that each person receives at least 2 cards?

28 / 29

Pick Your Strategy III

There are n citizens on 5 different committees. Say n > 15, and that each citizen is on at most 1 committee. How many ways to: I Assign a leader to each committee, then distribute all n − 5 remaining citizens in any way? I Assign a captain and two members to each committee?

29 / 29