0% found this document useful (0 votes)
17 views

Week 13

Uploaded by

EZ4REAPZ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Week 13

Uploaded by

EZ4REAPZ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

1/1/2025

Basic Counting Rules


 Recall that an ATM pin is a 4-digit number. How many ATM pins can one select?
 Eight friends meet in a party and all of them shake their hand with each other. How
many “handshakes” does this mean.
 The techniques needed to answer such questions will be introduced in this section.
 The two very basic counting principles are the product rule and the sum rule.
4 – Counting  Many counting problems can be solved with the use of theses rules.
 Whenever a procedure can be visualize as making up of separate tasks, the product
rule is used to find the number of ways the entire procedure can be performed.
 Definition:

DS - Induction, Recursion, and Counting 15 DS - Induction, Recursion, and Counting 16


1/1/2025

Example 1 Example 2
How many distinct 4-digit pins can be set? A new company with just two employees, Ahmed and Bilal, rents a floor of a building
with 12 offices. How many ways are there to assign different offices to these two
employees?

DS - Induction, Recursion, and Counting 17 DS - Induction, Recursion, and Counting 18


1/1/2025

Example 3 – 5 Example 6 – 7
3. The chairs of an auditorium are to be labelled with an upper-case English letter 6. How many different car’s number-plates can be made if each plate contains a
followed by a positive integer not exceeding 100. What is the largest number of chairs sequence of three uppercase English letters followed by three digits (and no sequences
that can be labelled differently? of letters are prohibited, even if they are obscene)?
Solution: The procedure labelling a chair consists of assigning an English letter in 26 Answer: 26 · 26 · 26 · 10 · 10 · 10 = 17, 576, 000 possible number-plates.
ways and the task of assigning a number in 100 ways. 7. How many functions are there from a set with 𝑚 elements to a set with 𝑛 elements?
So the entire procedure can be done in 26 · 100 = 2600 ways. Solution: Note that each element of the codomain can be chosen in n ways and
4. There are 32 microcomputers in a computer centre. Each microcomputer has 24 ports. there are m elements in the domain.
How many different ports to a microcomputer in the centre are there? Hence, by the product rule there are 𝑛 · 𝑛 ⋯ 𝑛 = 𝑛
Answer: 32 · 24 = 768. functions from a set with m elements to one with n elements.
5. How many different bit strings of length eight are there? For example, there are 5 = 125 different functions from a set with three elements to a
Answer: 2 = 256. set with five elements.

DS - Induction, Recursion, and Counting 19 DS - Induction, Recursion, and Counting 20


1/1/2025

Example 8 Example 9
How many one-to-one functions are there from a set with m elements to one with n
elements? What is the value of 𝑘 after the following code, where 𝑛 , 𝑛 , . . . , 𝑛 are positive
integers, has been executed?
Solution: First note that when 𝑚 > 𝑛 there are no one-to-one functions from a set with m
elements to a set with n elements.
When 𝑚 ≤ 𝑛, let the elements in the domain are 𝑎 , 𝑎 , … , 𝑎 .
There are 𝑛 ways to assign a value at 𝑎 .
Because the function is one-to-one, the value of the function at 𝑎 can be picked in 𝑛 − 1
ways (as the value assigned to a1 cannot be assigned again).
In general, the value of the function at 𝑎 can be chosen in 𝑛 − 𝑘 + 1 ways.
By the product rule, there are
𝑛(𝑛 − 1)(𝑛 − 2) · · · (𝑛 − 𝑚 + 1)
one-to-one functions from a set with m elements to one with n elements.
For example, there are 5 · 4 · 3 = 60 one-to-one functions from a set with three elements
to a set with five elements.
DS - Induction, Recursion, and Counting 21 DS - Induction, Recursion, and Counting 22
1/1/2025

Example 10 Sum Rule


Use the product rule to show that the number of different subsets of a finite set 𝐴 is Definition:
2 .?

DS - Induction, Recursion, and Counting 23 DS - Induction, Recursion, and Counting 24


1/1/2025

Example 11 Example 12, 13.


Suppose that either a member of the mathematics faculty or a student (with mathematics 12. A student can choose a computer project from one of three lists. The three lists
major) is chosen as a representative to a university committee. contain 23, 15, and 19 possible projects, respectively. No project is on more than one
list. How many possible projects are there to choose from?
 How many different choices are there for this representative if there are 37 members
of the mathematics faculty and 83 students with mathematics majors and no one is Answer: 23 + 15 + 19 = 57 ways to choose a project.
both a faculty member and a student? 13. What is the value of 𝑘 after the
Solution In this task, there are 37 ways to choose a faculty member and following code, where 𝑛 , 𝑛 , . . . , 𝑛
are positive integers, has been executed?
83 ways to select a student with mathematics major.
Solution: The starting value of k is zero
Both these selections are distinct because no one both a faculty member and a student. and there are m different loops.
By the sum rule it follows that there are In jth loop k is replaced by k + 1 𝑛 -times.
37 + 83 = 120 Therefore, by sum rule, the final value of
possible ways to pick this representative. k is 𝑛 + 𝑛 + · · · + 𝑛 .

DS - Induction, Recursion, and Counting 25 DS - Induction, Recursion, and Counting 26


1/1/2025

Questions from Exercise 6.1 Homework


Q2. An office building contains 27 floors and has 37 offices on each floor. How many offices are in
the building?
Ans. 27 ⋅ 37 = 999 offices
 Exercise 6.1
Q12. How many bit strings are there of length six or less, not counting the empty string?
 Q1 to Q12 + Q17, Q25, Q28, Q29, Q31, Q32, Q33, Q48.
Ans. Apply sum rule: 2 + 2 + 2 + 2 + 2 + 2 + 2 = = 127.
Q17. How many strings of five ASCII characters contain the character @ (“at” sign) at least once?
[Note: There are 128 different ASCII characters].
Ans. Total # of ASCII strings of length 5 MINUS the # of strings not containing @ = 128 − 127
Q26. How many strings of four decimal digits
a) do not contain the same digit twice?
b) end with an even digit?
c) have exactly three digits that are 9s?
Ans. a) 10 ⋅ 9 ⋅ 8 ⋅ 7 = 5040. b) 10 ⋅ 10 ⋅ 10 ⋅ 5 = 5000, c) 4 ⋅ 9 = 36 possible strings

DS - Induction, Recursion, and Counting 27 DS - Induction, Recursion, and Counting 28


1/1/2025

The Pigeonhole Principle Cont. . .


 The Pigeonhole Principle is the simple observation that if you put 𝑛 pigeons into 𝑟
 If there are more pigeons than pigeonholes, then there must be at least one pigeonhole holes, and 𝑛 > 𝑟, then some hole must contain multiple pigeons.
with at least two pigeons in it.  Theorem: (The Pigeonhole Principle) If 𝑘 is a positive integer and 𝑘 + 1 or more
 See Figure for some possibilities when there are 12 pigeonholes and 13 pigeons. objects are placed into 𝑘 boxes, then there is at least one box containing two or more
of the objects.
 We will illustrate the usefulness of the pigeonhole principle. We first show that it can
be used to prove a useful corollary about functions.
 Corollary: A function 𝑓 from a set with 𝑘 + 1 or more elements to a set with 𝑘
elements is not one-to-one.
 Proof: Suppose that for each element 𝑦 in the codomain of 𝑓 we have a box that contains all
elements 𝑥 of the domain of 𝑓 such that 𝑓(𝑥) = 𝑦. Because the domain contains 𝑘 + 1 or more
elements and the codomain contains only 𝑘 elements, the pigeonhole principle tells us that one of
these boxes contains two or more elements 𝑥 of the domain.
 This means that f cannot be one-to-one.

DS - Induction, Recursion, and Counting 29 DS - Induction, Recursion, and Counting 30


1/1/2025

Examples Examples
 Among a group of 367 people (randomly chosen), there must be at least two with the
same birthday, because there are only 366 possible birthdays.  How many students must be in a class to guarantee that at least two students receive
 In any group of 27 English words (randomly chosen), there must be at least two that the same score on the final exam, if the exam is graded on a scale from 0 to 100
begin with the same letter, because there are 26 letters in the English alphabet. points?
 Among a set of 8 or more students, at least 2 are born on the same day of the week.  Ans. 102. (CW)
(Why?)  Show that if there are 30 students in a class, then at least two have last names that
 In a club with 400 members, must there be some pair of members who share the same begin with the same letter. (Q2 Ex. 6.2)
birthday. Why?  Let 𝑑 be a positive integer. Show that among any group of 𝑑 + 1 (not necessarily
 Baber has a drawer full of 12 red and 14 green socks. In order to avoid waking his consecutive) integers there are two with exactly the same remainder when they are
roommate, he must grab a selection of clothes in the dark and get dressed out in the divided by 𝑑. (Q6 Ex. 6.2)
hallway. How many socks must he grab to be assured of having a matching pair?  Show that if five integers are selected from the first eight positive integers, there
Solution: Let 𝑓 ∶ 𝑋 → 𝐶 be the function that assigns a colour to each sock, where must be a pair of these integers with a sum equal to 9. (Q13 Ex. 6.2)
𝐶 = {red, green } and 𝑋 = be the set of socks Baber selects. By pigeonhole principle, 𝑋 > 𝐶 = 2.
Three is enough.
DS - Induction, Recursion, and Counting 31 DS - Induction, Recursion, and Counting 32
1/1/2025

The Generalized Pigeonhole Principle Cont. . . .


 The pigeonhole principle states that there must be at least two objects in the same box
when there are more objects than boxes.  One can replace the required lower-bound 𝑘 + 1 by for the number of pigeons in
 However, even more can be said when the number of objects exceeds a multiple of the some of the hole. Recall that is the ceiling value of .
number of boxes.
 In the above examples, ⌈2.25⌉ = 3 and = 3.1 = 4.
 That is, if 𝑛 pigeons fly into 𝑚 pigeonholes and, for some positive integer 𝑘,
 Example: What is the minimum number of students required in a Discrete Structures
𝑘 < , then at least one pigeonhole contains 𝑘 + 1 or more pigeons.
class to be sure that at least six will receive the same grade, if there are five possible
 As illustrated in the figure for 𝑚 = 4, 𝑛 = 9, and grades, 𝐴, 𝐵, 𝐶, 𝐷, and 𝐹?
𝑘 = 2. Since = = 2.25 and we have 𝑘 = 2 < 2.25,  Solution: Here we need to find n the minimum number of pigeons to place them in 5
at least one pigeonhole contains three (2 + 1) = 3 holes (the number of possible grades).
or more pigeons.  This is to be done in such a way at least 6 are placed in the same hole (receive the same grade).
 Here pigeonhole 3 contains three pigeons.  That is, find n such that ⌈ ⌉ = 6.
Similarly, among any set of 31 decimal digits (0, 1, 2, . . . , 9)  The smallest such integer is n = (6 − 1) · 5 + 1 = 5(5) + 1 = 26.
there must be 4 that are the same.
DS - Induction, Recursion, and Counting 33 DS - Induction, Recursion, and Counting 34
1/1/2025

Homework

 Exercise 6.2
 Q1 to Q6 + Q13, Q15, Q17, Q19.

DS - Induction, Recursion, and Counting 35

You might also like