4
8/30/12 1 1 2 CS202 Fall 2012 Lecture 1 – 8/28 Combinatorics: Counting Prof. Tanya Berger-Wolf http://www.cs.uic.edu/bin/view/CS202/WebHome Announcements Review sessions will be on Thursday Sept 6, 4:30-5:30 in 1000 SEO This class lectures will now be captured and the video will be available on Blackboard and iTunes (links for Podcast and Vodcast on class webpage) All Microsoft products offered through WebStore under the new UIC Campus Microsoft Agreement at no charge to UIC faculty, staff, students, and departments Undergraduate scholarships in Electronic Security and Privacy 3 Announcements Baltimore, MD, October 3-6, 2012 Scholarships available 4

8/30/12 CS202 Fall 2012 Lecture 1 – 8/28 Combinatorics ... · 1 1 2 CS202 Fall 2012 Lecture 1 – 8/28 Combinatorics: Counting Prof. Tanya Berger-Wolf Announcements

  • Upload
    doannga

  • View
    222

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 8/30/12 CS202 Fall 2012 Lecture 1 – 8/28 Combinatorics ... · 1 1 2 CS202 Fall 2012 Lecture 1 – 8/28 Combinatorics: Counting Prof. Tanya Berger-Wolf  Announcements

8/30/12

1

1 2

CS202 Fall 2012 Lecture 1 – 8/28

Combinatorics: Counting

Prof. Tanya Berger-Wolf http://www.cs.uic.edu/bin/view/CS202/WebHome

Announcements

•  Review sessions will be on Thursday Sept 6, 4:30-5:30 in 1000 SEO

•  This class lectures will now be captured and the video will be available on Blackboard and iTunes (links for Podcast and Vodcast on class webpage)

•  All Microsoft products offered through WebStore under the new UIC Campus Microsoft Agreement at no charge to UIC faculty, staff, students, and departments

•  Undergraduate scholarships in Electronic Security and Privacy

3

Announcements

Baltimore, MD, October 3-6, 2012 Scholarships available

4

Page 2: 8/30/12 CS202 Fall 2012 Lecture 1 – 8/28 Combinatorics ... · 1 1 2 CS202 Fall 2012 Lecture 1 – 8/28 Combinatorics: Counting Prof. Tanya Berger-Wolf  Announcements

8/30/12

2

for i = n to 1 do say “ i little monkeys jumping on the bed

One fell off and bumped his head So Momma called the doctor and the doctor said No more monkeys jumping on the bed!

In my CompPopBio lab there are 128 processors. The probability of a CPU processor failing within a year is about 0.0003.

• Should I expect any processors to fail this year?

• How many processors would I have to have to almost guarantee an annual failure?

6

Lets start counting

• How many integers are there from 5 to 12? 5, 6, 7, 8, 9, 10, 11, 12

8

n-m+1

m = 100, n = 999, so 900

• How many integers are there from m to n? m, m+1, m+2, m+3, ..., n=(m+(n-m))

• How many three-digit integers are there?

• How many three-digit integers are divisible by 5? 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, …, 994, 995, 996, 997, 998, 999 5*20 5*21 5*22 5*199

m = 20, n = 199, so 180

• Let A[0] A[1] …A[m] … A[n-1] be an array which is cut in the middle at A[m]. How many elements in each half? How many indices are there in the first half?

PossibilitiesTree Suppose you have 4 shirts, 3 pairs of pants, and 2 pairs of shoes.

How many different outfits do you have?

Possibilities Tree

How many different game series are possible between two teams who play until one wins two games in a row or a total of three ?

10

A PT is a good model for a sequence of events. It assists in counting, and can help you see special structure in

the problem.

Page 3: 8/30/12 CS202 Fall 2012 Lecture 1 – 8/28 Combinatorics ... · 1 1 2 CS202 Fall 2012 Lecture 1 – 8/28 Combinatorics: Counting Prof. Tanya Berger-Wolf  Announcements

8/30/12

3

Multiplication Rule

9

If an operation consists of k steps and the 1st step can be done in n1 ways the 2nd step can be done in n2 ways (regardless of step 1) … the kth step can be done in nk ways (regardless of steps 1..k-1)

then the entire operation can be done in n1 x n2 x … x nk=

nii =1

k

Counting!

10

• How many 4 symbol PINs are there with letters, numbers, repetitions allowed, not case sensitive?

• PINs without repetitions?

• Bit strings of length 5?

• Bit strings of length 5 that start and end with the same bit?

• Iterations of a nested loop? For i=1..n For j= 1..m ….

• 10 pages ranked 1st. How many orderings are there of those ten pages?

• Ways the letters of the word COMPUTER can be arranged in a row?

For any non-negative integer n, the number of permuitations of a set with n elements is n!

Permutations of Selected Elements A search engine returns 12 top ranked results but on the mobile interface

only 5 can appear on the first page. How many ways are there to display the results of the first page

a)  60 b)  125

c)  12!/7! d)  512

e)  No clue

A permutation is an ordered arrangement of objects.

The number of permutations of r distinct objects chosen from n distinct objects is denoted P(n,r).

P(n,r) = n! / (n-r)!

12

11

10

9

8

Practice with Permutations

•  What is P(5,2)?

•  How many 4-permutations are there of a set of 7 objects?

•  How many 5-permutations are there of set of 5 objects?

Page 4: 8/30/12 CS202 Fall 2012 Lecture 1 – 8/28 Combinatorics ... · 1 1 2 CS202 Fall 2012 Lecture 1 – 8/28 Combinatorics: Counting Prof. Tanya Berger-Wolf  Announcements

8/30/12

4

Permutations

Suppose your search engine returns Top 10 ranked web pages for the search query “jaguar”. You have 6 top ranked pages for the animal, 8 for the car, and 3 for a sports team.

How many different Top 10 lists can you make?

P(17,10) = 17x16x15x14x13x12x11x10x9x8

Permutations Suppose your search engine returns Top 10 ranked web pages for the search

query “jaguar”. You have 6 top ranked pages for the animal, 8 for the car, and 3 for a sports team.

Now suppose you want to have 4 animal, 4 car, and 2 sports results in the Top 10, in that band order. How many Top 10 lists can you make?

P(6,4) x P(8,4) x P(3,2)

Permutations

P(6,4) x P(8,4) x P(3,2) x 3!

Suppose your search engine returns Top 10 ranked web pages for the search query “jaguar”. You have 6 top ranked pages for the animal, 8 for the car, and 3 for a sports team.

Now suppose you want to have 4 animal, 4 car, and 2 sports results in the Top 10, the order doesn’t matter, but you want the results of the same type to appear together. How many Top 10 lists can you make?

Permutations In how many ways can 5 distinct Martians and 3 distinct Jovians stand in

line, if no two Jovians stand together?

M1 M2 M3 M4 M5

5! X P(6,3)