counting and the pigeonhole principleboerner/mat243/6.1 6.2 counting and the... · the generalized...

16
Counting and the Pigeonhole Principle

Upload: others

Post on 28-Mar-2020

25 views

Category:

Documents


1 download

TRANSCRIPT

Counting and the Pigeonhole Principle

Combinatorics and Counting

Combinatorics is the mathematical discipline that studies arrangements of objects. Determining numbers of arrangements is called counting.

The two foundational principles of counting are the product rule (aka the multiplication principle) and the sum rule. (These are NOT the same product rule and sum rule you may know from calculus.)

The Product Rule

Product Rule: If a procedure consists of carrying out two tasks, and if task 1 can be performed in 𝑛 ways, and if for every way of performing task 1, there are 𝑚 ways of performing task 2, then the procedure can be performed in 𝑛𝑚ways.

Example: you order a pizza and have a choice of 1 out of 3 toppings and 1 out of 4 kinds of cheeses. Each cheese can be combined with any of the toppings. Then you have a choice between 12 different pizzas.

The product rule also works for chains of more than two tasks. In that case, the number of ways of performing the entire procedure is equal to the product of all the numbers of ways to carry out the individual tasks.

For example, there are 𝑚𝑛 many functions from a set of 𝑛 elements to a set of 𝑚 elements because for each of the 𝑛 inputs, there is a choice of 𝑚possible outputs. Thus, the task of selecting such a function can be carried out in 𝑚 ⋅ 𝑚 ⋅ … ⋅ 𝑚

𝑛 factors

= 𝑚𝑛 many ways.

Application of the Product Rule to Counting Phone Numbers

Problem: If a phone number consists of 6 digits, and the first digit can’t be a zero, how many different phone numbers are there?

Solution: there are 9 choices for the first digit. For any choice of the first digit, there are 10 choices for the second digit. For any choice of the second digit, there are 10 choices for the third digit, and so on. Therefore, there are 9 ∙ 105 = 900,000 different phone numbers.

Application of the Product Rule to Counting Binary Logical Operators

A binary logical operator ⋆ is a logical operator that acts on two propositions p,q . It is completely defined by its truth table. Since each of p and q may be independently true or false, the truth table of any binary logical operator must have 4 rows by the product rule. Since the value of 𝑝 ⋆ 𝑞 in each of these rows may also be independently true or false, there are 24 = 16 distinct binary logical operators by the product rule.

Practice: write down the truth tables of all 16 binary logical operators and identify the named ones. Express the rest of them using named logical operators.

p q 𝑝 ⋆ 𝑞

T T

T F

F T

F F

The Sum Rule

If a task can be performed in 𝑛 ways of one type, or 𝑚 ways of a different type, and if these two types are mutually exclusive, then the task can be performed in 𝑛 +𝑚 ways.

Example: you have a choice of one extra topping for a pizza. The choices are 5 kinds of extra cheese and 8 kinds of vegetables. Again, you may not choose one of each, just one. Then there are 8 + 5 = 13ways of choosing the topping.

Application of the Product and Sum Rules to Passwords

Sometimes, we need to use both product and sum rules to solve a counting problem.

Problem: If a password must consists of 20 characters (upper or lowercase letters of the English alphabet, or digits (0-9), or any of 7 permitted special characters), how many different passwords are there?

Solution: by the sum rule, there are 26 + 26 + 10 + 7 = 69 choices for each character. By the product rule, there are

6920 = 5983865382382622672294674517005559601

≈ 6 ∙ 1036 many different passwords.

(If an attacker could attempt one trillion or 1012 passwords per second, it would take her 1036 divided by 1012, or 1024 seconds. This is over two million times the known age of the universe of roughly 14 billion years.)

Counting 1-1 and Onto Functions (1)We can use the multiplication principle to count the number of injective functions 𝑓from a set of 𝑛 elements 𝑆 = 𝑥1, 𝑥2, … , 𝑥𝑛 to another set of 𝑛 elements 𝑇 =𝑦1, 𝑦2, … , 𝑦𝑛 .

Designing such a function 𝑓 means picking the outputs 𝑓(𝑥1), 𝑓(𝑥2), …, 𝑓(𝑥𝑛). For 𝑓(𝑥1), we are free to choose any of the elements in 𝑇, so there are 𝑛 choices. Once 𝑓(𝑥1) has been chosen, it can’t be used as another output since the function is supposed to be 1-1. Therefore, there are only 𝑛 − 1 choices for 𝑓(𝑥2), then only 𝑛 −2 choices for 𝑓(𝑥3), and so on. Therefore, by the product rule, the total number of injective functions from 𝑆 to 𝑇 is 𝑛 ∙ 𝑛 − 1 ∙ 𝑛 − 2 ∙ ⋯ ∙ 2 ∙ 1. You may already know that this quantity is known as “𝑛 factorial” and written 𝑛!.

Example: you and your two friends are playing an MMO. You always play in a party of 3, with exactly one of each: tank (T), damage dealer (DD) and healer (H). The game lets you switch character classes, so to keep things interesting, you want to switch roles as much as possible. How many unique role distributions can you have?

The question asks how many injective functions from the set {you, your friend, your other friend} to the set {T, DD, H} there are. There are 3! = 6 such functions. Therefore, there are 6 unique party setups.

Observe that an injective function from a set of 𝑛 elements to another set of 𝑛elements is automatically surjective, and vice versa. There is only one way of picking 𝑛unique outputs from 𝑛 possible outputs, and that’s to pick all of them. Therefore, there are also 𝑛! onto functions, and 𝑛! bijections from 𝑆 to 𝑇.

Counting 1-1 and Onto Functions (2)

The situation is more complicated when domain and codomain have different cardinalities. Suppose we wish to count injective functions 𝑓 from a set of 𝑛elements 𝑆 = 𝑥1, 𝑥2, … , 𝑥𝑛 to a set of 𝑚 elements 𝑇 = 𝑦1, 𝑦2, … , 𝑦𝑚 .

If 𝑚 < 𝑛, then there are no such functions. You can’t pick 𝑛 unique outputs from 𝑇 when 𝑇 does not have this many elements in the first place.

We already covered the case 𝑚 = 𝑛: there are 𝑛! injective functions in this case, and all of them are in fact bijective.

If 𝑚 > 𝑛, then there are 𝑚 choices for 𝑓(𝑥1), then 𝑚 − 1 choices for 𝑓(𝑥2),etc, and still 𝑚− 𝑛 + 1 choices for 𝑓(𝑥𝑛). Thus, there are

𝑚 ⋅ 𝑚 − 1 ⋅ … ⋅ 𝑚 − 𝑛 + 1 =𝑚!

𝑚 − 𝑛 !

such functions. In Permutations and Combinations, we will identify this quantity as 𝑃 𝑚, 𝑛 , the number of ordered selections, or permutations, of 𝑛elements from 𝑚 elements.

Counting 1-1 and Onto Functions (3)

Let us now count surjective functions 𝑓 from a set of 𝑛 elements 𝑆 =𝑥1, 𝑥2, … , 𝑥𝑛 to a set of 𝑚 elements 𝑇 = 𝑦1, 𝑦2, … , 𝑦𝑚 . To count these, we

need to reverse our point of view. Rather than going through the inputs and determining in how many ways we can choose corresponding outputs, we need to go through the outputs, and count..

Suppose 𝑚 < 𝑛. The output 𝑦1 could have come from 𝑛 different inputs. The output 𝑦2 could have come from 𝑛 − 1 different inputs, etc. The output 𝑦𝑚could have come from 𝑛 −𝑚 + 1 different inputs. Therefore, there are

𝑛 ⋅ 𝑛 − 1 ⋅ … ⋅ 𝑛 − 𝑚 + 1 =𝑛!

𝑛 − 𝑚 != 𝑃(𝑛,𝑚)

different surjective functions from 𝑆 to 𝑇.

We have already covered the case 𝑚 = 𝑛.

If 𝑚 > 𝑛, then there are no surjective functions from 𝑆 to 𝑇. It is not possible to hit all 𝑚 elements of the codomain with only 𝑛 inputs.

Observe that this investigation confirms something we could have known in the first place: if 𝑚 ≠ 𝑛, there is no bijection possible from 𝑆 to 𝑇.

The Pigeonhole Principle

The Pigeonhole principle: if there are 𝑛 boxes, and you need to reach into these boxes 𝑛 + 1 times, then you need to reach into at least one of the boxes twice.

The Pigeonhole principle can be proved by contradiction: what if you could reach into the boxes 𝑛 + 1 times without repeating a box? Since there are only 𝑛 boxes, and you can reach into each box at most once, you reached at most 𝑛 times into a box. That is a contradiction.

Simple Applications of the Pigeonhole Principle

If you have 367 people in a room, two must have the same birthday.

If you have 51 people in a room who were born in one of the 50 states of the United States, then two must have been born in the same state.

If the choices in an election were the conservative party and the liberal party, then whenever you have 3 voters in a room, 2 of them must have voted for the same party.

Combining the Pigeonhole Principle with the Product Rule

In a medical survey, respondents were asked for• Their age group (18-30, 31-49, 50+)• Their income ( below or at least 50k per year)• Whether they exercise regularly (yes/no)

What number of people surveyed would guarantee that two people surveyed have all matching answers to these questions?

Solution: there are 3 choices for the age group, 2 for income and 2 for exercising. By the product rule, there are 12 ways of answering this survey. Therefore, if 13 or more people were surveyed, it is guaranteed that two will have all matching answers.

An advanced application of the Pigeonhole Principle

Sometimes, it is not so obvious what the “boxes” should be in an application of the Pigeonhole principle. The following is an example of that.

What size subset of 1,2,3,4,5,6 will guarantee that two of its elements add up to 7?

We can only get 7 as 1+6, 2+5, 3+4. These three groups of two numbers are the boxes. Therefore, if we select 4 unique numbers, we will have to reach into one of the three boxes twice, and therefore obtain a pair that adds up to 7.

The Generalized Pigeonhole Principle

Let us illustrate a generalization of the Pigeonhole principle with an example first. If there are 10 drawers, and you reach into these drawers 21 times, then you must have reached into at least one of them at least 3 times.

The Generalized Pigeonhole principle: if there are 𝑛 boxes and you reach into these boxes 𝑛𝑚 + 1 times, then you need to reach into at least one of the boxes 𝑚 + 1 times.

Once again, we prove this by contradiction: what if you could reach into the boxes 𝑛𝑚 + 1 times and only reach into each box at most 𝑚 times? Since there are only 𝑛 boxes, then you reached in at most 𝑛𝑚 times, which is less than 𝑛𝑚 + 1. That’s a contradiction.

Application of the Generalized Pigeonhole Principle

If you have 15 people in a room, 3 must have been born on the same day of the week.The same conclusion would hold if we had 16, 17, 18, 19, 20 or 21 people in a room. Only at 22 people do we reach the threshold for a stronger conclusion:If you have 22 people in a room, 4 must have been born on the same day of the week.

This observation gives rise to the following slightly more powerful version of the Generalized Pigeonhole principle:

If there are 𝑛 boxes and you reach into these boxes 𝑚 times, then you need to reach into at least one of the boxes

𝑚

𝑛times.

In the day of the week example above, the boxes are days of the week, so 𝑛 =7, and 𝑚 = 15,16,17, … , 22.