0% found this document useful (0 votes)
38 views192 pages

Final

Uploaded by

k230611
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)
38 views192 pages

Final

Uploaded by

k230611
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/ 192

Proofs

 A proof is a valid argument that establishes the truth


of a mathematical statement.

 Ingredients:
 hypotheses of the theorem
 axioms assumed to be true
You get:
 previously proven theorems
 rules of inference
truth of the
statement
being proved
Usefulness
 Computer Science
 Verifying that computer programs are correct.
 Establishing that operating systems are secure.
 Making inferences in artificial intelligence.
 Showing that system specifications are consistent.

 Mathematics
 Defining Formalism.
 Providing specification in a common language.
 Justification for the results.
Definitions
1. An integer n is even if, and only if, n = 2k for some integer k.
2. An integer n is odd if, and only if, n = 2k + 1 for some integer k.
3. An integer n is prime if, and only if, n > 1 and for all positive integers
r and s, if n = r·s, then r = 1 or s = 1.
4. An integer n > 1 is composite if, and only if, n = r·s for some positive
integers r and s with r ≠ 1 and s ≠ 1.
𝑎
5. A real number r is rational if, and only if, r= for some integers a and
𝑏
b with b ≠ 0.
6. If n and d are integers and d ≠ 0, then d divides n, written d|n if, and
only if, n = d.k for some integers k.
7. An integer n is called a perfect square if, and only if, n = 𝑘 2 for some
integer k.
Types of Proofs
 Proving conditional Statements
 Direct Proofs
 Indirect Proofs
 Proof by Contraposition
 Proofs by Contradiction
 Proving Non-conditional Statements
 Indirect Proofs
 If-And-Only-If Proof
 Constructive Versus Non-constructive Proofs
 Existence Proofs; Existence and Uniqueness Proofs
 Disproofs (Counterexample, Contradiction, Existence Statement)
 Proofs Involving Sets
 Mathematical Induction
Direct Proofs
 p q
 first step is the assumption that p is true
 subsequent steps constructed using rules of inference.
 final step showing that q must also be true

showing that if p is true,


then q must also be true,
so that the combination
p true and q false never occurs
Activity Time

Prove that the sum of two odd integers is even.


Prove that the sum of two odd integers is even.
proved that if n is an odd integer,
then n2 is an odd integer
 We assume that the hypothesis of this conditional
statement is true, namely, we assume that n is odd.
 By the definition of an odd integer, it follows that n =
2k + 1, where k is some integer.
 Square both sides n2 = (2k + 1)2
 4k2 + 4k + 1 = 2(2k2 + 2k) + 1.
 Consequently, we have proved that if n is an odd
integer, then n2 is an odd integer
Activity Time

Give a direct proof that if m and n are both perfect


squares, then nm is also a perfect square.
Proof
 We assume that the hypothesis of this conditional
statement is true, namely, we assume that m and n are
both perfect squares.
 By the definition of a perfect square, It follows that
there are integers s and t such that m = s2 and n = t2.
 Multiplying both m and n to get s2t2.
 Hence, mn = s2t2 = (ss)(tt) = (st)(st) = (st)2, using
commutativity and associativity of multiplication.
 By the definition of perfect square, it follows that mn
is also a perfect square, because it is the square of st,
which is an integer.
 We have proved that if m and n are both perfect
squares, then mn is also a perfect square.
Activity Time

Give a direct proof that if n is an integer and n is


odd, then 3n + 2 is odd.
Indirect Proofs
 Direct proof begin with the premises, continue with a
sequence of deductions, and end with the conclusion.
 Attempts at direct proofs often reach dead ends
 Proofs that do not start with the premises and end
with the conclusion, are called indirect proofs
Prove that if n is an integer and 3n + 2 is odd, then n
is odd.
Proofs by Contradiction
A proof by contradiction is based on the fact that either a
statement is true or it is false but not both. Hence the
supposition, that the statement to be proved is false, leads
logically to a contradiction, impossibility or absurdity, then the
supposition must be false. Accordingly, the given statement must
be true.
The method of proof by contradiction may be summarized as
follows:
1. Suppose the statement to be proved is false.
2. Show that this supposition leads logically to a contradiction.
3. Conclude that the statement to be proved is true.
Basic Idea
 Assume that the statement we want to prove is false,
and then show that this assumption leads to nonsense!

We are then led to


conclude that we were
wrong to assume the
statement was false,
so the statement must be true.
PROOF BY COUNTER EXAMPLE
Shoaib Raza
Conjecture: The sum of the first n
odd natural numbers equals n2.
An infinite ladder
 Suppose that we have an infinite ladder, and we want
to know whether we can reach every step on this
ladder.

 We know two things:


1. We can reach the first rung of the ladder.
2. If we can reach a particular rung of the ladder, then we
can reach the next rung.
Mathematical Induction
 Mathematical statements assert that a property is true for
all positive integers.

 Proofs using mathematical induction have two parts.


 First, they show that the statement holds for the positive integer 1
(base case).
 Second, they show that if the statement holds for a positive integer
then it must also hold for the next larger integer. (inductive case)

 The method can be extended to prove statements about


more general well-founded structures, such as trees; this
generalization, known as structural induction, is used
in mathematical logic and computer science.
NOTE
 It is extremely important to note that mathematical
induction can be used only to prove results obtained in
some other way.

 It is not a tool for discovering formulae or theorems.

 Mathematicians sometimes find proofs by mathematical


induction unsatisfying because they do not provide
insights as to why theorems are true.

 You can prove a theorem by mathematical induction even


if you do not have the slightest idea why it is true!
Chapter 6
Mr. Shoaib Raza
Chapter Summary
 The Basics of Counting
 The Pigeonhole Principle
 Permutations and Combinations
 Binomial Coefficients and Identities
 Generalized Permutations and Combinations
Chapter 4
Chapter Motivation
 Number theory is the part of mathematics devoted to the study
of the integers and their properties.
 Key ideas in number theory include divisibility and the primality
of integers.
 Number theory has long been studied because of the beauty of
its ideas, its accessibility, and its wealth of open questions.
 We’ll use many ideas developed in Chapter 1 about proof
methods and proof strategy in our exploration of number theory.
 Mathematicians have long considered number theory to be pure
mathematics, but it has important applications to computer
science and cryptography studied in Sections 4.5 and 4.6.
Chapter Summary
 Divisibility and Modular Arithmetic
 Primes and Greatest Common Divisors
 Solving Congruencies
 Applications of Congruencies
 Cryptography
Section 4.1
Section Summary
 Division
 Division Algorithm
 Modular Arithmetic
Division
Definition: If a and b are integers with a ≠ 0, then
a divides b if there exists an integer c such that b = ac.
 When a divides b we say that a is a factor or divisor of b
and that b is a multiple of a.
 The notation a | b denotes that a divides b.
 If a | b, then b/a is an integer.
 If a does not divide b, we write a ∤ b.
Example: Determine whether 3 | 7 and whether
3 | 12.
Properties of Divisibility
Theorem 1: Let a, b, and c be integers, where a ≠0.
i. If a | b and a | c, then a | (b + c);
ii.If a | b, then a | bc for all integers c;
If a | b and b | c, then a | c.
iii.
Proof: (i) Suppose a | b and a | c, then it follows that there are
integers s and t with b = as and c = at. Hence,
b + c = as + at = a(s + t). Hence, a | (b + c)
(Exercises 3 and 4 ask for proofs of parts (ii) and (iii).)
Corollary: If a, b, and c be integers, where a ≠0, such that
a | b and a | c, then a | mb + nc whenever m and n are
integers.
Can you show how it follows easily from from (ii) and (i) of
Theorem 1?
Division Algorithm
 When an integer is divided by a positive integer, there is a quotient and
a remainder. This is traditionally called the “Division Algorithm,” but is
really a theorem.
Division Algorithm: If a is an integer and d a positive integer, then
there are unique integers q and r, with 0 ≤ r < d, such that a = dq + r
(proved in Section 5.2). Definitions of Functions
 d is called the divisor.
div and mod
 a is called the dividend.
 q is called the quotient.
 r is called the remainder. q = a div d
Examples: r = a mod d
 What are the quotient and remainder when 101 is divided by 11?
Solution: The quotient when 101 is divided by 11 is 9 = 101 div 11, and the
remainder is 2 = 101 mod 11.
 What are the quotient and remainder when −11 is divided by 3?
Solution: The quotient when −11 is divided by 3 is −4 = −11 div 3, and the
remainder is 1 = −11 mod 3.
Congruence Relation
Definition: If a and b are integers and m is a positive integer, then a is
congruent to b modulo m if m divides a – b.
 The notation a ≡ b (mod m) says that a is congruent to b modulo m.
 We say that a ≡ b (mod m) is a congruence and that m is its modulus.
 Two integers are congruent mod m if and only if they have the same
remainder when divided by m.
 If a is not congruent to b modulo m, we write
a ≢ b (mod m)
Example: Determine whether 17 is congruent to 5 modulo 6 and
whether 24 and 14 are congruent modulo 6.

Solution:
 17 ≡ 5 (mod 6) because 6 divides 17 − 5 = 12.
 24 ≢ 14 (mod 6) since 6 divides 24 − 14 = 10 is not divisible by 6.
More on Congruences
Theorem 4: Let m be a positive integer. The integers a
and b are congruent modulo m if and only if there is
an integer k such that a = b + km.
Proof:
 If a ≡ b (mod m), then (by the definition of
congruence) m | a – b. Hence, there is an integer k such
that a – b = km and equivalently a = b + km.
 Conversely, if there is an integer k such that a = b + km,
then km = a – b. Hence, m | a – b and a ≡ b (mod m).
The Relationship between
(mod m) and mod m Notations
 The use of “mod” in a ≡ b (mod m) and a mod m = b
are different.
 a ≡ b (mod m) is a relation on the set of integers.
 In a mod m = b, the notation mod denotes a function.
 The relationship between these notations is made
clear in this theorem.
 Theorem 3: Let a and b be integers, and let m be a
positive integer. Then a ≡ b (mod m) if and only if
a mod m = b mod m. (Proof in the exercises)
Congruencies of Sums and Products
Let m be a positive integer. If a ≡ b (mod m) and c ≡
d (mod m), then
a + c ≡ b + d (mod m) and ac ≡ bd (mod m)
Example: Because 7 ≡ 2 (mod 5) and 11 ≡ 1 (mod 5)
, it follows from Theorem 5 that
18 = 7 + 11 ≡ 2 + 1 = 3 (mod 5)
77 = 7 11 ≡ 2 * 1 = 2 (mod 5)
Algebraic Manipulation of Congruencies
 Multiplying both sides of a valid congruence by an integer
preserves validity.
If a ≡ b (mod m) holds then c∙a ≡ c∙b (mod m), where c is any
integer, holds by Theorem 5 with d = c.
 Adding an integer to both sides of a valid congruence preserves
validity.
If a ≡ b (mod m) holds then c + a ≡ c + b (mod m), where c is any
integer, holds by Theorem 5 with d = c.
 Dividing a congruence by an integer does not always produce a
valid congruence.
Example: The congruence 14≡ 8 (mod 6) holds. But dividing
both sides by 2 does not produce a valid congruence since
14/2 = 7 and 8/2 = 4, but 7≢4 (mod 6).
Computing the mod m Function of
Products and Sums
 We use the following corollary to Theorem 5 to
compute the remainder of the product or sum of two
integers when divided by m from the remainders when
each is divided by m.
Corollary: Let m be a positive integer and let a and b
be integers. Then
(a + b) (mod m) = ((a mod m) + (b mod m)) mod m
and
ab mod m = ((a mod m) (b mod m)) mod m.
(proof in text)
Section Summary
 Hashing Functions
 Pseudorandom Numbers
 Check Digits
Hashing Functions
Definition: A hashing function h assigns memory location h(k) to the record that has
k as its key.
 A common hashing function is h(k) = k mod m, where m is the number of
memory locations.
 Because this hashing function is onto, all memory locations are possible.
Example: Let h(k) = k mod 111. This hashing function assigns the records of
customers with social security numbers as keys to memory locations in the following
manner:
h(064212848) = 064212848 mod 111 = 14
h(037149212) = 037149212 mod 111 = 65
h(107405723) = 107405723 mod 111 = 14, but since location 14 is already
occupied, the record is assigned to the next available position, which is 15.
 The hashing function is not one-to-one as there are many more possible keys than
memory locations. When more than one record is assigned to the same location, we
say a collision occurs. Here a collision has been resolved by assigning the record to
the first free location.
 For collision resolution, we can use a linear probing function:
h(k,i) = (h(k) + i) mod m, where i runs from 0 to m − 1.
 There are many other methods of handling with collisions. You may cover these in a
later CS course.
Pseudorandom Numbers
 Randomly chosen numbers are needed for many purposes,
including computer simulations.
 Pseudorandom numbers are not truly random since they are
generated by systematic methods.
 The linear congruential method is one commonly used procedure
for generating pseudorandom numbers.
 Four integers are needed: the modulus m, the multiplier a, the
increment c, and seed x0, with 2 ≤ a < m, 0 ≤ c < m, 0 ≤ x0 < m.
 We generate a sequence of pseudorandom numbers {xn}, with
0 ≤ xn < m for all n, by successively using the recursively defined
function
xn+1 = (axn + c) mod m.
(an example of a recursive definition, discussed in Section 5.3)
 If psudorandom numbers between 0 and 1 are needed, then the
generated numbers are divided by the modulus, xn /m.
Pseudorandom Numbers
 Example: Find the sequence of pseudorandom numbers generated by the linear
congruential method with modulus m = 9, multiplier a = 7, increment c = 4, and
seed x0 = 3.
 Solution: Compute the terms of the sequence by successively using the
congruence xn+1 = (7xn + 4) mod 9, with x0 = 3.
x1 = 7x0 + 4 mod 9 = 7∙3 + 4 mod 9 = 25 mod 9 = 7,
x2 = 7x1 + 4 mod 9 = 7∙7 + 4 mod 9 = 53 mod 9 = 8,
x3 = 7x2 + 4 mod 9 = 7∙8 + 4 mod 9 = 60 mod 9 = 6,
x4 = 7x3 + 4 mod 9 = 7∙6 + 4 mod 9 = 46 mod 9 = 1,
x5 = 7x4 + 4 mod 9 = 7∙1 + 4 mod 9 = 11 mod 9 = 2,
x6 = 7x5 + 4 mod 9 = 7∙2 + 4 mod 9 = 18 mod 9 = 0,
x7 = 7x6 + 4 mod 9 = 7∙0 + 4 mod 9 = 4 mod 9 = 4,
x8 = 7x7 + 4 mod 9 = 7∙4 + 4 mod 9 = 32 mod 9 = 5,
x9 = 7x8 + 4 mod 9 = 7∙5 + 4 mod 9 = 39 mod 9 = 3.
The sequence generated is 3,7,8,6,1,2,0,4,5,3,7,8,6,1,2,0,4,5,3,…
It repeats after generating 9 terms.
 Commonly, computers use a linear congruential generator with increment c = 0.
This is called a pure multiplicative generator. Such a generator with modulus 231 −
1 and multiplier 75 = 16,807 generates 231 − 2 numbers before repeating.
Check Digits: UPCs
 A common method of detecting errors in strings of digits is to add an extra digit at
the end, which is evaluated using a function. If the final digit is not correct, then
the string is assumed not to be correct.
Example: Retail products are identified by their Universal Product Codes (UPCs).
Usually these have 12 decimal digits, the last one being the check digit. The check
digit is determined by the congruence:
3x1 + x2 + 3x3 + x4 + 3x5 + x6 + 3x7 + x8 + 3x9 + x10 + 3x11 + x12 ≡ 0 (mod 10).
a. Suppose that the first 11 digits of the UPC are 79357343104. What is the check
digit?
b. Is 041331021641 a valid UPC?
Solution:
a. 3∙7 + 9 + 3∙3 + 5 + 3∙7 + 3 + 3∙4 + 3 + 3∙1 + 0 + 3∙4 + x12 ≡ 0 (mod 10)
21 + 9 + 9 + 5 + 21 + 3 + 12+ 3 + 3 + 0 + 12 + x12 ≡ 0 (mod 10)
98 + x12 ≡ 0 (mod 10)
x12 ≡ 0 (mod 10) So, the check digit is 2.
b. 3∙0 + 4 + 3∙1 + 3 + 3∙3 + 1 + 3∙0 + 2 + 3∙1 + 6 + 3∙4 + 1 ≡ 0 (mod 10)
0 + 4 + 3 + 3 + 9 + 1 + 0+ 2 + 3 + 6 + 12 + 1 = 44 ≡ 4 ≢ (mod 10)
Hence, 041331021641 is not a valid UPC.
Check Digits:ISBNs
Books are identified by an International Standard Book Number (ISBN-10), a 10 digit code. The
first 9 digits identify the language, the publisher, and the book. The tenth digit is a check digit,
which is determined by the following congruence

The validity of an ISBN-10 number can be evaluated with the equivalent

a. Suppose that the first 9 digits of the ISBN-10 are 007288008. What is the check digit?
b. Is 084930149X a valid ISBN10?

Solution: X is used
a. X10 ≡ 1∙0 + 2∙0 + 3∙7 + 4∙2 + 5∙8 + 6∙8 + 7∙ 0 + 8∙0 + 9∙8 (mod 11). for the
X10 ≡ 0 + 0 + 21 + 8 + 40 + 48 + 0 + 0 + 72 (mod 11). digit 10.
X10 ≡ 189 ≡ 2 (mod 11). Hence, X10 = 2.
b. 1∙0 + 2∙8 + 3∙4 + 4∙9 + 5∙3 + 6∙0 + 7∙ 1 + 8∙4 + 9∙9 + 10∙10 =
0 + 16 + 12 + 36 + 15 + 0 + 7 + 32 + 81 + 100 = 299 ≡ 2 ≢ 0 (mod 11)
Hence, 084930149X is not a valid ISBN-10.

 A single error is an error in one digit of an identification number and a transposition error is
the accidental interchanging of two digits. Both of these kinds of errors can be detected by
the check digit for ISBN-10. (see text for more details)
Arithmetic Modulo m
Definitions: Let Zm be the set of nonnegative integers less
than m: {0,1, …., m−1}
 The operation +m is defined as a +m b = (a + b) mod m.
This is addition modulo m.
 The operation ∙m is defined as a ∙m b = (a . b) mod m. This
is multiplication modulo m.
 Using these operations is said to be doing arithmetic
modulo m.
Example: Find 7 +11 9 and 7 ∙11 9.
Solution: Using the definitions above:
 7 +11 9 = (7 + 9) mod 11 = 16 mod 11 = 5
 7 ∙11 9 = (7 ∙ 9) mod 11 = 63 mod 11 = 8
Arithmetic Modulo m
 The operations +m and ∙m satisfy many of the same properties as
ordinary addition and multiplication.
 Closure: If a and b belong to Zm , then a +m b and a ∙m b belong
to Zm .
 Associativity: If a, b, and c belong to Zm , then
(a +m b) +m c = a +m (b +m c) and (a ∙m b) ∙m c = a ∙m (b ∙m c).
 Commutativity: If a and b belong to Zm , then
a +m b = b +m a and a ∙m b = b ∙m a.
 Identity elements: The elements 0 and 1 are identity elements
for addition and multiplication modulo m, respectively.
 If a belongs to Zm , then a +m 0 = a and a ∙m 1 = a.

continued →
Arithmetic Modulo m
 Additive inverses: If a≠ 0 belongs to Zm , then m− a is the additive
inverse of a modulo m and 0 is its own additive inverse.
 a +m (m− a ) = 0 and 0 +m 0 = 0

 Distributivity: If a, b, and c belong to Zm , then


 a ∙m (b +m c) = (a ∙m b) +m (a ∙m c) and
(a +m b) ∙m c = (a ∙m c) +m (b ∙m c).
 Exercises 42-44 ask for proofs of these properties.
 Multiplicatative inverses have not been included since they do not
always exist. For example, there is no multiplicative inverse of 2 modulo
6.
 (optional) Using the terminology of abstract algebra, Zm with +m is a
commutative group and Zm with +m and ∙m is a commutative ring.
Section 4.3
Section Summary
 Prime Numbers and their Properties
 Greatest Common Divisors and Least Common
Multiples
 The Euclidian Algorithm
 gcds as Linear Combinations
Primes
Definition: A positive integer p greater than 1 is
called prime if the only positive factors of p are 1 and
p. A positive integer that is greater than 1 and is not
prime is called composite.

Example: The integer 7 is prime because its only


positive factors are 1 and 7, but 9 is composite
because it is divisible by 3.
The Fundamental Theorem of
Arithmetic
Theorem: Every positive integer greater than 1 can be
written uniquely as a prime or as the product of two or
more primes where the prime factors are written in
order of non decreasing size.
Examples:
 100 = 2 ∙ 2 ∙ 5 ∙ 5 = 22 ∙ 52
 641 = 641
 999 = 3 ∙ 3 ∙ 3 ∙ 37 = 33 ∙ 37
 1024 = 2 ∙ 2 ∙ 2 ∙ 2 ∙ 2 ∙ 2 ∙ 2 ∙ 2 ∙ 2 ∙ 2 = 210
The Sieve of Erastosthenes
If an integer n is a
composite integer, then
it has a prime divisor
less than or equal to √n.

To see this, note that if


n = ab, then a ≤ √n or
b ≤√n.

Trial division, a very


inefficient method of
determining if a
number n is prime, is to
try every integer i ≤√n
and see if n is divisible
by i.
Erastothenes
(276-194 B.C.)

The Sieve of Erastosthenes


 The Sieve of Erastosthenes can be used to find all primes
not exceeding a specified positive integer. For example,
begin with the list of integers between 1 and 100.
a. Delete all the integers, other than 2, divisible by 2.
b. Delete all the integers, other than 3, divisible by 3.
c. Next, delete all the integers, other than 5, divisible by 5.
d. Next, delete all the integers, other than 7, divisible by 7.
e. Since all the remaining integers are not divisible by any of
the previous integers, other than 1, the primes are:
{2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,
97}
continued →
Marin Mersenne
(1588-1648)

Mersenne Primes
Definition: Prime numbers of the form 2p − 1 , where p is
prime, are called Mersenne primes.
 22 − 1 = 3, 23 − 1 = 7, 25 − 1 = 37 , and 27 − 1 = 127 are
Mersenne primes.
 211 − 1 = 2047 is not a Mersenne prime since 2047 = 23∙89.
 There is an efficient test for determining if 2p − 1 is prime.
 The largest known prime numbers are Mersenne primes.
 As of mid 2011, 47 Mersenne primes were known, the largest
is 243,112,609 − 1, which has nearly 13 million decimal digits.
 The Great Internet Mersenne Prime Search (GIMPS) is a
distributed computing project to search for new Mersenne
Primes.
http://www.mersenne.org/
Greatest Common Divisor
Definition: Let a and b be integers, not both zero. The
largest integer d such that d | a and also d | b is called the
greatest common divisor of a and b. The greatest common
divisor of a and b is denoted by gcd(a,b).

One can find greatest common divisors of small numbers


by inspection.
Example: What is the greatest common divisor of 24 and
36?
Solution: gcd(24,36) = 12
Example: What is the greatest common divisor of 17 and
22?
Solution: gcd(17,22) = 1
Greatest Common Divisor
Definition: The integers a and b are relatively prime if their
greatest common divisor is 1.
Example: 17 and 22
Definition: The integers a1, a2, …, an are pairwise relatively prime
if gcd(ai, aj)= 1 whenever 1 ≤ i<j ≤n.
Example: Determine whether the integers 10, 17 and 21 are
pairwise relatively prime.
Solution: Because gcd(10,17) = 1, gcd(10,21) = 1, and
gcd(17,21) = 1, 10, 17, and 21 are pairwise relatively prime.
Example: Determine whether the integers 10, 19, and 24 are
pairwise relatively prime.
Solution: Because gcd(10,24) = 2, 10, 19, and 24 are not
pairwise relatively prime.
Finding the Greatest Common Divisor
Using Prime Factorizations
 Suppose the prime factorizations of a and b are:

where each exponent is a nonnegative integer, and where all primes


occurring in either prime factorization are included in both. Then:

 This formula is valid since the integer on the right (of the equals sign)
divides both a and b. No larger integer can divide both a and b.
Example: 120 = 23 ∙3 ∙5 500 = 22 ∙53
gcd(120,500) = 2min(3,2) ∙3min(1,0) ∙5min(1,3) = 22 ∙30 ∙51 = 20
 Finding the gcd of two positive integers using their prime factorizations
is not efficient because there is no efficient algorithm for finding the
prime factorization of a positive integer.
Least Common Multiple
Definition: The least common multiple of the positive integers a and b
is the smallest positive integer that is divisible by both a and b. It is
denoted by lcm(a,b).
 The least common multiple can also be computed from the prime
factorizations.

This number is divided by both a and b and no smaller number is


divided by a and b.
Example: lcm(233572, 2433) = 2max(3,4) 3max(5,3) 7max(2,0) = 24 35 72
 The greatest common divisor and the least common multiple of two
integers are related by:
Theorem 5: Let a and b be positive integers. Then
ab = gcd(a,b) ∙lcm(a,b)
(proof is Exercise 31)
Euclidean Algorithm Euclid
(325 B.C.E. – 265 B.C.E.)
 The Euclidian algorithm is an efficient method for
computing the greatest common divisor of two integers. It
is based on the idea that gcd(a,b) is equal to gcd(a,c) when
a > b and c is the remainder when a is divided by b.
Example: Find gcd(91, 287):
 287 = 91 ∙ 3 + 14 Divide 287 by 91
 91 = 14 ∙ 6 + 7 Divide 91 by 14
 14 = 7 ∙ 2 + 0 Divide 14 by 7
Stopping
condition

gcd(287, 91) = gcd(91, 14) = gcd(14, 7) = 7


continued →
Euclidean Algorithm
 The Euclidean algorithm expressed in pseudocode is:
procedure gcd(a, b: positive integers)
x := a
x := b
while y ≠ 0
r := x mod y
x := y
y := r
return x {gcd(a,b) is x}

 In Section 5.3, we’ll see that the time complexity of the


algorithm is O(log b), where a > b.
Étienne Bézout
(1730-1783)
gcds as Linear Combinations
Bézout’s Theorem: If a and b are positive integers, then
there exist integers s and t such that gcd(a,b) = sa + tb.

Definition: If a and b are positive integers, then integers s


and t such that gcd(a,b) = sa + tb are called Bézout
coefficients of a and b. The equation gcd(a,b) = sa + tb is
called Bézout’s identity.

 By Bézout’s Theorem, the gcd of integers a and b can be


expressed in the form sa + tb where s and t are integers.
This is a linear combination with integer coefficients of a
and b.
 gcd(6,14) = (−2)∙6 + 1∙14
Finding gcds as Linear Combinations
Example: Express gcd(252,198) = 18 as a linear combination of 252
and 198.
Solution: First use the Euclidean algorithm to show gcd(252,198) = 18
i. 252 = 1∙198 + 54
ii. 198 = 3 ∙54 + 36
iii. 54 = 1 ∙36 + 18
iv. 36 = 2 ∙18
 Now working backwards, from iii and i above
 18 = 54 − 1 ∙36
 36 = 198 − 3 ∙54
 Substituting the 2nd equation into the 1st yields:
 18 = 54 − 1 ∙(198 − 3 ∙54 )= 4 ∙54 − 1 ∙198
 Substituting 54 = 252 − 1 ∙198 (from i)) yields:
 18 = 4 ∙(252 − 1 ∙198) − 1 ∙198 = 4 ∙252 − 5 ∙198

 This method illustrated above is a two pass method. It first uses the
Euclidian algorithm to find the gcd and then works backwards to
express the gcd as a linear combination of the original two integers. A
one pass method, called the extended Euclidean algorithm, is
developed in the exercises.
Dividing Congruencies by an
Integer
 Dividing both sides of a valid congruence by an integer
does not always produce a valid congruence (see
Section 4.1).
 But dividing by an integer relatively prime to the
modulus does produce a valid congruence:
Theorem 7: Let m be a positive integer and let a, b,
and c be integers. If ac ≡ bc (mod m) and gcd(c,m) = 1,
then a ≡ b (mod m).
Proof: Since ac ≡ bc (mod m), m | ac − bc = c(a − b)
by Lemma 2 and the fact that gcd(c,m) = 1, it follows
that m | a − b. Hence, a ≡ b (mod m).
Section 4.4
Section Summary
 Linear Congruencies
 The Chinese Remainder Theorem
 Fermat’s Little Theorem
 Pseudo primes
Linear Congruencies
Definition: A congruence of the form
ax ≡ b( mod m),
where m is a positive integer, a and b are integers, and x is a variable, is
called a linear congruence.

 The solutions to a linear congruence ax≡ b( mod m) are all integers x


that satisfy the congruence.

Definition: An integer ā such that āa ≡ 1( mod m) is said to be an


inverse of a modulo m.
Example: 5 is an inverse of 3 modulo 7 since 5∙3 = 15 ≡ 1(mod 7)

 One method of solving linear congruencies makes use of an inverse ā,


if it exists. Although we can not divide both sides of the congruence by
a, we can multiply by ā to solve for x.
Inverse of a modulo m
 The following theorem guarantees that an inverse of a modulo m
exists whenever a and m are relatively prime. Two integers a and
b are relatively prime when gcd(a,b) = 1.
Theorem 1: If a and m are relatively prime integers and m > 1,
then an inverse of a modulo m exists. Furthermore, this inverse
is unique modulo m. (This means that there is a unique positive
integer ā less than m that is an inverse of a modulo m and every
other inverse of a modulo m is congruent to ā modulo m.)
Proof: Since gcd(a,m) = 1, by Theorem 6 of Section 4.3, there
are integers s and t such that sa + tm = 1.
 Hence, sa + tm ≡ 1 ( mod m).
 Since tm ≡ 0 ( mod m), it follows that sa ≡ 1 ( mod m)
 Consequently, s is an inverse of a modulo m.
 The uniqueness of the inverse is Exercise 7.
Finding Inverses
 The Euclidean algorithm and Bézout coefficients gives us a
systematic approaches to finding inverses.
Example: Find an inverse of 3 modulo 7.
Solution: Because gcd(3,7) = 1, by Theorem 1, an inverse
of 3 modulo 7 exists.
 Using the Euclidian algorithm: 7 = 2∙3 + 1.
 From this equation, we get −2∙3 + 1∙7 = 1, and see that −2
and 1 are Bézout coefficients of 3 and 7.
 Hence, −2 is an inverse of 3 modulo 7.
 Also every integer congruent to −2 modulo 7 is an inverse of
3 modulo 7, i.e., 5, −9, 12, etc.
Finding Inverses
Example: Find an inverse of 101 modulo 4620.
Solution: First use the Euclidian algorithm to show that
gcd(101,4620) = 1. Working Backwards:
4620 = 45∙101 + 75 1 = 3 − 1∙2
101 = 1∙75 + 26 1 = 3 − 1∙(23 − 7∙3) = − 1 ∙23 + 8∙3
75 = 2∙26 + 23 1 = −1∙23 + 8∙(26 − 1∙23) = 8∙26 − 9 ∙23
26 = 1∙23 + 3 1 = 8∙26 − 9 ∙(75 − 2∙26 )= 26∙26 − 9 ∙75
23 = 7∙3 + 2 1 = 26∙(101 − 1∙75) − 9 ∙75
3 = 1∙2 + 1 = 26∙101 − 35 ∙75
2 = 2∙1 1 = 26∙101 − 35 ∙(42620 − 45∙101)
Since the last nonzero
= − 35 ∙42620 + 1601∙101
remainder is 1, Bézout coefficients : − 35 and 1601 1601 is an inverse of
gcd(101,4260) = 1 101 modulo 42620
Using Inverses to Solve Congruences
 We can solve the congruence ax≡ b( mod m) by multiplying both
sides by ā.
Example: What are the solutions of the congruence 3x≡ 4( mod 7).
Solution: We found that −2 is an inverse of 3 modulo 7 (two slides
back). We multiply both sides of the congruence by −2 giving
−2 ∙ 3x ≡ −2 ∙ 4(mod 7).
Because −6 ≡ 1 (mod 7) and −8 ≡ 6 (mod 7), it follows that if x is a
solution, then x ≡ −8 ≡ 6 (mod 7)
We need to determine if every x with x ≡ 6 (mod 7) is a solution.
Assume that x ≡ 6 (mod 7). By Theorem 5 of Section 4.1, it follows
that 3x ≡ 3 ∙ 6 = 18 ≡ 4( mod 7) which shows that all such x satisfy the
congruence.
The solutions are the integers x such that x ≡ 6 (mod 7), namely,
6,13,20 … and −1, − 8, − 15,…
The Chinese Remainder Theorem
Theorem 2: (The Chinese Remainder Theorem) Let m1,m2,…,mn
be pairwise relatively prime positive integers greater than one
and a1,a2,…,an arbitrary integers. Then the system
x ≡ a1 ( mod m1)
x ≡ a2 ( mod m2)



x ≡ an ( mod mn)
has a unique solution modulo m = m1m2 ∙ ∙ ∙ mn.
(That is, there is a solution x with 0 ≤ x <m and all other
solutions are congruent modulo m to this solution.)

 Proof: We’ll show that a solution exists by describing a way to


construct the solution. Showing that the solution is unique
modulo m is Exercise 30.
continued →
The Chinese Remainder Theorem
To construct a solution first let Mk=m/mk for k = 1,2,…,n and m = m1m2 ∙ ∙ ∙ mn.

Since gcd(mk ,Mk ) = 1, by Theorem 1, there is an integer yk , an inverse of Mk


modulo mk, such that
Mk yk ≡ 1 ( mod mk ).
Form the sum
x = a1 M1 y1 + a2 M2 y2 + ∙ ∙ ∙ + an Mn yn (mod m)

Note that because Mj ≡ 0 ( mod mk) whenever j ≠k , all terms except the kth
term in this sum are congruent to 0 modulo mk .
Because Mk yk ≡ 1 ( mod mk ), we see that x ≡ ak Mk yk ≡ ak( mod mk), for k
= 1,2,…,n.
Hence, x is a simultaneous solution to the n congruences.
x ≡ a1 ( mod m1)
x ≡ a2 ( mod m2)



x ≡ an ( mod mn)
The Chinese Remainder Theorem
Example: Consider the 3 congruences from Sun-Tsu’s problem:
x ≡ 2 ( mod 3), x ≡ 3 ( mod 5), x ≡ 2 ( mod 7).
 Let m = 3∙ 5 ∙ 7 = 105, M1 = m/3 = 35, M3 = m/5 = 21,
M3 = m/7 = 15.
 We see that
 2 is an inverse of M1 = 35 modulo 3 since 35 ∙ 2 ≡ 2 ∙ 2 ≡ 1 (mod 3)
 1 is an inverse of M2 = 21 modulo 5 since 21 ≡ 1 (mod 5)
 1 is an inverse of M3 = 15 modulo 7 since 15 ≡ 1 (mod 7)
 Hence,

x = a1M1y1 + a2M2y2 + a3M3y3 (mod m)


= 2 ∙ 35 ∙ 2 + 3 ∙ 21 ∙ 1 + 2 ∙ 15 ∙ 1 = 233 ≡ 23 (mod 105)

 We have shown that 23 is the smallest positive integer that is a


simultaneous solution. Check it!
The Chinese Remainder Theorem
Word Problem:
Jessica breeds rabbits. She's not sure exactly how many she has
today, but as she was moving them about this morning, she
noticed some things. When she fed them, in groups of 5, she had
4 left over. When she bathed them, in groups of 8, she had a
group of 6 left over. She took them outside to romp in groups of
9, but then the last group consisted of only 8. She's positive that
there are fewer than 250 rabbits - but how many does she have?
Solution:
We have the following congurences
x ≡ 4 ( mod 5),
x ≡ 6 ( mod 8),
x ≡ 8 ( mod 9).
Section Summary
 Classical Cryptography
 Cryptosystems
 Public Key Cryptography
 RSA Cryptosystem
 Fermat’s Little theorem
Caesar Cipher
Julius Caesar created secret messages by shifting each letter three letters forward
in the alphabet (sending the last three letters to the first three letters.) For
example, the letter B is replaced by E and the letter X is replaced by A. This
process of making a message secret is an example of encryption.
Here is how the encryption process works:
 Replace each letter by an integer from Z26, that is an integer from 0 to 25
representing one less than its position in the alphabet.
 The encryption function is f(p) = (p + 3) mod 26. It replaces each integer p in
the set {0,1,2,…,25} by f(p) in the set {0,1,2,…,25} .
 Replace each integer p by the letter with the position p + 1 in the alphabet.
Example: Encrypt the message “MEET YOU IN THE PARK” using the Caesar
cipher.
Solution: 12 4 4 19 24 14 20 8 13 19 7 4 15 0 17 10.
Now replace each of these numbers p by f(p) = (p + 3) mod 26.
15 7 7 22 1 17 23 11 16 22 10 7 18 3 20 13.
Translating the numbers back to letters produces the encrypted message
“PHHW BRX LQ WKH SDUN.”
Caesar Cipher
 To recover the original message, use f−1(p) = (p−3) mod 26.
So, each letter in the coded message is shifted back three
letters in the alphabet, with the first three letters sent to
the last three letters. This process of recovering the original
message from the encrypted message is called decryption.
 The Caesar cipher is one of a family of ciphers called shift
ciphers. Letters can be shifted by an integer k, with 3 being
just one possibility. The encryption function is
f(p) = (p + k) mod 26
and the decryption function is
f−1(p) = (p−k) mod 26
The integer k is called a key.
Shift Cipher
Example 1: Encrypt the message “STOP GLOBAL
WARMING” using the shift cipher with k = 11.
Solution: Replace each letter with the corresponding
element of Z26.
18 19 14 15 6 11 14 1 0 11 22 0 17 12 8 13 6.
Apply the shift f(p) = (p + 11) mod 26, yielding
3 4 25 0 17 22 25 12 11 22 7 11 2 23 19 24 17.
Translating the numbers back to letters produces the
ciphertext
“DEZA RWZMLW HLCXTYR.”
Shift Cipher
Example 2: Decrypt the message “LEWLYPLUJL PZ H
NYLHA ALHJOLY” that was encrypted using the shift
cipher with k = 7.
Solution: Replace each letter with the corresponding
element of Z26.
11 4 22 11 24 15 11 20 9 11 15 25 7 13 24 11 7 0 0 11 7 9 14 11 24.
Shift each of the numbers by −k = −7 modulo 26, yielding
4 23 15 4 17 8 4 13 2 4 8 18 0 6 17 4 0 19 19 4 0 2 7 4 17.
Translating the numbers back to letters produces the
decrypted message
“EXPERIENCE IS A GREAT TEACHER.”
Using RSA
Given pubKey = <e, n> and privKey = <d, n>
If Message = m
Then:
encryption: c = me mod n, m < n
decryption: m = cd mod n
signature: s = md mod n, m < n
verification: m = se mod n

8. Cryptography part 2 113


Example of RSA (1)
Choose p = 7 and q = 17.
Compute n = p*q= 119.
Compute f(n)=(p-1)(q-1)=96.
Select e = 5, (a relatively prime to f(n).)
Compute d = _77_such that e*d=1 mod f(n).
• Public key: <5,119>
• Private key: <77,119>
• Message = 19
• Encryption: 195 mod 119 = 66
• Decryption: 6677 mod 119 = 19

8. Cryptography part 2 114


Example of RSA (2)
p = 7, q = 11, n = 77
Alice chooses e = 17, making d = 53
Bob wants to send Alice secret message
HELLO (07 04 11 11 14)
– 0717 mod 77 = 28; 0417 mod 77 = 16
– 1117 mod 77 = 44; – 1117 mod 77 = 44
– 1417 mod 77 = 42
• Bob sends 28 16 44 44 42

8. Cryptography part 2 115


Example of RSA (3)
Alice receives 28 16 44 44 42
Alice uses private key, d = 53, to decrypt message:
– 2853 mod 77 = 07; 1653 mod 77 = 04
– 4453 mod 77 = 11; 4453 mod 77 = 11
– 4253 mod 77 = 14
• Alice translates 07 04 11 11 14 to HELLO
No one else could read it, as only Alice knows her
private key (needed for decryption)

8. Cryptography part 2 116


Fermat’s Little Theorem Pierre de Fermat
(1601-1665)

Theorem 3: (Fermat’s Little Theorem) If p is prime and a is an integer not


divisible by p, then ap-1 ≡ 1 (mod p)
Furthermore, for every integer a we have ap ≡ a (mod p)
(proof outlined in Exercise 19)

Fermat’s little theorem is useful in computing the remainders modulo p of


large powers of integers.
Example: Find 7222 mod 11.
By Fermat’s little theorem, we know that 710 ≡ 1 (mod 11), and so (710 )k ≡
1 (mod 11), for every positive integer k. Therefore,

7222 = 722∙10 + 2 = (710)2272 ≡ (1)22 ∙49 ≡ 5 (mod 11).

Hence, 7222 mod 11 = 5.


Section 6.1
COMBINATORICS
 Combinatorics is the mathematics of counting and
arranging objects. Counting of objects with certain
properties (enumeration) is required to solve many
different types of problem.
 Applications, include topics as diverse as codes, circuit
design and algorithm complexity [and gambling]
Counting
 Enumeration, the counting of objects with certain
properties, is an important part of combinatorics.
 We must count objects to solve many different types of
problems. For example, counting is used to:
1. Determine number of ordered or unordered arrangement
of objects.
2. Generate all the arrangements of a specified kind which is
important in computer simulations.
3. Compute probabilities of events.
4. Analyze the chance of winning games, lotteries etc.
5. Determine the complexity of algorithms.
Section Summary
 The Sum Rule
 The Product Rule
 The Subtraction Rule
 The Division Rule
 Examples, Examples, and Examples
 Tree Diagrams
Basic Counting Principles: The Sum Rule
The Sum Rule: If a task can be done
either in one of n1 ways or in one of n2
ways to do the second task, where none
of the set of n1 ways is the same as any
of the n2 ways, then there are n1 + n2
ways to do the task.
The Sum Rule in terms of sets.
 The sum rule can be phrased in terms of sets.
|A ∪ B|= |A| + |B| as long as A and B are disjoint sets.
 Or more generally,

|A1 ∪ A2 ∪ ∙∙∙ ∪ Am |= |A1| + |A2| + ∙∙∙ + |Am|


when Ai ∩ Aj = ∅ for all i, j.
 The case where the sets have elements in common will
be discussed when we consider the subtraction rule and
taken up fully in Chapter 8.
Basic Counting Principles: The Sum Rule
Example:
Suppose there are 7 different optional courses in
Computer Science and 3 different optional courses in
Mathematics. How many ways student can choose a
course.
Solution: By the sum rule it follows that there are
7 + 3 = 10 choices for a student who wants to take one
optional course.
Basic Counting Principles: The Sum Rule
Example: The mathematics department must choose
either a student or a faculty member as a
representative for a university committee. How many
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: By the sum rule it follows that there are
37 + 83 = 120 possible ways to pick a representative.
Basic Counting Principles: The Sum Rule
Example: A student can choose a computer project from
one of the three lists. The three lists contain 23, 15 and 19
possible projects, respectively. How many possible
projects are there to choose from?
Solution: The student can choose a project from the first
list in 23 ways, from the second list in 15 ways, and from
the third list in 19 ways. Hence, there are
23 + 15 + 19 = 57 projects to choose from.
Basic Counting Principles: The Product
Rule
The Product Rule: A procedure can be
broken down into a sequence of two
tasks. There are n1 ways to do the first
task and n2 ways to do the second task.
Then there are n1∙n2 ways to do the
procedure.
Product Rule in Terms of Sets
 If A1, A2, … , Am are finite sets, then the number of
elements in the Cartesian product of these sets is the
product of the number of elements of each set.
 The task of choosing an element in the Cartesian
product A1 ⨉ A2 ⨉ ∙∙∙ ⨉ Am is done by choosing an
element in A1, an element in A2 , …, and an element
in Am.
 By the product rule, it follows that:
|A1 ⨉ A2 ⨉ ∙∙∙ ⨉ Am |= |A1| ∙ |A2| ∙ ∙∙∙ ∙ |Am|.
The Product Rule
Example: How many ways a student can choose one
optional course each from computer science and
mathematics courses if there are 7 different optional
courses in Computer Science and 3 different optional
courses in Mathematics.
Solution:
A student who wants to take one optional course of each
subject, there are 7 × 3 = 21 choices.
The Product Rule
Example: The chairs of an auditorium are to be labeled
with two characters, a letter followed by a digit. What
is the largest number of chairs that can be labeled
differently?
Solution:
The procedure of labeling a chair consists of two events,
namely,
Assigning one of the 26 letters: A, B, C, …, Z and
Assigning one of the 10 digits: 0, 1, 2, …, 9
By product rule, there are 26 × 10 = 260 different ways
that a chair can be labeled by both a letter and a digit.
The Product Rule
Example: Find the number n of ways that an organization
consisting of 15 members can elect a president, treasurer,
and secretary. (assuming no person is elected to more than
one position)
Solution:
The president can be elected in 15 different ways; following
this, the treasurer can be elected in 14 different ways; and
following this, the secretary can be elected in 13 different
ways. Thus, by product rule, there are
n = 15 × 14 × 13 = 2730
different ways in which the organization can elect the
officers.
The Product Rule
Example: There are four bus lines between A and B; and
three bus lines between B and C.
Find the number of ways a person can travel:
a) By bus from A to C by way of B;
b) Round trip by bus from A to C by way of B;
c) Round trip by bus from A to C by way of B, if
the person does not want to use a bus line more
than once.
The Product Rule
a) By bus from A to C by way of B;
Solution:

There are 4 ways to go from A to B and 3 ways to go


from B to C; hence there are 4 × 3 = 12 ways to go from
A to C by way of B.
The Product Rule
b) Round trip by bus from A to C by way of B;
Solution:
The person will travel from A to B to C to B to A for the
round trip. i.e. (A →B →C →B →A)

The person can travel 4 ways from A to B and 3 way


from B to C and back.
Thus there are 4 ×3 ×3 × 4 = 144 ways to travel the
round trip.
The Product Rule
c) Round trip by bus from A to C by way of B, if the
person does not want to use a bus line more than once.
Solution:

The person can travel 4 ways from A to B and 3 ways


from B to C, but only 2 ways from C to B and 3 ways
from B to A, since bus line cannot be used more than
once. Hence there are
4 ×3 ×2 × 3 = 72 ways
to travel the round trip without using a bus line more
than once.
The Product Rule
Example: A bit string is a sequence of 0’s and 1’s.How many
bit string are there of length 4?

Solution:
Each bit (binary digit) is either 0 or 1.
Hence, there are 2 ways to choose each bit. Since we have
to choose four bits therefore,

the product rule shows, there are a total of different bit


strings of length four.
The Product Rule
Example: How many bit strings of length 8:
(i ) begin with a 1?
(ii) begin and end with a 1?
Solution:
(i) If the first bit (left most bit) is a 1, then it can be
filled in only one way. Each of the remaining seven
positions in the bit string can be filled in 2 ways (i.e.,
either by 0 or 1). Hence, there are

different bit strings of length 8 that begin with a 1.


The Product Rule
(ii) begin and end with a 1?
Solution:
If the first and last bit in an 8 bit string is a 1, then only the
intermediate six bits can be filled in 2 ways, i.e. by a 0 or 1.
Hence there are

different bit strings of length 8 that begin and end with a 1.


The Product Rule
Example: Suppose that an automobile license plate has
three letters followed by three digits.
(a) How many different license plates are possible?
Solution:
Each of the three letters can be written in 26 different ways,
and each of the three digits can be written in 10 different
ways.

Hence, by the product rule, there is a total of


26 × 26 × 26 × 10 × 10 × 10 = 17,576,000
different License plates possible.
The Product Rule
(b) How many license plates could begin with A and end on 0?
Solution:
The first and last place can be filled in one way only, while
each of second and third place can be filled in 26 ways and
each of fourth and fifth place can be filled in 10 ways.

Number of license plates that begin with A and end in 0 are


1 × 26 × 26 × 10 × 10 × 1 = 67600
The Product Rule
(c) How many license plates begin with PQR.
Solution:

Number of license plates that begin with PQR are


1 × 1 × 1 × 10 × 10 × 10 = 1000 ways.
The Product Rule
(d) How many license plates are possible in which all the
letters and digits are distinct?
Solution:
The first letter place can be filled in 26 ways. Since, the
second letter place should contain a different letter than
the first, so it can be filled in 25 ways. Similarly, the third
letter place can be filled in 24 ways. And the digits can be
respectively filled in 10, 9, and 8 ways.
Hence;
number of license plates in which all the letters and digits
are distinct are
26 × 25 × 24 × 10 × 9 × 8 = 11, 232, 000
The Product Rule
(e) How many license plates could begin with AB and have all
three letters and digits distinct.
Solution:

The first two letters places are fixed (to be filled with A and B),
so there is only one way to fill them. The third letter place
should contain a letter different from A & B, so there
are 24 ways to fill it.
The three digit positions can be filled in 10 and 8 ways to have
distinct digits. Hence, desired number of license plates are
1 × 1 × 24 × 10 × 9 × 8 = 17280
Telephone Numbering Plan
Example: The North American numbering plan (NANP) specifies that a
telephone number consists of 10 digits, consisting of a three-digit area code,
a three-digit office code, and a four-digit station code. There are some
restrictions on the digits.
 Let X denote a digit from 0 through 9.
 Let N denote a digit from 2 through 9.
 Let Y denote a digit that is 0 or 1.
 In the old plan (in use in the 1960s) the format was NYX-NNX-XXXX.
 In the new plan, the format is NXX-NXX-XXXX.
How many different telephone numbers are possible under the old plan and
the new plan?

Solution: Use the Product Rule.


 There are 8 ∙2 ∙10 = 160 area codes with the format NYX.
 There are 8 ∙10 ∙10 = 800 area codes with the format NXX.
 There are 8 ∙8 ∙10 = 640 office codes with the format NNX.
 There are 10 ∙10 ∙10 ∙10 = 10,000 station codes with the format XXXX.
Number of old plan telephone numbers: 160 ∙640 ∙10,000 = 1,024,000,000.
Number of new plan telephone numbers: 800 ∙800 ∙10,000 = 6,400,000,000.
NUMBER OF ITERATIONS OF A NESTED LOOP
Example: Determine how many times the inner loop will be
iterated when the following algorithm is implemented and run
For i: = 1 to 4
For j : = 1 to 3
[Statement in body of inner loop. None contain branching
statements that lead out of the inner loop.]
next j
next i
Solution:
The outer loop is iterated four times, and during each iteration of
the outer loop, there are three iterations of the inner loop.
Hence, by product rules the total number of iterations of inner
loop is 4·3=12
Example: Determine how many times the inner loop will
be iterated when the following algorithm is implemented
and run.
for i = 5 to 50
for j: = 10 to 20
[Statement in body of inner loop. None contain branching
statements that lead out of the inner loop.]
next j
next i
Solution:
The outer loop is iterated 50 - 5 + 1 = 46 times and during
each iteration of the outer loop there are 20 - 10 + 1 = 11
iterations of the inner loop. Hence by product rule, the
total number of iterations of the inner loop is 46×11 = 506.
Example: Determine how many times the inner loop will be
iterated when the following algorithm is implemented and run.
for i: = 1 to 4
for j: = 1 to i
[Statements in body of inner loop. None contain branching
statements that lead outside the loop.]
next j
next i
Solution:
The outer loop is iterated 4 times, but during each iteration of the
outer loop, the inner loop iterates different number of times.
For first iteration of outer loop, inner loop iterates 1 times.
For second iteration of outer loop, inner loop iterates 2 times.
For third iteration of outer loop, inner loop iterates 3 times.
For fourth iteration of outer loop, inner loop iterates 4 times.
Hence, total number of iterations of inner loop = 1 + 2 + 3 + 4 = 10.
Combining the Sum and Product Rule
Example: Suppose statement labels in a programming
language can be either a single letter or a letter followed by
a digit. Find the number of possible labels.
Solution:
 First consider variable names one character in length.
Since such names consist of a single letter, there are 26
variable names of length 1.
 Next, consider variable names two characters in length.
Since the first character is a letter, there are 26 ways to
choose it. The second character is a digit, there are 10 ways
to choose it. Hence, to construct variable name of two
characters in length, there are 26×10 = 260 ways.
 Finally, by sum rule, there are 26 + 260 = 286 possible
variable names in the programming language.
Combining the Sum and Product Rule
Example: A computer access code word consists of from
one to three letters of English alphabets with repetitions
allowed. How many different code words are possible.
Solution:
Number of code words of length 1 = 261
Number of code words of length 2 = 262
Number of code words of length 3 = 263
Hence, the total number of code words =
261 + 262 + 263 = 18,278
Counting Passwords
 Combining the sum and product rule allows us to solve more complex problems.
Example: Each user on a computer system has a password, which is six
to eight characters long, where each character is an uppercase letter or a
digit. Each password must contain at least one digit. How many possible
passwords are there?
Solution: Let P be the total number of passwords, and let P6, P7, and P8
be the passwords of length 6, 7, and 8.
 By the sum rule P = P6 + P7 +P8.
Finding P6 directly is difficult. To find P6 it is easier to find the number of
strings of uppercase letters and digits that are six characters long,
including those with no digits, and subtract from this the number of
strings with no digits. By the product rule, the number of strings of six
characters is 366 ,and the number of strings with no digits is 266
Counting Passwords(Continued)
 To find each of P6, P7, and P8 , we find the number of
passwords of the specified length composed of letters and
digits and subtract the number composed only of letters.
We find that:
 P6 = 366 − 266 = 2,176,782,336 − 308,915,776 =1,867,866,560.
 P7 = 367 − 267 = 78,364,164,096 − 8,031,810,176 = 70,332,353,920.
 P8 = 368 − 268 = 2,821,109,907,456 − 208,827,064,576 =2,612,282,842,880.
 Consequently, P = P6 + P7 + P8 = 2,684,483,063,360.
Internet Addresses
 Version 4 of the Internet Protocol (IPv4) uses 32 bits.

 Class A Addresses: used for the largest networks, a 0,followed


by a 7-bit netid and a 24-bit hostid.
 Class B Addresses: used for the medium-sized networks, a
10,followed by a 14-bit netid and a 16-bit hostid.
 Class C Addresses: used for the smallest networks, a
110,followed by a 21-bit netid and a 8-bit hostid.
 Neither Class D nor Class E addresses are assigned as the address
of a computer on the internet. Only Classes A, B, and C are
available.
 1111111 is not available as the netid of a Class A network.
 Hostids consisting of all 0s and all 1s are not available in any
network.
Counting Internet Addresses
Example: How many different IPv4 addresses are available for
computers on the internet?
Solution: Use both the sum and the product rule. Let x be the
number of available addresses, and let xA, xB, and xC denote the
number of addresses for the respective classes.
 To find, xA: 27 − 1 = 127 netids. 224 − 2 = 16,777,214 hostids.
xA = 127∙ 16,777,214 = 2,130,706,178.
 To find, xB: 214 = 16,384 netids. 216 − 2 = 16,534 hostids.
xB = 16,384 ∙ 16, 534 = 1,073,709,056.
 To find, xC: 221 = 2,097,152 netids. 28 − 2 = 254 hostids.
xC = 2,097,152 ∙ 254 = 532,676,608.
 Hence, the total number of available IPv4 addresses is
x = xA + xB + xC
= 2,130,706,178 + 1,073,709,056 + 532,676,608
= 3, 737,091,842.
Not Enough Today !!
The newer IPv6 protocol solves the problem
of too few addresses.
Basic Counting Principles:
Subtraction Rule
Subtraction Rule: If a task can be done either in one
of n1 ways or in one of n2 ways, then the total number
of ways to do the task is n1 + n2 minus the number of
ways to do the task that are common to the two
different ways.
 Also known as, the principle of inclusion-exclusion:
Counting Bit Strings
Example: How many bit strings of length eight start
either with a 1 bit or end with the two bits 00?
Solution: Use the subtraction rule.
 Number of bit strings of length eight
that start with a 1 bit: 27 = 128
 Number of bit strings of length eight
that end with bits 00: 26 = 64
 Number of bit strings of length eight
that start with a 1 bit and end with bits 00 : 25 = 32
Hence, the number is 128 + 64 − 32 = 160.
Counting Functions
Counting Functions: How many functions are there from a
set with m elements to a set with n elements?
Solution: Since a function represents a choice of one of the n
elements of the codomain for each of the m elements in the
domain, the product rule tells us that there are n ∙ n ∙ ∙ ∙ n =
nm such functions.

Counting One-to-One Functions: How many one-to-one


functions are there from a set with m elements to one with n
elements?
Solution: Suppose the elements in the domain are
a1, a2,…, am. There are n ways to choose the value of a1 and
n−1 ways to choose a2, etc. The product rule tells us that there
are n(n−1) (n−2)∙∙∙(n−m +1) such functions.
Tree Diagrams
 Tree Diagrams: We can solve many counting problems
through the use of tree diagrams, where a branch
represents a possible choice and the leaves represent
possible outcomes.
 Example: Suppose that “I Love Discrete Math” T-shirts
come in five different sizes: S,M,L,XL, and XXL. Each size
comes in four colors (white, red, green, and black),
except XL, which comes only in red, green, and black,
and XXL, which comes only in green and black. What is
the minimum number of shirts that the campus book
store needs to stock to have one of each size and color
available?
Tree Diagrams
 Solution: Draw the tree diagram.

 The store must stock 17 T-shirts.


Section 6.2
Section Summary
 The Pigeonhole Principle
 The Generalized Pigeonhole Principle
The Pigeonhole Principle
Pigeonhole Principle: If k is a positive
integer and k + 1 objects are placed into k
boxes, then at least one box contains two or
more objects.
Proof: We use a proof by contraposition.
Suppose none of the k boxes has more than
one object. Then the total number of objects
would be at most k. This contradicts the
statement that we have k + 1 objects.
The Pigeonhole Principle
 If a flock of 20 pigeons roosts in a set of 19
pigeonholes, one of the pigeonholes must have more
than 1 pigeon.
The Pigeonhole Principle
Corollary 1: A function f from a set with k + 1
elements to a set with k elements is not one-to-one.
Proof: Use the pigeonhole principle.
 Create a box for each element y in the codomain of f .
 Put in the box for y all of the elements x from the
domain such that f(x) = y.
 Because there are k + 1 elements and only k boxes, at
least one box has two or more elements.
Hence, f can’t be one-to-one.
The Generalized Pigeonhole Principle
The Generalized Pigeonhole Principle: If N objects are
placed into k boxes, then there is at least one box
containing at least ⌈N/k⌉ objects.
Proof: We use a proof by contraposition. Suppose that
none of the boxes contains more than ⌈N/k⌉ − 1 objects.
Then the total number of objects is at most

where the inequality ⌈N/k⌉ < ⌈N/k⌉ + 1 has been used. This
is a contradiction because there are a total of n objects.
Pigeonhole Principle
Example: Among any group of 367 people, there must
be at least two with the same birthday, because there
are only 366 possible birthdays. ⌈367/366⌉ = 2
Example: Among 100 people there are at least
⌈100/12⌉ = 9 who were born in the same month.
Example: In any set of 27 English , must be at least
two that begin with the same letter, since there are 26
letters in the English alphabet. ⌈27/26⌉ = 2
The Generalized Pigeonhole Principle
Example: What is the minimum number of students required
in a Discrete Mathematics class to be sure that at least six will
receive the same grade, if there are five possible grades, A, B, C,
D, and F.
Solution:
The minimum number of students needed to guarantee that at
least six students receive the same grade is the smallest integer
N such that ⌈ N/K ⌉ = ⌈ N/5 ⌉ = 6. The smallest such integer is
N = K(⌈ N/K ⌉-1)+1 = 5(6-1)+1=5 ⋅ 5 + 1 = 26.
Thus 26 is the minimum number of students needed to be sure
that at least 6 students will receive the same grades.
Section 6.3
Section Summary
 Permutations
 Combinations
 Combinatorial Proofs
Permutations
Definition: A permutation of a set of distinct objects
is an ordered arrangement of these objects. An ordered
arrangement of r elements of a set is called an
r-permutation.
Example: Let S = {1,2,3}.
 The ordered arrangement 3,1,2 is a permutation of S.
 The ordered arrangement 3,2 is a 2-permutation of S.
 The number of r-permutations of a set with n
elements is denoted by P(n,r).
 The 2-permutations of S = {1,2,3} are 1,2; 1,3; 2,1; 2,3;
3,1; and 3,2. Hence, P(3,2) = 6.
A Formula for the Number of
Permutations
Theorem 1: If n is a positive integer and r is an integer with
1 ≤ r ≤ n, then there are
P(n, r) = n(n − 1)(n − 2) ∙∙∙ (n − r + 1)
r-permutations of a set with n distinct elements.
Proof: Use the product rule. The first element can be chosen in n
ways. The second in n − 1 ways, and so on until there are
(n − ( r − 1)) ways to choose the last element.
 Note that P(n,0) = 1, since there is only one way to order zero
elements.
Corollary 1: If n and r are integers with 1 ≤ r ≤ n, then
Solving Counting Problems by
Counting Permutations
Example: How many ways are there to select a first-
prize winner, a second prize winner, and a third-prize
winner from 100 different people who have entered a
contest?

Solution:
P(100,3) = 100 ∙ 99 ∙ 98 = 970,200
Solving Counting Problems by
Counting Permutations (continued)
 Example: Suppose that there are eight runners in a race.
The winner receives a gold medal, the second place
finisher receives a silver medal, and the third-place
finisher receives a bronze medal. How many different
ways are there to award these medals, if all possible
outcomes of the race can occur and there are no ties?
 Solution: The number of different ways to award the
medals is the number of 3-permutations of a set with
eight elements. Hence, there are
P(8, 3) = 8 · 7 · 6 = 336
possible ways to award the medals.
Solving Counting Problems by
Counting Permutations (continued)
Example: Suppose that a saleswoman has to visit eight
different cities. She must begin her trip in a specified city,
but she can visit the other seven cities in any order she
wishes. How many possible orders can the saleswoman use
when visiting these cities?

Solution: The first city is chosen, and the rest are ordered
arbitrarily. Hence the orders are:
P(7,7)= 7! = 7 ∙ 6 ∙ 5 ∙ 4 ∙ 3 ∙ 2 ∙ 1 = 5040
If she wants to find the tour with the shortest path that
visits all the cities, she must consider 5040 paths!
Solving Counting Problems by
Counting Permutations (continued)
Example: How many permutations of the letters
ABCDEFGH contain the string ABC ?

Solution: We solve this problem by counting the


permutations of six objects, ABC, D, E, F, G, and H.

P(6,6)= 6! = 6 ∙ 5 ∙ 4 ∙ 3 ∙ 2 ∙ 1 = 720
Combinations
Definition: An r-combination of elements of a set is
an unordered selection of r elements from the set.
Thus, an r-combination is simply a subset of the set
with r elements.
 The number of r-combinations of a set with n distinct
elements is denoted by C(n, r).

 The notation is also used and is called a binomial


coefficient. (We will see the notation again in the
binomial theorem in Section. 6.4)
Combinations
Example:
 Let S be the set {a, b, c, d}. Then {a, c, d} is a 3-
combination from S. It is the same as {d, c, a} since the
order listed does not matter.
 C(4,2) = 6 because the 2-combinations of {a, b, c, d}
are the six subsets {a, b}, {a, c}, {a, d}, {b, c}, {b, d},
and {c, d}.
Combinations
Theorem 2: The number of r-combinations of a set
with n elements, where n ≥ r ≥ 0, equals

Proof: By the product rule P(n, r) = C(n,r) ∙ P(r,r).


Therefore,
Combinations
Example: How many poker hands of five cards can be
dealt from a standard deck of 52 cards? Also, how many
ways are there to select 47 cards from a deck of 52
cards?
Solution: Since the order in which the cards are dealt
does not matter, the number of five card hands is:

 The different ways to select 47 cards from 52 is

This is a special case of a general result. →


Combinations
Corollary 2: Let n and r be nonnegative integers with
r ≤ n. Then C(n, r) = C(n, n − r).
Proof: From Theorem 2, it follows that

and

Hence, C(n, r) = C(n, n − r).

This result can be proved without using algebraic manipulation. →


Combinatorial Proofs
 Definition 1: A combinatorial proof of an identity is a
proof that uses one of the following methods.
 A double counting proof uses counting arguments to
prove that both sides of an identity count the same
objects, but in different ways.
 A bijective proof shows that there is a bijection between
the sets of objects counted by the two sides of the
identity.
Combinatorial Proofs
 Here are two combinatorial proofs that
C(n, r) = C(n, n − r)
when r and n are nonnegative integers with r < n:
 Bijective Proof: Suppose that S is a set with n elements. The
function that maps a subset A of S to is a bijection between
the subsets of S with r elements and the subsets with n − r
elements. Since there is a bijection between the two sets, they
must have the same number of elements.
 Double Counting Proof: By definition the number of subsets of
S with r elements is C(n, r). Each subset A of S can also be
described by specifying which elements are not in A, i.e., those
which are in . Since the complement of a subset of S with r
elements has n − r elements, there are also C(n, n − r) subsets
of S with r elements.
Combinations
Example: How many ways are there to select five players
from a 10-member tennis team to make a trip to a match at
another school.
Solution: By Theorem 2, the number of combinations is

Example: A group of 30 people have been trained as


astronauts to go on the first mission to Mars. How many
ways are there to select a crew of six people to go on this
mission?
Solution: By Theorem 2, the number of possible crews is
Section 6.4
Section Summary
 The Binomial Theorem
 Pascal’s Identity and Triangle
Binomial Theorem
Binomial Theorem: Let x and y be variables, and n a
nonnegative integer. Then:

Proof: We use combinatorial reasoning . The terms in


the expansion of (x + y)n are of the form xn−jyj for
j = 0,1,2,…,n. To form the term xn−jyj, it is necessary to
choose n−j xs from the n sums. Therefore, the
coefficient of xn−jyj is which equals .
Powers of Binomial Expressions
Definition: A binomial expression is the sum of two terms, such as x + y.
(More generally, these terms can be products of constants and variables.)
 We can use counting principles to find the coefficients in the expansion of (x +
y)n where n is a positive integer.
 To illustrate this idea, we first look at the process of expanding (x + y)3.
 (x + y) (x + y) (x + y) expands into a sum of terms that are the product of a term
from each of the three sums.
 Terms of the form x3, x2y, x y2, y3 arise. The question is what are the coefficients?
 To obtain x3 , an x must be chosen from each of the sums. There is only one way
to do this. So, the coefficient of x3 is 1.
 To obtain x2y, an x must be chosen from two of the sums and a y from the other.
There are ways to do this and so the coefficient of x2y is 3.
 To obtain xy2, an x must be chosen from of the sums and a y from the other two .
There are ways to do this and so the coefficient of xy2 is 3.
 To obtain y3 , a y must be chosen from each of the sums. There is only one way to
do this. So, the coefficient of y3 is 1.
 We have used a counting argument to show that (x + y)3 = x3 + 3x2y + 3x y2 +
y3 .
 Next we present the binomial theorem gives the coefficients of the terms in the
expansion of (x + y)n .
Using the Binomial Theorem
Example:
Using the Binomial Theorem
Using the Binomial Theorem
Example: What is the coefficient of x12y13 in the
expansion of (2x − 3y)25?
Solution: We view the expression as (2x +(−3y))25.
By the binomial theorem

Consequently, the coefficient of x12y13 in the expansion


is obtained when j = 13.
A Useful Identity
Corollary 1: With n ≥0,

Proof (using binomial theorem): With x = 1 and y = 1, from the


binomial theorem we see that:

Proof (combinatorial): Consider the subsets of a set with n


elements. There are subsets with zero elements, with one
element, with two elements, …, and with n elements.
Therefore the total is

Since, we know that a set with n elements has 2n subsets, we


conclude:
Blaise Pascal
(1623-1662)

Pascal’s Identity
Pascal’s Identity: If n and k are integers with n ≥ k ≥ 0, then

Proof (combinatorial): Let T be a set where |T| = n + 1, a ∊T, and


S = T − {a}. There are subsets of T containing k elements.
Each of these subsets either:
 contains a with k − 1 other elements, or
 contains k elements of S and not a.
There are
 subsets of k elements that contain a, since there are
subsets of k − 1 elements of S,
 subsets of k elements of T that do not contain a, because there
are subsets of k elements of S.
See Exercise 19
Hence,
for an algebraic
proof.
Pascal’s Triangle
The nth row in
the triangle
consists of the
binomial
coefficients ,
k = 0,1,….,n.

By Pascal’s identity, adding two adjacent bionomial coefficients results is the


binomial coefficient in the next row between these two coefficients.

You might also like