cs322

31
CS322 Week 9 - Friday

Upload: ashanti

Post on 06-Jan-2016

23 views

Category:

Documents


0 download

DESCRIPTION

Week 9 - Friday. CS322. Last time. What did we talk about last time? Partial orders Total orders Basic probability Event Sample space Monty Hall Multiplication rule. Questions?. Logical warmup. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CS322

CS322Week 9 - Friday

Page 2: CS322

Last time

What did we talk about last time? Partial orders Total orders Basic probability

Event Sample space

Monty Hall Multiplication rule

Page 3: CS322

Questions?

Page 4: CS322

Logical warmup

There are 10 thieves who have just stolen an enormous pile of loot: gold, jewels, solid state drives, and so on

The thieves need to find a way to divide it all equally

Give an algorithm such that each of the 10 thieves believe that he is getting at least 1/10 of the loot

Hint: When you were a kid, how did your mother have you and your brother or sister divide the last piece of cake?

Page 5: CS322

Permutations

Page 6: CS322

Permutations

A permutation of a set of objects is an ordering of the objects in a row

Consider set { a, b, c } Its permutations are:

abc acb cba bac bca cab

If a set has n 1 elements, it has n! permutations

Page 7: CS322

Permutations of letters in a word How many different ways can the letters in

the word "WOMBAT" be permuted? How many different ways can "WOMBAT" be

permuted such that "BA" remains together? What is the probability that, given a random

permutation of "WOMBAT", the "BA" is together?

How many different ways can the letters in "MISSISSIPPI" be permuted?

How many would it be if we don't distinguish between copies of letters?

Page 8: CS322

Permuting around a circle

What if you want to seat 6 people around a circular table?

If you only care about who sits next to whom (rather than who is actually in Seat 1, Seat 2, etc.) how many circular permutations are there?

What about for n people?

Page 9: CS322

Permutations of selected elements

An r-permutation of a set of n element is an ordered selection of r elements from the set

Example: A 2-permutation of {a, b, c} includes: ab ac ba bc ca cb

The number of r-permutations of a set of n elements is P(n,r) = n!/(n – r)!

Page 10: CS322

r-permutation examples

What is P(5,2)? How many 4-permutations are there

in a set of 7 objects? How many different ways can three

of the letters in "BYTES" be written in a row?

Page 11: CS322

Disjoint Sets

Page 12: CS322

Addition rule

If a finite set A equals the union of k distinct mutually disjoint subsets A1, A2, … Ak, then:

N(A) = N(A1) + N(A2) + … + N(Ak)

Page 13: CS322

Addition rule example

How many passwords are there with length 3 or smaller?

Assume that a password is only made up of lower case letters

Passwords with length 3 or smaller fall into 3 disjoint sets Number of passwords with length 1 Number of passwords with length 2 Number of passwords with length 3

Total passwords = 26 + 262 + 263 = 18278

Page 14: CS322

Difference rule

If A is a finite set and B is a subset of A, then

N(A – B) = N(A) – N(B)

Example: Recall that a PIN has 4 digits, each of which is

one of the 26 letters or one of the 10 digits How many PINs contain repeated symbols? What is the probability that a PIN contains a

repeated symbol?

Page 15: CS322

Inclusion/exclusion rule

If A, B, C are any finite sets, then

N(A B) = N(A) + N(B) – N(A B)

And,

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: CS322

Inclusion exclusion example

How many integers from 1 through 1,000 are multiples of 3 or multiples of 5?

How many integers from 1 through 1,000 are neither multiples of 3 nor multiples of 5?

Page 17: CS322

Inclusion exclusion example Consider a survey of 50 students about the

programming languages they know The results are:

30 know Java 18 know C++ 26 know ML 9 known both Java and C++ 16 know both Java and ML 8 know both C++ and ML 47 know at least one of the three

How many students know none of the three? How many students know all three? How many students know Java and C++ but not ML? How many students know Java but neither C++ nor ML?

Page 18: CS322

CombinationsStudent Lecture

Page 19: CS322

Combinations

Page 20: CS322

Subsets of sets

How many different subsets of size r can you take out of a set of n items? Subset of size 3 out of a set of size 5? Subset of size 4 out of a set of size 5? Subset of size 5 out of a set of size 5? Subset of size 1 out of a set of size 5?

This is called an r-combination, written

r

n

Page 21: CS322

Permutations and combinations

In r-permutations, the order matters In r-combinations, the order doesn't Thus, the number of r-combinations

is just the number of r-permutations divided by the possible orderings

)!(!!

!),(

rnrn

rrnP

r

n

Page 22: CS322

Combinations example

How many ways are there to choose 5 people out of a group of 12?

What if two people don't get along? How many 5 person teams can you make from a group of 12 if those two people cannot both be on the team?

Page 23: CS322

Poker examples

How many five-card poker hands contain two pairs?

If a five-card hand is dealt at random from an ordinary deck of cards, what is the probability that the hand contains two pairs?

Page 24: CS322

r-combinations with repetitions

What if you want to take r things out of a set of n things, but you are allowed to have repetitions?

Think of it as putting r things in n categories

Example: n = 5, r = 4

We could represent this as x||xx|x| That's an r x's and n – 1 |'s

1 2 3 4 5

x xx x

Page 25: CS322

r-combinations with repetitions

So, we can think of taking an r-combination with repetitions as choosing r items in a string that is r + n – 1 long and marking those as x's

Consequently, the number of r-combinations with repetitions is

r

nr 1

Page 26: CS322

Example

Let's say you grab a handful of 10 Starbursts

Original Starbursts come in Cherry Lemon Strawberry Orange

How many different handfuls are possible?

How many possible handfuls will contain at least 3 cherry?

Page 27: CS322

Handy dandy guide to counting

This is a quick reminder of all the different ways you can count things:

Order Matters Order Doesn't Matter

Repetition Allowed nk

Repetition Not Allowed P(n,k)

k

nk 1

k

n

Page 28: CS322

Quiz

Page 29: CS322

Upcoming

Page 30: CS322

Next time…

Binomial theorem Probability axioms Expected values

Page 31: CS322

Reminders

Work on Homework 7 Due Friday before midnight!

Keep reading Chapter 9