Counting Rosen 6 th ed., §§5.1-5.3. Sum and Product Rules Let m be the number of ways to do task 1...

27
Counting Counting Rosen 6 th ed., §§5.1-5.3

description

Example of Product Rules A new company with just two employees, Sanchez and Patel, rents a floor of a building with 12 offices. How many ways are there to assign different offices to these two employees? The chairs of an auditorium are to be labeled with a letter and a positive integer not exceeding 100. What is the largest number of chairs that can be labeled differently?

Transcript of Counting Rosen 6 th ed., §§5.1-5.3. Sum and Product Rules Let m be the number of ways to do task 1...

Page 1: Counting Rosen 6 th ed., §§5.1-5.3. Sum and Product Rules Let m be the number of ways to do task 1 and n the number of ways to do task 2 The sum rule:

CountingCounting

Rosen 6th ed., §§5.1-5.3

Page 2: Counting Rosen 6 th ed., §§5.1-5.3. Sum and Product Rules Let m be the number of ways to do task 1 and n the number of ways to do task 2 The sum rule:

Sum and Product RulesSum and Product Rules• Let m be the number of ways to do task 1 and n

the number of ways to do task 2• The sum rule: The task “do either task 1 or task 2,

but not both” can be done in m+n ways.• The product rule: The task “do both task 1 and

task 2” can be done in mn ways.

Page 3: Counting Rosen 6 th ed., §§5.1-5.3. Sum and Product Rules Let m be the number of ways to do task 1 and n the number of ways to do task 2 The sum rule:

Example of Product RulesExample of Product Rules

• A new company with just two employees, Sanchez and Patel, rents a floor of a building with 12 offices. How many ways are there to assign different offices to these two employees?

• The chairs of an auditorium are to be labeled with a letter and a positive integer not exceeding 100. What is the largest number of chairs that can be labeled differently?

Page 4: Counting Rosen 6 th ed., §§5.1-5.3. Sum and Product Rules Let m be the number of ways to do task 1 and n the number of ways to do task 2 The sum rule:

Example of Product Rules Cont.Example of Product Rules Cont.

• There are 32 microcomputers in a computer center. Each microcomputer has 24 ports. How many different ports to a microcomputer in the center are there?

• How many different bit strings of length seven are there?

• How many different subsets of a finite set S of cardinality 10 are there?

Page 5: Counting Rosen 6 th ed., §§5.1-5.3. Sum and Product Rules Let m be the number of ways to do task 1 and n the number of ways to do task 2 The sum rule:

Example of Sum RulesExample of Sum Rules• Suppose that either a member of the mathematics

faculty or a student who is a mathematics major is chosen as a representative to a university committee. How many different choices are there for this representative if there are 37 members of the mathematics faculty and 83 mathematics majors and no one is both a faculty member and a student?

Page 6: Counting Rosen 6 th ed., §§5.1-5.3. Sum and Product Rules Let m be the number of ways to do task 1 and n the number of ways to do task 2 The sum rule:

Example of Sum Rules Cont.Example of Sum Rules Cont.

• A student can choose a computer project from one of the three lists. The three lists contain 23, 15, and 19 possible projects, respectively. No projects is on more than one list. How many possible projects are there to choose from?

Page 7: Counting Rosen 6 th ed., §§5.1-5.3. Sum and Product Rules Let m be the number of ways to do task 1 and n the number of ways to do task 2 The sum rule:

Mixed ExamplesMixed Examples• 어느 서점에서 미술 분야의 책을 50 권 ,

음악분야의 책을 60 권 , 건축 분야의 책을 40 권 소장하고 있다 . 어떤 사람이 이 서점에서 책 한 권을 살 때의 경우의 수는 얼마인가 ?

• 위 서점에서 각 분야별로 한 권씩 세 권의 책을 사고자 할 때의 경우의 수는 얼마인가 ?

Page 8: Counting Rosen 6 th ed., §§5.1-5.3. Sum and Product Rules Let m be the number of ways to do task 1 and n the number of ways to do task 2 The sum rule:

Mixed Examples Cont.Mixed Examples Cont.• 어떤 영어 동아리의 인원은 영문과 학생 5 명 ,

수학과 학생 7 명 , 음악과 학생 2 명 , 간호학과 학생 4 명으로 구성되어 있다 . 새 학기를 맞아 이 동아리의 대표를 선출하려 할 때 대표를 선출할 수 있는 방법의 수는 몇 가지인가 ?

• 8 비트의 이진수 가운데 1111 로 시작하는 이진수는 몇 개 있는가 ?

Page 9: Counting Rosen 6 th ed., §§5.1-5.3. Sum and Product Rules Let m be the number of ways to do task 1 and n the number of ways to do task 2 The sum rule:

Mixed Examples Cont.Mixed Examples Cont.• 메일 서비스를 제공해주는 인터넷 업체 A

사에서는 사용자 ID 로 6~7 개의 글자를 사용할 수 있다 . 각 ID 는 영어 소문자이거나 숫자이고 숫자를 적어도 하나 포함하고 있어야 한다 . 사용할 수 있는 ID 의 갯수는 ?

• 위 문제에서 ID 는 영어 소문자이거나 숫자이고 맨 앞은 숫자일 수 없을 때 , 사용할 수 있는 ID의 개수는 ?

Page 10: Counting Rosen 6 th ed., §§5.1-5.3. Sum and Product Rules Let m be the number of ways to do task 1 and n the number of ways to do task 2 The sum rule:

IP Address Example (p341)IP Address Example (p341)

• Some facts about Internet Protocol vers. 4:– Valid computer addresses are in one of 3 types:

• A class A IP address contains a 7-bit “netid” ≠ 17, and a 24-bit “hostid”

• A class B address has a 14-bit netid and a 16-bit hostid.• A class C addr. Has 21-bit netid and an 8-bit hostid.

– The 3 classes have distinct headers (0, 10, 110)– Hostids that are all 0s or all 1s are not allowed.

• How many valid computer addresses are there?

Page 11: Counting Rosen 6 th ed., §§5.1-5.3. Sum and Product Rules Let m be the number of ways to do task 1 and n the number of ways to do task 2 The sum rule:

IP address solutionIP address solution• (# addrs)

= (# class A) + (# class B) + (# class C)(by sum rule)

• # class A = (# valid netids)·(# valid hostids)(by product rule)

• (# valid class A netids) = 27 − 1 = 127.• (# valid class A hostids) = 224 − 2 = 16,777,214.• Continuing in this fashion we find the answer is:

3,737,091,842 (3.7 billion IP addresses)

Page 12: Counting Rosen 6 th ed., §§5.1-5.3. Sum and Product Rules Let m be the number of ways to do task 1 and n the number of ways to do task 2 The sum rule:

Inclusion-Exclusion PrincipleInclusion-Exclusion Principle

• Suppose that km of the ways of doing task 1 also simultaneously accomplish task 2.

• Then the number of ways to accomplish “Do either task 1 or task 2” is mnk.

• Set theory: If A and B are not disjoint, then |AB|=|A||B||AB|.

Page 13: Counting Rosen 6 th ed., §§5.1-5.3. Sum and Product Rules Let m be the number of ways to do task 1 and n the number of ways to do task 2 The sum rule:

Inclusion/Exclusion ExampleInclusion/Exclusion Example

• 1 로 시작하거나 00 으로 끝나는 8 비트 문자열은 모두 몇 개인가 ?

– 1 로 시작하는 8 비트 문자열 : 맨 앞 비트를 고정하고 나머지 7 개 비트는 0 과 1 중 선택 가능하므로 곱셈 법칙에 의해 27 = 128 개

– 00 으로 끝나는 8 비트 문자열 : 26 = 64 개– 1 로 시작하고 00 으로 끝나는 8 비트 문자열 : 중간의

5 개 비트는 0 과 1 중에 선택 가능하므로 곱셈 법칙에 의해 25 = 32 개

– Answer: 128 + 64 – 32 = 160 개

Page 14: Counting Rosen 6 th ed., §§5.1-5.3. Sum and Product Rules Let m be the number of ways to do task 1 and n the number of ways to do task 2 The sum rule:

Inclusion/Exclusion Example Cont.Inclusion/Exclusion Example Cont.

• 아래와 같은 조건을 만족하는 비밀번호는 모두 몇 개인가 ?

• 조건 :– 2 개의 문자로 구성–각 문자는 알파벳 a-z, 숫자 0-9, 혹은 10

가지 특수 문자 !@#$%^&*() 중 하나–숫자나 특수 문자가 한번 나타나야 함

Page 15: Counting Rosen 6 th ed., §§5.1-5.3. Sum and Product Rules Let m be the number of ways to do task 1 and n the number of ways to do task 2 The sum rule:

Inclusion/Exclusion Example Cont.Inclusion/Exclusion Example Cont.• 비밀번호는 1 번 위치 혹은 2 번 위치에 특수

문자를 포함할 수 있다 . – 하지만 , 이 두 가지 모두에 해당되는 경우가 있다

(These cases overlap, so the principle applies.)• 1 번 위치에 특수 문자가 오는 경우 :

(10+10)·(10+10+26)• 2 번 위치에 특수 문자가 오는 경우 : 20·46• 양쪽 위치에 특수 문자가 오는 경우 : 20·20• 비밀번호의 가지 수 : 920+920−400 = 1,440

Page 16: Counting Rosen 6 th ed., §§5.1-5.3. Sum and Product Rules Let m be the number of ways to do task 1 and n the number of ways to do task 2 The sum rule:

Pigeonhole PrinciplePigeonhole Principle

• If ≥k+1 objects are placed into k boxes, then at least 1 box must contain ≥2 objects.

• A function f from a set with k + 1 or more elements to a set with k elements is not one-to-one function.

Page 17: Counting Rosen 6 th ed., §§5.1-5.3. Sum and Product Rules Let m be the number of ways to do task 1 and n the number of ways to do task 2 The sum rule:

Example of Pigeonhole PrincipleExample of Pigeonhole Principle

• Among any group of 367 people, there must be at least two with the same birthday, because there are only 365 possible birthdays.

• In any group of 27 English words, there must be at least two that begin with the same letter because there are 26 letters in the English alphabet.

Page 18: Counting Rosen 6 th ed., §§5.1-5.3. Sum and Product Rules Let m be the number of ways to do task 1 and n the number of ways to do task 2 The sum rule:

Example Cont.Example Cont.

• There are 101 possible numeric grades (0%-100%) rounded to the nearest integer.

• There are >101 students in this class.• Therefore, there must be at least one

(rounded) grade that will be shared by at least 2 students at the end of the semester.– I.e., the function from students to rounded grades

is not a one-to-one function.

Page 19: Counting Rosen 6 th ed., §§5.1-5.3. Sum and Product Rules Let m be the number of ways to do task 1 and n the number of ways to do task 2 The sum rule:

Example Cont.Example Cont.

• Show that for every integer n there is a multiple of n that has only 0s and 1s in its decimal expansion.

• Solution: n 이 양수라 하고 , n+1 개의 정수 1, 11, 111, 1111, … , 11···1(1 이 n 개인 정수 ) 가 있다고 하자 . 어떤 정수를 n 으로 나누었을 때 가능한 나머지 값은 n 개라는 사실을 생각할 때 , 비둘기 집의 원리에 의해 위 n+1 개의 정수 중 적어도 두 수는 n 으로 나눈 나머지가 같다 . 이 두 수의 차이는 n 으로 나누어 떨어지고 , 0 과 1 로만 표현된다 .

Page 20: Counting Rosen 6 th ed., §§5.1-5.3. Sum and Product Rules Let m be the number of ways to do task 1 and n the number of ways to do task 2 The sum rule:

Example Cont.Example Cont.

• 가로 , 세로 길이가 2 미터인 방안에 5개의 인형을 놓을 때 , ‘ 어떤 두 인형은 n 미터 이내의 거리에 있게 된다’라는 문장이 참이 되는 n 의 최소값은 ?

• Solution: root(2)

Page 21: Counting Rosen 6 th ed., §§5.1-5.3. Sum and Product Rules Let m be the number of ways to do task 1 and n the number of ways to do task 2 The sum rule:

Generalized Pigeonhole PrincipleGeneralized Pigeonhole Principle

• If N objects are placed into k boxes, then at least one box must contain at least N/k objects.

• E.g., there are N=280 students in this class. There are k=52 weeks in the year.– Therefore, there must be at least 1 week during

which at least 280/52= 5.38=6 students in the class have a birthday.

Page 22: Counting Rosen 6 th ed., §§5.1-5.3. Sum and Product Rules Let m be the number of ways to do task 1 and n the number of ways to do task 2 The sum rule:

G.P.P. ExampleG.P.P. Example

• Given: There are 280 students in the class. Without knowing anybody’s birthday, what is the largest value of n for which we can prove that at least n students must have been born in the same month?

• Answer:

280/12 = 23.3 = 24

Page 23: Counting Rosen 6 th ed., §§5.1-5.3. Sum and Product Rules Let m be the number of ways to do task 1 and n the number of ways to do task 2 The sum rule:

G.P.P. Example Cont.G.P.P. Example Cont.

• 이산수학 과목에서 A, B, C, D, F 의 다섯 가지 학점이 있을 때 , 적어도 6 명이 같은 학점을 받도록 하기 위해서는 최소한 몇 명이 있어야 하는가 ?

• Answer: N/5 =6 을 만족하는 최소한의 정수 . 5 · 5 + 1 = 26 (25 명만 있다면 , 다섯 명씩 같은 학점을 받으면 , 6 명이 같은 학점을 받는 경우가 생기지 않는다 .)

Page 24: Counting Rosen 6 th ed., §§5.1-5.3. Sum and Product Rules Let m be the number of ways to do task 1 and n the number of ways to do task 2 The sum rule:

PermutationsPermutations

• A permutation of a set S of objects is a sequence containing each object once.

• An ordered arrangement of r distinct elements of S is called an r-permutation.

• The number of r-permutations of a set with n=|S| elements is P(n,r) = n(n−1)…(n−r+1) = n!/(n−r)!

Page 25: Counting Rosen 6 th ed., §§5.1-5.3. Sum and Product Rules Let m be the number of ways to do task 1 and n the number of ways to do task 2 The sum rule:

Permutation ExamplePermutation Example

• A terrorist has planted an armed nuclear bomb in your city, and it is your job to disable it by cutting wires to the trigger device. There are 10 wires to the device. If you cut exactly the right three wires, in exactly the right order, you will disable the bomb, otherwise it will explode! If the wires all look the same, what are your chances of survival?

P(10,3) = 10·9·8 = 720, so there is a 1 in 720 chance that you’ll survive!

Page 26: Counting Rosen 6 th ed., §§5.1-5.3. Sum and Product Rules Let m be the number of ways to do task 1 and n the number of ways to do task 2 The sum rule:

CombinationsCombinations• An r-combination of elements of a set S is simply a subset

TS with r members, |T|=r.• The number of r-combinations of a set with n=|S|

elements is

• Note that C(n,r) = C(n, n−r)– Because choosing the r members of T is the same thing as

choosing the n−r non-members of T.

)!(!!

!)!/(!

),(),(),(

rnrn

rrnn

rrPrnP

rn

rnC

Page 27: Counting Rosen 6 th ed., §§5.1-5.3. Sum and Product Rules Let m be the number of ways to do task 1 and n the number of ways to do task 2 The sum rule:

Combination ExampleCombination Example

• How many distinct 7-card hands can be drawn from a standard 52-card deck?– The order of cards in a hand doesn’t matter.

• Answer C(52,7) = P(52,7)/P(7,7)= 52·51·50·49·48·47·46 / 7·6·5·4·3·2·1

710 82

17

52·17·10·7·47·46 = 133,784,560