Lecture 15 Counting.

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 52

Discrete Structures

Counting (Ch. 6)

MUHAMMAD JAFFAR KHAN (MS Electrical Engineering)


MASTER IN COMPUTER SCIENCE-1
FEDERAL URDU UNIVERSITY, ISLAMABAD (Campus).
First Reaction

Counting??
What??
Are we first graders??

3
Counting applications
• Counting has many applications in computer
science and mathematics.
• For example,
 Counting the number of operations used by an
algorithm to study its time complexity
 Counting the successful outcomes of experiments
 Counting all the possible outcomes of experiments
…

4
Combinatorics
Combinatorics: study of arrangement of objects
Enumeration: counting of objects with certain
properties

 to solve a complicated problem:


break it down into smaller problems
piece together solutions to these smaller problems

5
Basic Counting Principles
2
Product Rule
Sum Rule

6
The Product Rule
• Also called the multiplication rule
• If there are n1 ways to do task 1, and n2
ways to do task 2:
– Then there are n1n2 ways to do both tasks in
sequence
– This applies when doing the “procedure” is
made up of separate tasks.
– We must make one choice AND a second
choice

7
EXAMPLE 1
at page# 386
• 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?
• Solution:
• Break the procedure into tasks
 Task 1: Possible ways of allotment of any office to first
employee = 12
 Task 2: Possible ways of allotment of any of the remaining
office to second employee = 11
• (Product Rule) All possible ways of allotment of offices
to two employees = 12 * 11 = 132
8
EXAMPLE 2
at page# 386
• The chairs of an auditorium are to be labeled with an uppercase
English letter followed by a positive integer not exceeding 100. What
is the largest number of chairs that can be labeled differently?

• Solution:
• Break the procedure into tasks:
 assigning to the seat one of the 26 uppercase English letters,
 and then assigning to it one of the 100 possible integers.
• The product rule shows that there are 26 · 100 = 2600 different ways
that a chair can be labeled.

• Therefore, the largest number of chairs that can be labeled


differently is 2600.
9
EXAMPLE 3
at page# 386
• 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?
• Solution:
• Break the procedure into tasks
 first picking a microcomputer and
 then picking a port on this microcomputer.
• Because there are 32 ways to choose the microcomputer
and
• 24 ways to choose the port no matter which
microcomputer has been selected,
• the product rule shows that there are 32 · 24 = 768 ports.
10
Extended version of the product rule
• Extended version of the product rule:
A procedure can be broken down into a sequence of
tasks T1, T2, …, Tm.
Assume each task Ti (i=1,2,…,m), can be done in ni
different ways, regardless of how the previous tasks
were done.
The procedure can be done in n1n2…nm different ways.

(prove it using induction as exercise.)

11
EXAMPLE 4
at page# 386
• How many different bit strings of length seven are there?
• Solution:
• Break the procedure into tasks
 Task 1: assigning bit 1 to 0 or 1
 Task 2: assigning bit 2 to 0 or 1
 …
 Task 7: assigning bit 7 to 0 or 1

 Count different ways of doing each task and then use product rule
 Each task can be done in 2 different ways. because each bit is either
0 or 1.
 By product rule, There are 27= 128 different bit strings of length
seven.
12
EXAMPLE 5
at page# 387
• How many different license plates can be made if each plate contains a sequence of three
uppercase English letters followed by three digits (and no sequences of letters are
prohibited, even if they are obscene)?
• Solution:
• Break the procedure into tasks
 Task 1: choose letter 1
 Task 2: choose letter 2
 Task 3: choose letter 3
 Task 4: choose digit 1
 Task 5: choose digit 2
 Task 6: choose digit 3
• Count different ways of doing each task and then use the product
rule
 By product rule, There are 26 . 26 . 26 .10 .10 . 10 = 17576000 different
license plates.
13
Product Rule Example
• Sample question
– There are 18 math majors and 25 CS majors
– How many ways are there to pick one math
major and one CS major?

• Total is 18 * 25 = 450 possible ways

14
More Examples
• What is the value of k after the following code,
where n1, n2, . . . , nm are +ive integers:

n1* n2* ...* nm

15
The Sum Rule
• Also called the addition rule
• If there are n1 ways to do task 1, and n2 ways to do
task 2
– If these tasks can be done at the same time, then…
– Then there are n1+n2 ways to do one of the two tasks
– We must make first choice OR a second choice

16
Sum Rule Examples
More sample questions
• How many strings of 4 decimal (non-zero)digits…
• Have exactly three digits that are 9s?
– The string can have:
• The non-9 as the first digit
• OR the non-9 as the second digit
• OR the non-9 as the third digit
• OR the non-9 as the fourth digit
• Thus, we use the sum rule
– For each of those cases, there are 9 possibilities for the non-
9 digit (any number other than 9)
– Thus, the answer is 9+9+9+9 = 36

17
Sum Rule Examples
• Sample question
– There are 18 math majors and 25 CS majors
– How many ways are there to pick one math major or
one CS major?

• Total is 18 + 25 = 43

18
• n1 + n 2 + … + n m

19
Example# 12
at Page# 389
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?
Solution:
• There are 37 ways to choose a faculty member.
• There are 83 ways to choose a student.
• By the sum rule, there are 37+83=120 different ways to
choose such a representative.

Exercise Q. 1,3
20
Extended version of the sum rule
• Extended version of the sum rule:
Suppose a task can be done in one of n1 ways, in
one of n2 ways, …, or in one of nm ways.
Assume none of the set of ni ways of doing the task
is the same as any of the set of nj ways, for all pairs I
and j with 1 ≤ i < j ≤ m.
The task can be done in n1+n2+…+nm different ways.

21
Example# 13
at Page# 390
A student can choose a computer project from one
of three lists. The three lists 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?
Solution:
• The student can choose a project from the first list,
the second list or the firs list.
• By the sum rule, there are 23+15+19=57 ways to
choose a project.
22
Misc Examples
There are 18 mathematics majors and 325
computer science majors at a college
• In how many ways can two representatives be
picked so that one is a mathematics major and
the other is a computer science major?
18 . 325
• In how many ways can one representative be
picked who is either a mathematics major or a
computer science major?
18 + 325
23
• A multiple-choice test contains 10 questions. There
are four possible answers for each question.
 In how many ways can a student answer the
questions on the test if the student answers every
question?
 Solution:
4 * 4 * …. * 4 (10 times)= 410
 In how many ways can a student answer the
questions on the test if the student can leave answers
blank?
 Solution:
510 24
The product rule and the sum rule
• Some complicated counting problems can be
solved using both the product rule and the sum
rule.

25
Example# 17
at Page# 391
• On the internet, each computer is assigned an internet address.
 An address is a string of 32 bits. It begins with a network number (netid)
followed by a host number (hostid).
 There are three forms of addresses.
 Class A addresses consists of 0, followed by a 7-bit netid and a 24-bit hostid.
 Class B addresses consists of 10, followed by a 14-bit netid and a 16-bit hostid.
 Class C addresses consists of 110, followed by a 21-bit netid and a 8-bit hostid.
 There are several restrictions:
 1111111 is not available as the netid of a class A network.
 Hostids do not consists of all 0s and all 1s are not available for use in any
network.
• How many different addresses are available for computers on the
Internet.

26
• Task 1: choose a Class A address.
• Task 2: choose a Class B address.
• Task 3: choose a Class C address.
 Since the netid of class A cannot be 1111111, the number of Class
A netids is 27 - 1.
 Since the hostid cannot consist all 0s and all 1s, the number of
Class A hostids is 224 - 2.
• By the product rule, the number of task 1 is (27 - 1)( 224 - 2) =
2,130,706,178.
27
• By the product rule, the number of Class B netids is 2 14.
• Since the hostid cannot consist all 0s and all 1s, the number of
Class B hostids is 216 - 2.
• By the product rule, the number of task 2 is 214 (216 - 2) =
1,073,709,056.
• By the product rule, the number of Class C netids is 2 21.
• Since the hostid cannot consist all 0s and all 1s, the number of
Class C hostids is 28 - 2.
• By the product rule, the number of task 1 is 221 (28 - 2) =
532,676,608.
• By the sum product, the number of Internet addresses are the
number of task 1 + the number of task 2 + the number of task 3
= 3,737,091,842.
28
• A particular brand of shirt comes in 12 colors, has
a male version and a female version, and comes
in three sizes for each gender. How many
different types of this shirt are made?

• Solution:

12 * ( 3 + 3)

29
• A committee is formed consisting of one
representative from each of the 50 states in the
United States, where the representative from a
state is either the governor or one of the two
senators from that state. How many ways are
there to form this committee?
• (1+1+1)50

30
• How many license plates can be made using
either three digits followed by three uppercase
English letters or three uppercase English letters
followed by three digits?

• Solution:
103 * 263 + 263 * 103

31
• How many license plates can be made using
either two uppercase English letters followed by
four digits or two digits followed by four
uppercase English letters?

• Solution:
 262*104 + 102*264

32
Recommended exercises
• 3,7,11,13,15,21,31,38,39,59

33
6.2 What is the Pigeon-Hole Principle?
• The Pigeon-Hole Principle states that if p items (Pigeons) are
put into h pigeonholes with p>h, then at least one pigeonhole
must contain more than one item.

e o n.
ig
n ep
th an o
m o re
in s
c onta
n h ole
ige o
s p
Th i
Example Problem

There are 3 pigeonholes and 4 pigeons


Example Problem

We can evenly distribute a pigeon into each of the


pigeonholes, leaving one pigeon leftover.
Example Problem

The result is that at least one hole has two pigeons


because the number of pigeons is greater than the
number of holes. P>H
Try it on your own!

• There are 25 students in the class. Each


student received an A, B, or C on their
math test. Show that there are at least
nine students who received the same
grade on the test.
Here’s a Hint!

• The students are the pigeons and the


grades are the holes!
A B C

Here is how we se
up the problem. We
have 3 holes, for the
grades, and 25
students.
A B C

We can evenly distribute the


students into each of the holes.
One student is remaining.
A B C

We can show that nine students have the same


grade because number of students is greater
than the number of holes.
Problem Overview
• Since 25 = 3 x 8 + 1, we were able to equally
distribute the students into the letter grades.
With eight students in each letter grade, there
was one student leftover. Therefore, one of the
grades must have nine students with the same
letter grade.
Summary
• Why would teachers use the pigeon-hole
principle to teach students?
– Differentiation for grade levels
– Provides a visual to learn mathematical concepts
– Improves problem solving skills
We hope you are one of those nine students
who will receive an A on your next math
test!!!
Example # 1 and 2
at Page# 400
• Among a group of 367 people (randomly
chosen), there must be at least two with the
same birthday, because there are only 365
possible birthdays.
• In any group of 27 English words (randomly
chosen), there must be at least two that begin
with the same letter, because there are 26 letters
in the English alphabet.
• Among a set of 15 or more students, at least 3
are born on the same day of the week. 46
Example # 3
at Page# 400
How many students must be in a class to guarantee
that at least two students receive the same score
on the final exam, if the exam is graded on a scale
from 0 to 100 points?
Ans:
There are 101 possible scores on the final.
The pigeonhole principle shows that among any
102 students there must be at least 2 students with
the same score.
47
The Generalized Pigeonhole Principle
• Even more can be said when the number of
objects exceeds a multiple of the number of
boxes.
• Example:
Among any set of 21 decimal digits there must be 3
that are the same.
Why? when 21 objects are distributed into 10 boxes,
one box must have more than 2 objects.

48
49
Example# 5, 6
at Page# 401 and 402

50
The Last slide. VIS
• How many numbers must be selected from the
set {1, 2, 3, 4 , 5, 6} to guarantee that at least one
pair of these numbers add up to 7?
• Solution:
Total numbers = 6
Possible ways to add up to 7= (1,6), (2, 5), (3, 4)
We have to select at least 4 numbers, so that at least
one pair from above 3 pairs is selected.

51
Recommended exercises
• 3,5,9,13,21,25,31

52

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy