1 cmsc 250 chapter 6, counting and probability. 2 cmsc 250 counting l counting elements in a list:...

32
1 CMSC 250 Chapter 6, Counting and Probability

Upload: alfred-ball

Post on 03-Jan-2016

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 CMSC 250 Chapter 6, Counting and Probability. 2 CMSC 250 Counting l Counting elements in a list: –how many integers in the list from 1 to 10? –how many

1CMSC 250

Chapter 6, Counting and Probability

Page 2: 1 CMSC 250 Chapter 6, Counting and Probability. 2 CMSC 250 Counting l Counting elements in a list: –how many integers in the list from 1 to 10? –how many

2CMSC 250

Counting

Counting elements in a list:

– how many integers in the list from 1 to 10?– how many integers in the list from m to n? (assuming m <= n)

Page 3: 1 CMSC 250 Chapter 6, Counting and Probability. 2 CMSC 250 Counting l Counting elements in a list: –how many integers in the list from 1 to 10? –how many

3CMSC 250

How many in a list divisible by something

How many positive three-digit integers are there?– (this means only the ones that require 3 digits)– 999 – 100 + 1 = 900

How many three-digit integers are divisible by 5?– think about the definition of divisible by

x | y ( k Z)[y = kx] then count the k’s that work 100, 101, 102, 103, 104, 105, 106,…,994, 995, 996, 997, 998, 999

20 5 21 5 … 199 5

– count the integers between 20 and 199– 199 – 20 + 1 = 180

Page 4: 1 CMSC 250 Chapter 6, Counting and Probability. 2 CMSC 250 Counting l Counting elements in a list: –how many integers in the list from 1 to 10? –how many

4CMSC 250

Probability The likelihood of a specific event. Sample space = set of all possible outcomes Event = subset of sample space Equal probability formula:

– given a finite sample space S where all outcomes are equally likely

– select an event E from the sample space S– the probability of event E from sample space S:

)(

)()(

Sn

EnEP

Page 5: 1 CMSC 250 Chapter 6, Counting and Probability. 2 CMSC 250 Counting l Counting elements in a list: –how many integers in the list from 1 to 10? –how many

5CMSC 250

Coins and cards and dice

Two coins– sample space = {(H,H), (H,T), (T,H), (T,T)}

Cards– values: 2,3,4,5,6,7,8,9,10,J,Q,K,A– suits: D(), H(), S(), C()

Dice– sample space

{(1,1),(1,2),(1,3),(1,4),(1,5),(1,6), (2,1),(2,2),(2,3),(2,4),(2,5),(2,6), … (6,1),(6,2),(6,3),(6,4),(6,5),(6,6)}

Page 6: 1 CMSC 250 Chapter 6, Counting and Probability. 2 CMSC 250 Counting l Counting elements in a list: –how many integers in the list from 1 to 10? –how many

6CMSC 250

Multi-level probability

If a coin is tossed once, the probability of head = ½ If it’s tossed 5 times

– the probability of all heads:

– the probability of exactly 4 heads:

This is because the coin tosses are all independent events

52

1

2

1*2

1*2

1*2

1*2

1

52

5

Page 7: 1 CMSC 250 Chapter 6, Counting and Probability. 2 CMSC 250 Counting l Counting elements in a list: –how many integers in the list from 1 to 10? –how many

7CMSC 250

The breakfast problem

Suppose your cereal can be Rice Krispies, cornflakes, Raisin Bran, or Cheerios.

Suppose your drink can be coffee, orange juice, or milk.

How many ways can you have breakfast?

Page 8: 1 CMSC 250 Chapter 6, Counting and Probability. 2 CMSC 250 Counting l Counting elements in a list: –how many integers in the list from 1 to 10? –how many

8CMSC 250

The multiplication rule If the 1st step of an operation can be performed n1 ways

And the 2nd step can be performed n2 ways … And the kth step can be performed nk ways

Then the operation can be performed n1n2 ∙ ∙ ∙ nk ways

Cartesian product n(A)=3, n(B)=2, n(C)=4– n(A B C) = 24– n(A B) = 6– n((A B) C) = 24

Page 9: 1 CMSC 250 Chapter 6, Counting and Probability. 2 CMSC 250 Counting l Counting elements in a list: –how many integers in the list from 1 to 10? –how many

9CMSC 250

Discrete StructuresCMSC 250Lecture 34

April 21, 2008

Page 10: 1 CMSC 250 Chapter 6, Counting and Probability. 2 CMSC 250 Counting l Counting elements in a list: –how many integers in the list from 1 to 10? –how many

10CMSC 250

Using the multiplication rule for selecting a PIN

Number of 4 digit PINs of (0,1,2,.)– with repetition allowed = 4 4 4 4 = 256– with no repetition allowed = 4 3 2 1 = 24

Extra rules :– . (the period) can’t be first or last– 0 can’t be first

• with repetition allowed = 2 4 4 3• without repetition allowed = 2 2 2 1

Page 11: 1 CMSC 250 Chapter 6, Counting and Probability. 2 CMSC 250 Counting l Counting elements in a list: –how many integers in the list from 1 to 10? –how many

11CMSC 250

Probabilities with PINs

Number of 4 digit PINs of {0,1,2,.}– with repetition allowed = 4 4 4 4 = 256– with no repetition allowed = 4 3 2 1 = 24

What is the probability that your 4 digit PIN has no repeated digits?

What is the probability that your 4 digit PIN does have repeated digits?

Probability of the complement of an eventP(E’) = P(Ec) = 1 P(E)

Page 12: 1 CMSC 250 Chapter 6, Counting and Probability. 2 CMSC 250 Counting l Counting elements in a list: –how many integers in the list from 1 to 10? –how many

12CMSC 250

The difference rule formally

If A is a finite set and B A, then

n(A B) = n(A) – n(B)

One application: probability of the complement of an event:

P(E’) = P(Ec) = 1 P(E)

Page 13: 1 CMSC 250 Chapter 6, Counting and Probability. 2 CMSC 250 Counting l Counting elements in a list: –how many integers in the list from 1 to 10? –how many

13CMSC 250

PINs with less specified length-addition rule

Assume a PIN can be of length 2, 3, or 4, using {0,1,2,.} Partition the problem:

– number of length-2 PINs w/rep allowed: 4 4 = 16– number of length-3 PINs w/rep allowed: 4 4 4 = 64– number of length-4 PINs w/rep allowed: 4 4 4 4 = 256

Number of PINs if allowing length 2, 3, or 4 = 336

Page 14: 1 CMSC 250 Chapter 6, Counting and Probability. 2 CMSC 250 Counting l Counting elements in a list: –how many integers in the list from 1 to 10? –how many

14CMSC 250

The addition rule formally

If A1 A2 A3 … Ak = A

and A1, A2 , A3,…,Ak are pairwise disjoint

in other words, if these subsets form a partition of A, then

n(A) = n(A1) + n(A2) + n(A3) + ∙∙∙ + n(Ak)

Page 15: 1 CMSC 250 Chapter 6, Counting and Probability. 2 CMSC 250 Counting l Counting elements in a list: –how many integers in the list from 1 to 10? –how many

15CMSC 250

The inclusion/exclusion rule

If there are two sets:n(A B) = n(A) + n(B)

– n(A B)

If there are three sets:n(A B C) = n(A) + n(B) + n(C) – n(A B) – n(A C) – n(B C)

+ n(A B C)

Page 16: 1 CMSC 250 Chapter 6, Counting and Probability. 2 CMSC 250 Counting l Counting elements in a list: –how many integers in the list from 1 to 10? –how many

16CMSC 250

Discrete StructuresCMSC 250Lecture 35

April 23, 2008

Page 17: 1 CMSC 250 Chapter 6, Counting and Probability. 2 CMSC 250 Counting l Counting elements in a list: –how many integers in the list from 1 to 10? –how many

17CMSC 250

Permutations

Different ways of arranging all n of n objects– in either a line or a circle– without duplication/all items distinguishable– note: order is taken into account

Number of linear permutations of N objects = N!N possible for 1st position (N – 1) for 2nd ∙ ∙ ∙ 1 for last

Number of circular permutations of N objects = (N 1)!Fix one person,

then (N – 1) possible for next position * (N – 2) for 2nd ∙ ∙ ∙ 1 for last

Page 18: 1 CMSC 250 Chapter 6, Counting and Probability. 2 CMSC 250 Counting l Counting elements in a list: –how many integers in the list from 1 to 10? –how many

18CMSC 250

r-permutations If there are n things in a set, and you want to line up

only r of them

Example:Class = {Alice, Bob, Carol, Dan}– select a president and a vice president to represent the class– select a president, vice president, and webmaster

)!(

!),(

rn

nPrnP rn

Page 19: 1 CMSC 250 Chapter 6, Counting and Probability. 2 CMSC 250 Counting l Counting elements in a list: –how many integers in the list from 1 to 10? –how many

19CMSC 250

Combinations

Different ways of selecting objects– counting subsets– without duplication/all items distinguishable– note: order is not taken into account

Examples: suppose {Alice, Bob, Carol, Dan} are on the ballot– select two superdelegates– select three superdelegates

!)!(

!

!

),(),(

rrn

n

r

rnPrnC n

r

),( 0 rnwhereZrn

Page 20: 1 CMSC 250 Chapter 6, Counting and Probability. 2 CMSC 250 Counting l Counting elements in a list: –how many integers in the list from 1 to 10? –how many

20CMSC 250

Permutations but of indistinguishable items Examples:

– Arrangements of the word “baboons”– Assume you have a set of 15 beads:

• 6 green• 4 orange• 3 red • 2 black

select positions of the green ones, then the orange ones, then the red ones, then the black ones (or a different order of selecting their positions would work as well)

!2!3!4!6

!15*** 2

253

94

156

Page 21: 1 CMSC 250 Chapter 6, Counting and Probability. 2 CMSC 250 Counting l Counting elements in a list: –how many integers in the list from 1 to 10? –how many

21CMSC 250

Discrete StructuresCMSC 250Lecture 36

April 25, 2008

Page 22: 1 CMSC 250 Chapter 6, Counting and Probability. 2 CMSC 250 Counting l Counting elements in a list: –how many integers in the list from 1 to 10? –how many

22CMSC 250

Combinations with repetition

{a,b,c,d,e} How many 3-combinations can be made without

repetition? How many 3-combinations can be made with unlimited

repetition allowed?

These are multisets [a,b,c]– not sets {a,b,c}– and not tuples (a,b,c)

How many combinations of 20 a's, b's, and c's can e made with unlimited repetition allowed?

Page 23: 1 CMSC 250 Chapter 6, Counting and Probability. 2 CMSC 250 Counting l Counting elements in a list: –how many integers in the list from 1 to 10? –how many

23CMSC 250

Notice similarities

The number of nonnegative integer solutions of the equation

The number of selections, with repetition, of size r from a collection of size n.

The number of ways r identical objects can be distributed among n distinct containers.

rxxx n 21ni

i Zix 1,0

Page 24: 1 CMSC 250 Chapter 6, Counting and Probability. 2 CMSC 250 Counting l Counting elements in a list: –how many integers in the list from 1 to 10? –how many

24CMSC 250

Choosing r elements out of n elements

order matters order doesn’t matter

repetition

allowed

repetition not allowed

r

r

nnn times

r

rn 1

)!(

!),(

rn

nrnP

!)!(

!

rrn

n

r

n

Page 25: 1 CMSC 250 Chapter 6, Counting and Probability. 2 CMSC 250 Counting l Counting elements in a list: –how many integers in the list from 1 to 10? –how many

25CMSC 250

Probability with combinations

Assume:– there are 32 people in a class– seven will be chosen to get extra homework

What is the probability that you get extra homework?

Number of ways to select the lucky seven Number of ways to select if you get homework P(you get homework)

Page 26: 1 CMSC 250 Chapter 6, Counting and Probability. 2 CMSC 250 Counting l Counting elements in a list: –how many integers in the list from 1 to 10? –how many

26CMSC 250

Tournament play

Team A and Team B compete in a “best of 3” tournament They each have an equal likelihood of winning each game

– Do the leaves add up to 1?– Do they always have to play 3 games?– What's the probability the tournament finishes in 2 games?– Do A and B have an equal chance of winning?

Page 27: 1 CMSC 250 Chapter 6, Counting and Probability. 2 CMSC 250 Counting l Counting elements in a list: –how many integers in the list from 1 to 10? –how many

27CMSC 250

What if A wins 2 of every 3 games? Each line for A must have a 2/3 Each line for B must have a 1/3

– How likely is A to win the tournament?– How likely is B to win the tournament?– What is the probability the tournament finishes in two

games?

Page 28: 1 CMSC 250 Chapter 6, Counting and Probability. 2 CMSC 250 Counting l Counting elements in a list: –how many integers in the list from 1 to 10? –how many

28CMSC 250

Where the multiplication rule doesn’t work

People= {Alice, Bob, Carolyn, Dan} Need to be appointed as president, vice-president, and

treasurer, and nobody can hold more than one office– how many ways can it be done with no restrictions?– how many ways can it be done if Alice doesn’t want to be

president?– how many ways can it be done if Alice doesn’t want to be

president, and only Bob and Dan are willing to be vice-president?

Page 29: 1 CMSC 250 Chapter 6, Counting and Probability. 2 CMSC 250 Counting l Counting elements in a list: –how many integers in the list from 1 to 10? –how many

29CMSC 250

Discrete StructuresCMSC 250Lecture 37

April 28, 2008

Page 30: 1 CMSC 250 Chapter 6, Counting and Probability. 2 CMSC 250 Counting l Counting elements in a list: –how many integers in the list from 1 to 10? –how many

30CMSC 250

Harder examples of selecting representatives

Candidates= {Azar, Barack, Clinton, Dan, Erin, Fred}

1. select two, with no restrictions

2. select two, assuming that Azar and Dan must stay together

3. select three, with no restrictions

4. select three, assuming that Azar and Dan must stay together

5. select three, assuming that Barack and Clinton refuse to serve together

Page 31: 1 CMSC 250 Chapter 6, Counting and Probability. 2 CMSC 250 Counting l Counting elements in a list: –how many integers in the list from 1 to 10? –how many

31CMSC 250

Properties of combinations and their proofs

1nn

nrn

nr

10 n

2

)1(2

nnnn

nnn 1

2

)1(2

nnn

nn 1

Page 32: 1 CMSC 250 Chapter 6, Counting and Probability. 2 CMSC 250 Counting l Counting elements in a list: –how many integers in the list from 1 to 10? –how many

32CMSC 250

The binomial theoremyxyx )(

22222 2))(()( yxyxyxyxyxyxyxyx

3223322223

2223

3322

))(2()()()(

yxyyxxyxyyxxyyxx

yxyxyxyxyxyx

432234

4322332234

322334

464

3333

))(33()()()(

yxyyxyxx

yxyyxyxxyyxyxx

yxyxyyxxyxyxyx

4322344

4

4

3

4

2

4

1

4

0

4)( yxyyxyxxyx

inin

i

n yxi

nyx

0

)(