Math132 Lectures
Math132 Lectures
Beifang Chen
Contents
Chapter 4. Combinatorics 39
4.1. Counting Principle 39
4.2. Permutations 39
4.3. Combination 42
4.4. Combination with Repetition 45
4.5. Combinatorial Proof 46
4.6. Pigeonhole Principle 50
4.7. Relation to Probability 51
4.8. Inclusion-Exclusion Principle 53
4.9. More Examples 57
4.10. Generalized Inclusion-Exclusion Formula 59
Set Theory
Example 1.1. The power set of the set A = {a, b, c} is the set
n o
P(A) = , {a}, {b}, {c}, {a, b}, {a, c}, {b, c}, {a, b, c} .
The Cartesian product (or just product) of two sets A and B, written AB,
is the set consisting of all ordered pairs (a, b), where a A and b B, that is,
AB = {(a, b) | a A and b B}.
The product of a finite family of sets A1 , . . . , An is the set
Yn n o
Ai = A1 An = (a1 , . . . , an ) | a1 A1 , . . . , an An ,
i=1
Example 1.2. For sets A = {0, 1}, B = {a, b, c}, the product A and B is the
set
A B = {(0, a), (0, b), (0, c), (1, a), (1, b), (1, c)};
and the product and A3 = A A A is the set
(0,1,0)???
A3 = {(0, 0, 0), (0, 0, 1), (0, 1, 1), (1, 0, 0), (1, 0, 1), (1, 1, 0), (1, 1, 1)}.
For the set R of real numbers, the product R2 is the 2-dimensional coordinate plane
and R3 is the 3-dimensional coordinate space.
A sequence of a nonempty set A is a list of finite or infinite number of objects
of A in order:
a1 , a2 , . . . , an (finite sequence)
a1 , a2 , . . . (infinite sequence)
where a1 , a2 , . . . A. The sequence is called finite in the former case and infinite
in the latter case. A word of length n over a nonempty set A is a string
a1 a2 an ,
where a1 , a2 , . . . , an A. The string
a1 a2
with a1 , a2 , . . . A is called a word of infinite length over A. There is a unique
word of length zero, called the empty word, and is denoted by . The sets of all
words of length n, of finite length, and of infinite length over A are denoted by
A(n) , A , and A() ,
1.3. FUNCTIONS 9
1.3. Functions
Definition 1.2. Let X and Y be nonempty sets. A function f from X to Y ,
written
f : X Y,
is a rule that associates each element x X with a unique element y Y , denoted
y = f (x).
When this rule f is given, the sets X, Y , and f (X) = {f (x) | x X} are called the
domain, the codomain, and the range of f , respectively; the element y(= f (x)) is
called the image (or value) of x, and x is called the inverse image (or preimage)
of y under f . Functions are also called mappings or just maps.
Note that for a function y = f (x) in calculus, the variable x is called the
independent variable and y is called the dependent variable.
Let f : X Y be a function from a set X to a set Y . It can be viewed as a
black-box device
x f f (x),
where the input x is in X and the output f (x) is to be in Y . For a subset A X,
the image of A under f is the set
f (A) := {y Y | there is a A such that y = f (a)};
and for a subset B Y , the inverse image of B under f is the set
f 1 (B) := {x X | there is b B such that b = f (x)}.
The graph of f is the set
(f ) = {(x, y) X Y | y = f (x)}.
The set of all functions from a set A to a set B is sometimes denoted by B A ; that
is,
B A := {f | f : A B}.
10 1. SET THEORY
F ig.
The identity function of a set X is the function idX : X X such that
idX (x) = x for all x X.
Definition 1.6. A function f : X Y is called invertible if there exists a
function g : Y X such that for any x X and y Y ,
g(f (x)) = x and f (g(y)) = y.
In other words, g f = idX and f g = idY ; the function g is called an inverse of
f , and is denoted by f 1 .
Example 1.6. Some invertible and non-invertible functions.
(1) The function f : R R, f (x) = x3 , is invertible; its inverse is the function
g : R R, g(x) = 3 x.
(2) The function f : R R+ , f (x) = ex , is invertible; its inverse is the
function g : R+ R, g(x) = log x.
(3) The function f : R R, f (x) = x2 , is not invertible. However, the
2
function f1 : R0 R0 , f1 (x) = x , is invertible, and its inverse is the
function g1 : R0 R0 , g1 (x) = x. The function f2 : R0 R0 ,
f2 (x) = x2 , is invertible; its inverse is g2 : R0 R0 , g2 (x) = x.
(4) The function f : R [1, 1], f (x) = sin x, is not invertible. However,
f1 : [ 2 , 2 ] [1, 1], f1 (x) = sin x, is invertible, and has the inverse
g1 : [1, 1] [ 2 , 2 ], g1 (x) = arcsin x.
Theorem 1.7. A function f : X Y is invertible if and only if f is one-to-one
and onto.
Proof. : Since f is invertible, there is a function g : Y X such that
g f = idX and f g = idY . Suppose f is not one-to-one. Then there are x1 , x2 X
such that f (x1 ) = f (x2 ). Thus x1 = g(f (x1 )) = g(f (x2 )) = x2 , a contradiction. So
f is one-to-one. On the other hand, for any y Y , we have an element g(y) X
and f (g(y)) = y. This means that f is onto.
: Since f is one-to-one and onto, then for any y Y there is one and
only one element x X such that f (x) = y. We define a function g : Y X
by g(y) = x, where x is the unique element of X such that f (x) = y. Then
(g f )(x) = g(f (x)) = g(y) = x and (f g)(y) = f (g(y)) = f (x) = y. Thus
g f = idX and f g = idY .
Exercise 7. Show that if f : X Y is invertible, then the inverse function
of f is unique.
Exercise 8. Let f : X Y be a function. Let Ai , i I, be a family of
subsets of X. Show that
T T
(1) f SiI Ai iI f (Ai );
S
(2) f T iI Ai = f (Ai );
T
iI
(3) f SiI Ai = iI f 1 (Ai );
1
S
(4) f 1 iI Ai = iI f
1
(Ai ).
Exercise 9. Let f : X Y and g : Y Z be functions. Show that
(1) If f and g are one-to-one, then g f is one-to-one;
1.5. INFINITE SETS 13
f k = f (k1) f 1 = f 1 f 1 f 1 .
| {z }
k
Exercise 13. For real numbers a, b R such that a < b, find a one-to-one
correspondence between the open interval (a, b) and the closed interval [a, b], where
(a, b) = {x R | a < x < b} and [a, b] = {x R | a x b}.
Exercise 14. Show that the union of countably many countable sets is still
countable.
S That is, if Ai are countable sets, i = 1, 2, . . ., not necessarily disjoint,
then i=1 Ai is countable.
Exercise 15. Let A be a countable set. Show that A is countable.
Exercise 16. Let A be a set with at least two elements. Show that A is in
one-to-one correspondent with a subset of A() .
Exercise 17. Let B = {0, 1} and let B = {a1 a2 | a1 , a2 , . . . B} be the
set of words with infinite length. Show that B is uncountable.
1.6. Permutations
A bijective function from a finite set A to itself is called a permutation of A.
If A = {a1 , a2 , . . . , an } is a set of n objects and f : A A is a permutation, then
f (a1 ), f (a2 ), . . . , f (an )
is the same collection of a1 , a2 , . . . , an , and may be in different order. Let
f (a1 ) = ai1 , f (a2 ) = ai2 , . . . , f (an ) = ain .
The permutation f is usually expressed by the array
a1 a2 . . . an
f=
ai1 ai2 . . . ain
and sometimes by the word
ai1 ai2 ain .
Let a be an element of A. The sequence
a, f (a), f 2 (a), f 3 (a), . . .
must eventually return to a and then repeat the pattern. Let k be the smallest
positive integer such that f k (a) = a. The sequence a, f (a), f 2 (a), . . . , f k1 (a) is
called a cycle of length k of the permutation f , and is denoted by
a f (a) f 2 (a) f k1 (a) .
Of course,
f (a) f 2 (a) f k (a) , f 2 (a) f 3 (a) f k+1 (a) , . . .
are also cycles of f . However, they are viewed as the same cycle. For instance, for
the set A = {1, 2, 3, 4, 5, 6, 7, 8}, the permutation
1 2 3 4 5 6 7 8
=
6 7 5 4 3 8 2 1
has four cycles (168), (27), (53), (4). The permutation can be written as (681)(27)(53)(4).
However, the way of writing in this fashion is not unique. We may make this
kind of writing unique by requiring that the leading element of each cycle to be the
largest element inside the cycle and requiring that all leading elements of cycles to
be increasing. Hence the permutation can be uniquely written in the cycle
= (4)(53)(72)(816).
16 1. SET THEORY
Number Theory
2.1. Divisibility
Leopold Kronecker said: God created integers, all else are the work of man.
We assume that the set of integers are well defined and we are familiar with the
properties of integers such as addition, subtraction, multiplication, and division. In
particular, we assume the following axiom for subsets of integers bounded below.
Axiom. For every nonempty subset of integers, if it is bounded below, then it
has a unique minimum integer.
It follows easily from the axiom that for every subset of integers, if it is bounded
above, then it has a unique maximum integer. Given two integers a and b with
a 6= 0, we say that a divides b, written a|b, if there exists an integer q such that
b = qa.
When this is true we say that a is a factor (or divisor) of b, and say that b is
a multiple of a. Obviously, any integer n has divisors, 1 and n, called the
trivial divisors of n. The divisors of n other than the trivial divisors are called
nontrivial divisors. Note that every integer is a divisor of 0. A positive integer
p (6= 1) is called a prime if its positive divisors are only the trivial divisors 1 and
p. A positive integer is called composite if it is not a prime. The first few primes
are listed as follows:
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 57.
Proposition 2.1. Let a, b, c be nonzero integers.
(a) If a|b and b|a, then a = b.
(b) If a|b and b|c, then a|c.
(c) If a|b and a|c, then a|(bx + cy) for x, y Z.
Proof. (a) Let b = q1 a and a = q2 b for some integers q1 and q2 . Then
b = q1 q2 b.
Dividing both sides by b, we have q1 q2 = 1. It follows that q1 = q2 = 1. Thus
b = a.
(b) Let b = q1 a and c = q2 b for some integers q1 and q2 . Then c = q1 q2 a, that
is, a|c.
(c) Let b = q1 a and c = q2 a for q1 , q2 Z. Then for x, y Z,
bx + cy = (q1 x + q2 y)a,
that is, a|(bx + cy).
Theorem 2.2. There are infinitely many prime numbers.
19
20 2. NUMBER THEORY
Proof. Suppose there are finitely many primes, say, p1 , p2 , . . . , pk . Then the
integer
a = p1 p2 p k + 1
is not divisible by any of the primes p1 , p2 , . . . , pk because the remainders of a
dividing by p1 , p2 , . . . , pk respectively are always 1. This means that a has no
prime factors. By definition of primes, the integer a must be a prime, and this
prime is larger than all primes p1 , p2 , . . . , pk , a contradiction.
Theorem 2.3 (Division Algorithm). For any integers a and b, where a > 0,
there are unique integers q and r such that
b = qa + r, 0 r < a.
Proof. Consider the set S = {b ta 0 | t Z}. Obviously, S is nonempty
and is bounded below. Then S has the unique minimum element r, that is, there
is an unique integer q such that b qa = r. We claim that r < a. Suppose r a,
then b (q + 1)a = r a 0 shows that r a is an element of S. This is contrary
to that r is the minimum element of S.
Proof. Let d1 = gcd(a, b) and let d2 = gcd(a, r). Obviously, d1 |a; d1 |r because
r = b qa and d1 |b. This means that d1 is a common divisor of a and r. Thus
d1 d2 . On the other hand, d2 |a; d2 |b because b = qa + r and d2 |r. This means
that d2 is a common divisor of a and b. Hence, d2 d1 . Therefore d1 = d2 .
The above proposition gives rise a simple constructive method to calculate gcd
by repeating the Division Algorithm. For example, gcd(297, 3627) can be calculated
as follows:
3627 = 12 297 + 63,
297 = 4 63 + 45,
63 = 1 45 + 18,
45 = 2 18 + 9,
18 = 2 9;
The procedure to calculate gcd(297, 3627) applies to any pair of nonnegative in-
tegers. Let a be a positive integer and b a nonnegative integer. Repeating the
Division Algorithm will produce finite sequences of nonnegative integers qi and ri
such that
b = q 0 a + r0 , 0 r0 < a,
a = q 1 r0 + r1 , 0 r1 < r0 ,
r0 = q 2 r1 + r2 , 0 r2 < r1 ,
r1 = q 3 r2 + r3 , 0 r3 < r2 ,
..
.
rk2 = qk rk1 + rk , 0 rk < rk1 ,
rk1 = qk+1 rk + rk+1 , rk+1 = 0.
Notice that the sequence {ri } is strictly decreasing; it ends eventually to 0 at some
step, say, the remainder rk+1 becomes zero in the very first time, i.e., rk+1 = 0 and
ri 6= 0 for all 0 i k. Reverse the sequence {ri }ki=0 and make substitutions as
follows:
gcd(a, b) = rk ,
rk = rk2 qk rk1 ,
rk1 = rk3 qk1 rk2 ,
..
.
r1 = a q 1 r0 ,
r0 = b q0 a.
Example 2.1. The greatest common divisor of 297 and 3627, written as an
integral linear combination of 297 and 3627, can be obtained as follows:
gcd(297, 3627) = 45 2 18
= 45 2(63 45)
= 3 45 2 63
= 3(297 4 63) 2 63
= 3 297 14 63
= 3 297 14(3627 12 297)
= 171 297 14 3627.
Proposition 2.6. For integers a, b, c, if a|bc and gcd(a, b) = 1, then a|c.
Proof. By the Euclidean Algorithm, there are integers x and y such that
ax + by = 1. Then
c = 1 c = (ax + by)c = acx + bcy.
It is clear that a|c because a|ac and a|bc.
Theorem 2.7 (Unique Factorization). Every integer a 2 can be uniquely
factorized into the form
a = pe11 pe22 pemm ,
where p1 , p2 , . . . , pm are distinct primes, e1 , e2 , . . . , em are positive integers, and
p1 < p 2 < < p s .
Proof. If a has only the trivial divisors, then a itself is a prime, and it obvi-
ously has unique factorization. If a has some nontrivial divisors, then
a = bc
for some positive integers b and c other than 1 and a. Obviously, b < a and
c < a. By induction, the positive integers b and c have factorizations into primes.
Consequently, a has a factorization into primes.
Let a = q1f1 q2f2 afnn be another factorization, where q1 , q2 , . . . , qn are distinct
primes, f1 , f2 , . . . , fn are positive integers, and q1 < q2 < < qn . We claim that
m = n, pi = qi , ei = fi for all 1 i m.
Suppose p1 < q1 . Then p1 is distinct from the primes q1 , q2 , . . . , qn . It is
clear that gcd(p1 , qi ) = 1 and so gcd(p1 , qifi ) = 1 for all 1 i n. Note that
p1 |q1f1 q2f2 afnn . Since gcd(p1 , q1f1 ) = 1, by Proposition 2.6, we have p1 |q2f2 afnn .
Since gcd(p1 , q2f2 ) = 1, again by Proposition 2.6, we have p1 |q3f2 afnn . Repeating
the argument, we finally obtain that p1 |qnfn , which is contrary to gcd(p1 , qnfn ) = 1.
We thus conclude that p1 q1 . Similarly, p1 q1 . Hence p1 = q1 . Next we claim
that e1 = f1 .
Suppose e1 < f1 . Then
pe22 pemm = pf11 e1 q2f2 qnfn .
This implies that p1 |pe22 pemm . If m = 1, it would imply that p1 divides 1, which
is impossible because p1 is a prime. If m 2, note that gcd(p1 , pi ) = 1 and so
gcd(p1 , pei i ) = 1 for all 2 i m; by the same token of applying Proposition 2.6
repeatedly, we have p1 |pemm , which is contrary to gcd(p1 , pemm ) = 1. This means that
we must have e1 f1 . Similarly, e1 f1 . Hence e1 = f1 .
Now we have obtained pe22 pemm = q2f2 qnfn . If m < n, then by induction we
fm+1
have p1 = q1 , . . . , pm = qm and e1 = f1 , . . . , em = fm . Thus 1 = qm+1 qnfn ; this
2.3. LEAST COMMON MULTIPLE 23
Proof. It is clear that (x, y) = (u, v) + d1 (kb, ka) are integer solutions. We
only need to show that all integer solutions of ax + by = 0 are of the form
k
(x, y) = (b, a).
d
Since ax = by, we have a|by and b|ax. This means that ax and by are both
common multiples of a and b. Thus lcm(a, b) is a common divisor of ax and by,
that is, ax = k lcm(a, b) and by = k lcm(a, b) for some k Z. Thus
( k lcm(a,b) bk
x = a = gcd(a,b)
y = k lcm(a,b)
b
ak
= gcd(a,b) .
The inverse of f[a] is the map f[a]1 = f[b] , where [a][b] = [1]. Then
[u] = [a1 ][a2 ] [am ] = [aa1 ][aa2 ] [aam ] = [am ][a1 ][a2 ] [am ]
Thus [am ] = [1]. This means that a(n) 1 (mod n).
Corollary 2.16 (Fermats Little Theorem). Let p be a prime. If p - a,
then
ap1 1 (mod p).
Proof. Apply the Euler Theorem and (p) = p 1.
Propositional Logic
3.1. Statements
By a mathematical statement (or just statement) we mean a declarative
sentence that is either true or false, but not both. The truth value (true or
false) for any statement can be determined and is not ambiguous in any sense. For
example, the following sentences are statements.
(1) Today is 1st of July 1997.
(2) The course number of Discrete Structure in HKUST is Math132.
(3) The equation x2 + y 2 = z 2 has no positive integer solutions.
(4) There are 7,523,804 people in Hong Kong.
However, many sentences in daily life languages are not mathematical statements.
For instance, the following sentences are not mathematical statements.
(1) How are you?
(2) Hong Kong is a big city.
(3) What a beautiful campus!
(4) This sentence is false.
For the last sentence above, if we say that the sentence is true, then it is false. If, on
the other hand, we claim that the sentence is false, then it is true. Such sentences
will not be considered as mathematical statements. Statements are usually denoted
by lowercase letters such as p, q, r, . . ., etc.
3.2. Connectives
Given several statements, we wish to set up rules by which we can decide the
truth of various combinations of the given statements. New statements can be
formed by using connectives not, and, and or.
The Negation of a statement p is the statement not p, denoted p. The
truth values of p are given by the table
p p
T F
F T
The conjunction of two statements p and q is the statement p and q, denoted
p q. Its truth values are given by the table
p q pq
T T T
T F F
F T F
F F F
29
30 3. PROPOSITIONAL LOGIC
3.3. Tautology
A statement is called a tautology if it is always true for all possible values of its
propositional variables; a contradiction if it is always false; and a contingency if
it can be either true or false, depending on the truth values of its propositional vari-
ables. For instance, (p q) q is a tautology; (p q) p q is a contradiction;
and (p q) p is a contingency.
Two statements p and q are said to be logically equivalent or simply equiv-
alent, written p q or even p = q, if p q is a tautology; that is, p and q have
the same truth values.
Proposition 3.1. Let p, q, r be arbitrary statements. Then
(1) p q q p
(2) p q q q
(3) p (q r) (p q) r
(d) p (q r) (p q) r
(4) p (q r) (p q) (p r)
(5) p (q q) (p q) (p r)
(6) p p p
(7) p p p
32 3. PROPOSITIONAL LOGIC
(8) (p) p
(9) (p q) p q
(10) (p q) p q
Example 3.3. (p q) (p) q is a tautology.
p q pq p p q (p q) (p q)
T T T F T T
T F F F F T
F T T T T T
F F T T T T
Example 3.4. (p q) (q p) is a tautology.
p q pq q p q p (p q) (q p)
T T T F F T T
T F F T F F T
F T T F T T T
F F T T T T T
For instance, let us consider the statement
If I got SARS, then I stayed in hospital.
Let p denote I got SARS and let q denote I stayed in hospital. One feel that
statement If I got SARS, then I stayed in hospital is logically equivalent to the
statement
If I didnt stay in hospital, then I didnt get SARS.
It is also logically equivalent to
I didnt get SARS or I stayed in hospital.
Theorem 3.2. (1) (p q) (p) q
(2) (p q) (q p)
(3) (p q) (p q) (q p)
Theorem 3.3. (1) (x P (x)) x P (x)
(2) (x P (x)) x P (x)
(3) x (P (x) Q(x)) (x P (x)) (x Q(x))
(4) x (P (x) Q(x)) (x P (x)) (x Q(x))
(5) (x P (x)) (x Q(x)) x (P (x) Q(x)) is a tautology.
(6) x (P (x) Q(x)) (x P (x)) (x Q(x)) is a tautology.
(7) ((x P (x)) (x Q(x))) x (P (x) Q(x)) is a tautology.
(8) x (P (x) Q(x)) (x P (x)) (x Q(x))
Proof. (1)-(4) are trivial.
(5) If the statement (x P (x)) (x Q(x)) has T value, then (x P (x)) = T or
(x Q(x)) = T , say (x P (x)) = T . Obviously, (x P (x) Q(x)) = T . Note that
(x P (x)) (x Q(x)) and (x P (x) Q(x)) are not equivalent.
(6) It is an equivalent form of (5).
(7) (x P (x)) (x Q(x)) (x P (x))(x Q(x)) (x P (x))(x Q(x));
x (P (x) Q(x)) x (P (x) Q(x)). The tautology follows from (5).
3.4. METHODS OF PROOF 33
Example 3.5. If two integers a and b are even, then their sum a + b is even.
Proof.
Statement Reason
1. a = 2a0 , b = 2b0 . Hypothesis and the definition of even
2. a + b = 2a0 + 2b0 . Step 1 and the meaning of = and +
3. a + b = 2(a0 + b0 ) = 2c. Factoring
4. a + b is even. Step 3 and the definition of even
Note that we have not yet proved that a + b is even; we have simply proved If a
and b are even, then a + b is even. The above informal argument can be made into
the following formal argument.
Symbol Statement Reason
1. p a and b are even. Hypothesis
2. p q If a and b are even, then Definition of even
a = 2a0 and b = 2b0 .
3. q r If a = 2a0 and b = 2b0 , Meaning of = and +
then a + b = 2a0 + 2b0 .
4. p r If a and b are even, then Steps 2 and 3, and
a + b = 2a0 + 2b0 the Law of the Syllogism
5. r s If a + b = 2a0 + 2b0 , then Factoring
a + b = 2(a0 + b0 ) = 2c.
6. p s If a and b are even, then Steps 4 and 5, and
a + b = 2c. the Law of the Syllogism
7. s t If a + b = 2c, then a + b Definition of even
is even.
8. p t If a and b are even, then Steps 6 and 7, and
a + b is even the Law of Syllogism
9. t a + b is even. Steps 1 and 8, and
the Rule of Detachment
Proof.
Statement Reason
1. n = 2m + 1 Definitiomn of odd
2. n2 = (2m + 1)2 = 4m2 + 4m + 1 Meaning of =, +; and
= 2(2m2 + 2m) + 1 = 2M + 1 using of algebra
3. n2 is odd Step 2 and definition of odd
The informal argument can be made into the following formal argument.
Symbol Statement Reason
1. q n is not even. Denying
2. q r If n is not even, then n = 2m + 1. Meaning of not even
3. r s If n = 2m + 1, then Using of algebra
n2 = 2(2m2 + 2m) + 1 = 2M + 1.
4. q s If n is not even, then n2 = 2M + 1. Law of Syllogism
5. st If n2 = 2M + 1, then n is odd. Definition of odd
6. q t If n is not even, then n2 = 2M + 1. Law of Syllogism
7. t n2 = 2M + 1. Rule of Detachment
8. p n2 is not even. Meaning of not even
EXERCISES
(1) Consider the statement
If 1 = 4, then 1 = 2.
Proof. Since 1 + 3 = 4 and 1 = 4, we have 0 = 3. Dividing both sides of
0 = 3 by 3, we further have 0 = 1. Hence 1 = 0 + 1 = 1 + 1 = 2. Is the
proof a true argument? What can you conclude from the statement and
proof?
(2) Define the connectives and by
p q pq p q pq
T T F T T F
T F F and T F T
F T F F T T
F F T F F F
respectively. Find the truth tables for
(p q) r, (p q) (p r), (p q) (p r), (p q)p, (pq)(qr).
(3) Let
p : John is a student of Computer Science Department in HKUST.
q : John takes course Math132
Write the English sentences of the converse, inverse and contrapositive
forms for the statement p q. Write the English sentence for the state-
ments
p q, q p
(4) Show that the set {, , } is adequate. Are the sets {, , } and
{, , } adequate?
(5) Show that the statement
(x P (x)) (x Q(x)) x (P (x) Q(x))
is a tautology. Is the converse of the statement a tautology? If yes, prove
it. If no, find a counterexample.
(6) Show that if statements p and p q are tautologies then q is a tautology.
Give a daily life example of the argument.
(7) Express p q and pq in terms of p, q, and other connectives without
and .
(8) If p q and q r are tautologies, then p r is a tautology.
(9) If p q and q are tautologies, then p is a tautology.
CHAPTER 4
Combinatorics
4.2. Permutations
Let A be a set of n objects. An arrangement of r elements from A in linear
order is called an r-permutation of n objects. The number of r-permutations of
n objects is denoted by P (n, r). In forming an r-permutation of n objects, the 1st
element can be selected in n choices, the 2nd element in n 1 choices, and so on.
Thus
P (n, r) = n(n 1) (n r + 1).
In particular, when r = n, an n-permutation of n objects is simply called a per-
mutation of n objects. The number of permutations of n objects is given by
n! := n(n 1)(n 2) 3 2 1,
39
40 4. COMBINATORICS
Example Find the number of possible seating plans for four persons to be seated
at a round table.
Solution. Let A = {a, b, c, d} be the set of four persons. We denote by X the set
of all permutations of A and by Y the set of all round permutations of A. We
define a map f : X Y such that for any permutation x1 x2 x3 x4 , f (x1 x2 x3 x4 ) is
the round permutation by letting x1 sit next to x4 and keeping all other persons
in same order. It is clear that the map f is onto; and for each round permutation
there are 4 permutations sending to the same round permutation. For instance, the
four permutations
x1 x2 x3 x4 , x2 x3 x4 x1 , x3 x4 x1 x2 , x4 x3 x2 x1
4! = |X| = 4|Y |.
Therefore
4!
|Y | = = 3! = 6.
4
Proposition 4.1. The number of round permutations of n objects is
n!
= (n 1)!.
n
(n 1)!
.
2
Elements in a set are always considered distinct. When considering indistin-
guishable elements we need the concept of multisets. By a multiset we mean a
collection of objects such that some of them may be identically the same, called
indistinguishable. Let A be a multiset of n objects such that there are k distin-
guishable types of objects. If there are ni indistinguishable objects for the ith type,
where 1 i k, the multiset is called a multiset of type (n1 , n2 , . . . , nk ).
Example How many ways to arrange 6 color balls of the same size, of which two
are white, 3 are black, and 2 is red, in linear order?
Solution. Let the 6 balls be represented by w, w, b, b, b, r, r. Let us label
the balls of the same color by numbers to get 6 distinct balls w1 , w2 , b1 , b2 , b3 ,
r1 , r2 . Then each permutation of the 6 balls without labels produces 12 = 2!3!2!
permutations of the 6 distinct balls (6 color balls with labels). More precisely, let X
be the set of permutations of b1 , b2 , b3 , w1 , w2 , r1 , r2 and Y the set of permutations
of b, b, b, w, w, r, r. Then there is a map f : X Y , sending each permutation of
b1 , b2 , b3 , w1 , w2 , r1 , r2 to a permutation of b, b, b, w, w, r, r by erasing the labels. For
4.2. PERMUTATIONS 41
instance,
r1 b1 w1 b2 b3 r2 w2 r2 b1 w1 b2 b3 r1 w2
r1 b1 w1 b3 b2 r2 w2 r2 b1 w1 b3 b2 r1 w2
r1 b2 w1 b1 b3 r2 w2 r2 b2 w1 b1 b3 r1 w2
r1 b2 w1 b3 b1 r2 w2 r2 b2 w1 b3 b1 r1 w2
r1 b3 w1 b1 b2 r2 w2 r2 b3 w1 b1 b2 r1 w2
r1 b3 w1 b2 b1 r2 w2 r2 b3 w1 b2 b1 r1 w2 f
2!3!2! 7 rbwbbrw.
r1 b1 w2 b2 b3 r2 w1 r2 b1 w2 b2 b3 r1 w1
r1 b1 w2 b3 b2 r2 w1 r2 b1 w2 b3 b2 r1 w1
r1 b2 w2 b1 b3 r2 w1 r2 b2 w2 b1 b3 r1 w1
r1 b2 w2 b3 b1 r2 w1 r2 b2 w2 b3 b1 r1 w1
r1 b3 w2 b1 b2 r2 w1 r2 b3 w2 b1 b2 r1 w1
r1 b3 w2 b2 b1 r2 w1 r2 b3 w2 b2 b1 r1 w1
Clearly, f is onto. For each permutation P of b, b, b, w, w, r, r, its inverse image
f 1 (P ) consists of 2!3!2! permutations of b1 , b2 , b3 , w1 , w2 , r1 , r2 . Thus |X| = 24|Y |,
that is,
|X| 7!
|Y | = = = 210.
2!3!2! 2!3!2!
Theorem 4.3. The number of permutations of n objects of type (n1 , n2 , . . . , nk )
is
n!
.
n1 !n2 ! nk !
Example How many ways to put five same calculus books, three same physics
books, and two same chemistry book in a bookshelf?
10!
answer = = 2520.
5!3!2!
Corollary 4.4. The number of sequences of 0 and 1 of length n with exact r
1s and (n r) 0s is given by
n!
.
r!(n r)
Example Counting the number of nondecreasing coordinate paths from the origin
(0,0) to the point (6,4).
Solution. Note that each such path can be viewed as a walk by moving to the right
and up. If we denote the moving of one unit to the right by R and the moving of
one unit up by U , then each such path can be viewed as a sequence of R and U of
length 10 with 6 Rs and 4 U s. Thus the answer is
10!
= 210.
6!4!
Proposition 4.5. The number of non-decreasing coordinate paths from (0, 0)
to (a, b), where a and b are both non-negative integers, is given by
(a + b)!
.
a!b!
Thinking Problem Find a formula for the number of round permutations of n
objects of type (n1 , n2 , . . . , nk ).
42 4. COMBINATORICS
Example How many possible seating plans can be made for r people to be seated
at a round table of n seats, leaving n r seats empty? (Assume n r 1)
Solution. First Method: Let X be the set of all permutations of the five elements
a, b, c, d, e and let Y be the set of all 3-subsets of A. Then there is a map f :
X Y , sending each permutation x1 x2 x3 x4 x5 to the 3-subset {x1 , x2 , x3 }, that
is, f (x1 x2 x3 x4 x5 ) = {x1 , x2 , x3 }. It is clear that f is onto, and the inverse image
of every 3-subset from Y has 3!2! permutations in X. For instance,
acebd
aecbd
caebd
ceabd
eacbd
ecabd f
12 = 3!2! 7 {a, c, e}
acedb
aecdb
caedb
ceadb
eacdb
ecadb
Thus |X| = 3!2!|Y | and the answer is
5 5!
= = 10.
3 3!2!
Second Method: Let X be the set of 3-permutations of A and Y the set of
3-subsets of A. Define f : X Y by f (x1 x2 x3 ) = {x1 , x2 , x3 } for each 3-
permutation x1 x2 x3 X. Obviously, there are 3! permutations of {x1 , x2 , x3 }
sent to {x1 , x2 , x3 }. We then have
|X| P (6, 3)
|Y | = = .
3! 3!
4.3. COMBINATION 43
n n! P (n, r)
= = .
r r!(n r)! r!
n
X n
(x + y)n = xk y nk .
k
k=0
Proof.
(x + y)n = (x + y)(x + y) (x + y)
| {z }
n
X
= u1 u2 un (ui = x or y, 1 i n)
X number of sequences of x and y of
n
=
length n with k xs and (n k) ys
k=0
n
X n k nk
= x y .
k
k=0
A collection of k disjoint subsets of an n-set is called a combination of n ob-
jects of type (n1 , n2 , . . . , nk ) if the k subsets have the cardinalities n1 , n2 , . . . , nk
and n = n1 + n2 + + nk . A combination of n objects of type (n1 , n2 , . . . , nk ) can
be viewed as a placement of n objects into k boxes so that the 1st box contains n1
objects, the 2nd box contains n2 objects, and so on. The number of combinations
of n objects of type (n1 , n2 , . . . , nk ) is denoted by
n
,
n1 , n2 , . . . , nk
Example How many ways can six distinct objects be placed into three boxes so
that the 1st box contains two objects, the 2nd box contains three objects, and the
3rd box contains one object?
Solution. Given a set A = {a, b, c, d, e, f } of six objects. Let X be the set of
permutations of A, and let Y be the set of placements of elements of A into three
boxes so that the 1st box receives two elements, the 2nd box receives thee elements,
and the 3rd box receives one element. Then there is map f : X Y , sending each
permutation x1 x2 x3 x4 x5 x6 of A to the placement {x1 , x2 }{x3 , x4 , x5 }{x6 }. It is
clear that f is onto. For each placement {x1 , x2 }{x3 , x4 , x5 }{x6 }, its inverse image
44 4. COMBINATORICS
Proof.
4.4. COMBINATION WITH REPETITION 45
Solution. Take a collection of seven objects from A with repetition allowed, say,
a, a, b, b, b, c, d, we insert bars (denoted by the symbol 1) between the as and bs,
the bs and the cs, the cs and ds; and denote the objects a, b, c, d by the same
symbol 0. Then each collection of seven objects from A is encoded into a sequence
of 0 and 1 of length 10 with seven 0s and three 1s. For instance,
aa 1 bbb 1 c 1 d 7 0010001010
aaa 1 bbbb 1 1 7 0001000011
1 bb 1 ccccc 1 7 1001000001
a 1 1 ccc 1 ddd 7 0110001000
Note that different collections of seven objects from A with repetition allowed are
encoded into different sequences, and every sequence of 0 and 1 of length 10 with
exact seven 0s and three 1s can be obtained in this way. Thus
4 4+71 10
= = .
7 7 7
Theorem 4.10. The number of r-combinations of n objects with repetition
allowed is DnE n + r 1
= .
r r
Example Eight students plan to have dinner together in a restaurant where the
menu shows 20 different dishes. Now each student decides to order one dish. How
many possible combinations of dishes can be ordered by the students for their din-
ner?
Solution.
20 20 + 8 1 27
Answer = = = .
8 8 8
Theorem 4.11. The number of nonnegative integer solutions for the equation
x1 + x2 + + xn = r
is given by
DnE n+r1
= .
r r
Example There are five types of color T-shirts on sale, black, blue, green, orange,
and white. John is going to buy ten T-shirts; he has to buy at least two blues and
two oranges, and at least one for all other colors. Find the number of ways that
John can select ten T-shirts.
46 4. COMBINATORICS
Solution. We label the colors black, blue, green, orange and white by numbers
1, 2, 3, 4, 5. Let xi be the number of T -shirts that John would select for the ith
color T -shirt. Then the problem is to find the number of integer solutions for the
equation
x1 + x2 + + x5 = 10,
where x1 1, x2 2, x3 1, x4 2, x5 1.
5 5+31 7
Answer = = = = 35.
3 3 3
Example In how many ways can a student order eight dumplings from three dif-
ferent kinds? In how many ways can a student eat eight dumplings from the three
kinds, assuming that there are infinitely many supply of dumplings for each kind
and that the dumplings of the same kind should be eaten consecutively one by one?
3 10
= = 45.
8 8
3
X
k
answer = k!
8k
k=1
Example
n
n+1 n
= + .
r r1 r
Proof. Let An be a set {a1 , a2 , . . . , an } of n elements and let An+1 be the {a1 , . . . , an , an+1 }
of n + 1 elements. The r-subsets of An+1 can be divided into two kinds: the r-
subsets
n of An and the r-subsets of An+1 that are not subsets of An . There are
r r-subsets of the first kind. Each r-subset of the second kind must contain the
element an+1 . Thus the r-subsets of the second kind can be obtained by taking all
(r
1)-subsets
of An and adding the element an+1 to each of them; so there are
n
n+1 n n
r1 r-subsets of the second kind. Thus we have r = r + r1 .
1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
Example 4.1.
n 2 n 2 n 2
2n
= + + +
n 0 1 n
Proof. Let us consider n-combinations of 2n balls of the same size, of which n balls
are white and the other n balls are black. Each such combination can be obtained
4.5. COMBINATORIAL PROOF 47
by taking k balls from the n white balls and taking (n k) balls from the n black
balls, where k ranges from 0 to n. Then we have
n n n n n n
2n
= + + +
n 0 n 1 n1 n 0
n 2 n 2 n 2
= + + + .
0 1 n
Exercises
(1) A computer user name consists of three English letters followed by five
digits. How many different user names can be made?
(2) A set lunch is to include a soup, a main course, and a drink. Suppose a
customer can select from three soups, five main courses, and four drinks.
How many different set lunches can be selected.
(3) Give a procedure for determining the number of zeros at the end of n!.
Justify your procedure and make examples for 12! and 26!.
(4) Find the number of different permutations of the letters in HONGKONG.
(5) A bookshelf is to be used to display 10 math books. Suppose there are
8 kinds of calculus books, 6 kinds of linear algebra books, and 5 kinds of
discrete math books. It is required that books for the same subject should
be displayed together.
(a) Find the number of ways to display 10 distinct books so that there
are 5 calculus books, 3 linear algebra books, and 2 discrete math
books.
(b) Find the number of ways to display 10 books (not necessarily distinct)
so that there are 5 calculus books, 3 linear algebra books, and 2
discrete math books.
(6) There are n men and n women to form a circle or a line, n 2. Find the
number of patterns of
(a) circles could be formed so that each man is next to at least one
woman;
(b) straight lines could be formed so that each man is next to at least
one woman.
(7) Four identical six-sided dice are tossed simultaneously and numbers show-
ing on the top faces are recorded as a multiset of four elements. How many
different multisets are possible?
(8) Find the number of non-decreasing coordinate paths from the origin (0, 0, 0)
to the lattice point (a, b, c).
(9) In how many ways can a six-card hand be dealt from a deck of 52 cards.
(10) How many different eight-card hands with five red cards and three black
cards can be dealt from a deck of 52 cards?
(11) Fortune draws are arranged to select six ping pang balls simultaneously
from a box in which 20 are orange and 30 are white. A draw is lucky if
it consists of three orange and thee white balls. What is the chance of a
lucky draw?
(12) Determine the number of integer solutions for x1 + x2 + x3 + x4 38,
where
(a) xi 0, 1 i 5.
48 4. COMBINATORICS
(b) x1 0, x2 2, x3 2, 3 x4 8.
(13) Determne the number of nonnegative integer solutions to the pair of equa-
tions
x1 + x2 + x3 = 8, x1 + x2 + x3 + x4 + x5 + x6 = 18.
(14) Let M be a multiset of type (n1 , n2 , . . . , nk ) such that ni 1 for 1 i k.
If the numbers n1 , n2 , . . . , nk are all coprime with n = n1 + n2 + + nk ,
then the number of round permutations of M is
n
n1 ,n2 ,...,nk
.
n
The formula is actually valid when gcd(n1 , . . . , nk ) = 1, but we didnt
define the gcd yet for more than two integers. Find a counterexample if
the conditions are not satisfied.
(15) Find the number of non-decreasing lattice paths from the origin (0, 0)
to a non-negative lattice point (a, b), allowing only horizontal, vertical,
and diagonal unit moves; that is, allowing moves (x, y) (x + 1, y),
(x, y) (x, y + 1) and (x, y) (x + 1, y + 1).
(16) *Find the number of non-decreasing lattice paths from the origin (0, 0)
to a non-negative lattice point (a, b), allowing arbitrary straight moves
from one lattice point to another lattice point; that is, allowing moves
(x, y) (x + k, y + h), where k and h are non-negative integers such that
(k, h) 6= (0, 0).
Hint for Ex. 14: Let M be a multiset of type (n1 , . . . , nk ) and S(M ) the set of all
permutations of M . Define : S(M ) S(M ) by
(x1 x2 x3 xn ) = x2 x3 xn x1 .
A permutation w = x1 x2 xn is called primitive if the permutations
w, (w), 2 (w), . . . , n1 (w)
are distinct.
For a non-primitive permutation x1 x2 xn of M , there are integers a and b,
0 a < b < n, such that
a (x1 x2 xn ) = b (x1 x2 xn ).
Let l = b a. Then
l (x1 x2 xn ) = x1 x2 xn .
That is,
xl+1 xl+2 xn x1 x2 xl = x1 x2 xnl xnl+1 xnl+2 xn .
This is equivalent to saying that
xl+1 = x1 , xl+2 = x2 , . . . , xn = xnl ; x1 = xnl+1 , x2 = xnl+2 , . . . , xl = xn .
We claim that l|n. In fact, suppose l doesnt divide n, then n = ql+r with 0 < r < l.
Then
xl+1 = x1 , xl+2 = x2 , . . . , x2l = xl , x2l+1 = x1 , . . . , xn = xql+r = xr .
4.5. COMBINATORIAL PROOF 49
Thus
xl+1 xl+2 xn x1 x2 xl = x1 x2 xl x1 x2 xl x1 x2 xr x1 x2 xl .
| {z } | {z }
| {z }
q1
xl+1 xl+2 xn x1 x2 xl = x1 x2 xn = x1 x2 xl x1 x2 xl x1 x2 xr .
| {z } | {z }
| {z }
q
x1 x2 xr x1 x2 xl = x1 x2 xl x1 x2 xr .
Continuing this procedure, one can find a positive integer s such that n = sd and
x1 x2 xn = x1 x2 xs x1 x2 xs .
| {z } | {z }
| {z }
d
Let si be the number of elements of the ith type in the segment x1 x2 xs . Then
si d = ni . So d|ni , 1 i k. Hence d divides gcd(n1 , . . . , nk ). We have shown
that if gcd(n1 , . . . , nk ) = 1 then there is no positive integer l < n such that
` (x1 x2 xn ) = x1 x2 xn , that
is, every
permutation is primitive. Thus the
n
number of round permutations is n1 ,...,nk /n.
Now let m = gcd(n1 , . . . , nk ) and let Dm be the set of divisors of m. Then Dm
is a finite partially ordered set by its divisibility. For each d D, let
Note that each permutation x1 x2 xdn/m of type (dn1 /m, . . . , dnk /m) can be
classified as a unique primitive permutation x1 x2 xd0 n/m for some d0 such that
d0 |d and
x1 x2 xdn/m = x1 x2 xd0 n/m x1 x2 xd0 n/m .
| {z } | {z }
| {z }
d/d0
Then
X
f (d) = g(d0 ).
d0 |d
1 X X m/d0
= f (d0 ) (k)
n 0 k
d |m k|(m/d0 )
1 X m
= f (d0 ) 0
n 0 d
d |m
1 X m
= f (d)
n d
d|m
1X n/d
= (d).
n n1 /d, . . . , nk /d
d|m
min{a,b}
X a+bk
answer: .
a k, b k, k
k=0
For any such path with k diagonal moves (0 k min{a, b}), the number of
horizontal moves should be a k and the number of vertical moves should be b k.
Example Among any five integers between 1 and 8 inclusive, there are at least two
of them adding up to 9.
Solution. We can divide the set {1, 2, , 8} into four disjoint subsets where each
has two elements adding up to 9: {1, 8}, {2, 7}, {3, 6}, and {4, 5}. When selecting
five numbers from these four subsets, at least two of the five selected numbers must
4.7. RELATION TO PROBABILITY 51
come from a same subset of the four subsets. Thus their addition is 9.
Example Show that in any group of two or more persons there are at least two
having the same number of friends (It is assumed that if a person x is a friend of a
person y then y is also a friend of x).
Solution. Assume that there are n persons in the group. The number of friends of
a person x should be between 0 and n 1. If there is one person x who has n 1
friends, then everyone is a friend of x . So both 0 and n 1 can not be numbers
of friends of some people in the group. Thus the pigeonhole principle tells us that
there are at least two people who have the same number of friends.
Example Given 10 distinct integers a1 , a2 , . . . , a10 such that 0 ai < 100, can we
find a subset of {a1 , . . . , a10 } such that the sum of numbers in the subset with sign
is zero?
Solution. Consider all possible partial sums of the selected numbers a1 , a2 , . . . , a10 .
The values of these sums should be between 0 and 1000. Note that the number of
subsets of 10 objects is 210 = 1024. By the Pigeonhole Principle there are at least
two subsets A and B of {a1 , a2 , . . . , a10 } such that the sum of the elements of A
and the sum of the elements of B are the same, that is,
X X
ai = aj .
ai A aj B
Now we move all elements from the right side to the left; the elements in both A
and B will be canceled. Thus sum of the elements of AB with positive sign for
the elements in A B and negative sign for the elements in B A is equal to 0.
Theorem 4.13. If n objects are placed in m boxes, then one of the boxes must
n n
contain at least d m e objects, where d m e denotes the smallest integer greater or equal
n
to m .
roll a pair of dice we may have outcomes a collection of pairs of numbers between
1 and 6. The chance of the event of the outcomes that the sum of the pair is even
is one-half. For instance, we may be interested in computing the probability of the
event of the outcomes that the sum of the pair is 8.
Definition 4.14. Any collection of outcomes in a probabilistic experiment is
called an event. If each outcome is equally likely to be happened, we define
Total number of favorite outcomes
Probability of even A = P (A) = .
Total number of possible outcomes
Example What is the probability of selecting three distinct numbers from 1, 2, . . . , 11
so that two are less that 5, one is equal to 5, and four are larger than 5?
Solution. The total number of possible outcomes is 11 7 , and the total number of
4 1 6
favorite outcomes is 2 1 4 . Then the probability is
4 1 6
2 1 4
11 .
7
Example Find the probability that no two persons have the same birthday in a
party of 40 people.
40
Solution. The total number
365 of possible outcomes is 365 and the total number of
favorite outcomes is 40 40!. The probability is
365
40 40!
0.109.
36540
Example What is the probability of rolling a pair of dice so that the sum of
numbers on the top faces is 8?
Solution. Since there is no order between the two dice, there are twenty-one possible
outcomes
{i, j}, 1 i j 6
3
and three favorite outcomes {2, 6}, {3, 5}, {4, 4}. So the answer might be 21 = 17 .
One may color the two dice as black and white so that the two dice are ordered.
There are 36(= 6 6) possible outcomes and five favorite outcomes (2, 6), (3, 5),
5
(4, 4), (5, 3), (6, 2). The answer should be 36 . Which one is correct and why?
Example Find the probability of rolling four dice simultaneously so that the sum
of points is exactly 9.
Solution. The total number of possible outcomes is 64 . The total number of favorite
outcomes is the number of positive integer solutions of the equation
x1 + x2 + x3 + x4 = 9
which is equivalent to the number of non-negative integer solutions of the equation
y1 + y2 + y3 + y4 = 5.
Thus the answer is given by
4
5 7 1
= .
64 162 23
Exercises
4.8. INCLUSION-EXCLUSION PRINCIPLE 53
(1) Show that there must be 90 ways to choose six numbers from 1 to 15 so
that all the choices have the same sum.
(2) Show that if five points are selected in a square whose sides have length
2, then there are at leat two points whose distance is at most 2.
(3) Prove that if any 14 numbers from 1 to 25 are chosen, then one of them
is a multiple of another.
(4) Twenty disks numbered 1 through 20 are placed face down on a table.
Disks are selected one at a time and turned over until 10 disks have been
chosen. If two of the disks add up to 21, the play loses. Is it possible to
win this game?
(5) Show that it is impossible to arrange the numbers 1, 2, . . . , 10 in a circle
so that every triple of consecutively placed numbers has a sum less than
15.
Example The pin numbers Hang Seng Bank card are nonnegative integers of six
digits. How many pin numbers can be made so that the triple 444 doesnt appear?
Solution. Let U be the set of all possible secrete codes. Then |U | = 106 . Let
A1 = set of codes of the form 444xxx,
A2 = set of codes of the form x444xx,
A3 = set of codes of the form xx444x,
A4 = set of codes of the form xxx444,
where x varies from 0 to 9. Then |A1 | = |A2 | = |A3 | = |A4 | = 103 ; |A1 A2 | =
|A2 A3 | = |A3 A4 | = 102 , |A1 A3 | = |A2 A4 | = 10, |A1 A4 | = 1; |A1 A2 A3 | =
|A2 A3 A4 | = 10, |A1 A2 A4 | = |A1 A3 A4 | = 1; |A1 A2 A3 A4 | = 1.
Thus
answer = 106 4 103 + (3 102 + 2 10 + 1) (2 10 + 2) + 1 = 996310.
54 4. COMBINATORICS
Example Find the number of positive integer solutions for the linear equation
x1 + x2 + x3 = 8.
Solution. Let Ai be the set of non-negative integer solutions of the above equation
such that xi = 0, 1 i 3. Then
3 3+81 10
|U | = = = = 45;
8 8 8
|A1 A2 A3 | = 0.
or equivalently,
X X
|A1 A2 An | = |U | |Ai | + |Ai Aj |
i i<j
X
|Ai Aj Ak |
i<j<k
+
+ (1)n |A1 A2 An |
n
X X
(4.2) = |U | + (1)k |Ai1 Aik | .
k=1 1i1 <<ik n
Proof. For each element x U , we show that x contributes the same count to
both sides of (4.2).
Case I: x 6 A1 A2 An . Note that the element x is counted once in
A1 A2 An = A1 A2 An ,
once in U , and 0 times in all
Ai1 Ai2 Aik , i1 < i2 < < ik .
Thus x is counted once on both sides of (4.2).
Case II: x A1 A2 An . We assume that x belongs r to rexactly
r rsubsets
of
rA1 , A 2 , . . . , An , say A t1
, A t2
, . . . , Atr
. Then x is counted 0 , 1 , 2 , 3r , . . .,
r times in
X X X
U, |Ati |, |Ati Atj |, |Ati Atj Atk |, . . . , |At1 At2 Atr |
i i<j i<j<k
It is clear that
|af + bg| = a|f | + b|g|.
Note that A1 An is the set of elements of U satisfying none of the conditions
c1 , . . . , cn . The set Ai1 Aik consists of the elements of U satisfying the
conditions ci1 , . . . , cik . On the one hand by Proposition 4.16, we have
1A1 An = 1A 1An
= (1U 1A1 ) (1U 1A1 )
X
= f1 f2 fn (each fi is either 1U or 1Ai )
X
= 1U 1U + 1U 1U (1Ai1 ) (1Aik )
| {z } | {z }
1i1 <<ik n
n 1kn nk
n
X X
= 1U + (1)k 1Ai1 1Aik
k=1 1i1 <<ik n
Xn X
= 1U + (1)k 1Ai1 Aik .
k=1 1i1 <<ik n
Thus
|A1 An | = |1A1 An |
Xn X
= (1)k1 |1Ai1 Aik |
k=1 1i1 <<ik n
Xn X
= (1)k1 |Ai1 Aik |.
k=1 1i1 <<ik n
and
n
Nk = (n k)m , 0 k n.
k
Therefore
n
X n
=
C(m, n) = N (1)k (n k)m .
k
k=0
Note that C(m, n) can be interpreted as the number of ways to place the
elements of A into n distinct boxes so that no one box is empty. We have
X
m
C(m, n) = .
i ++in=m
i1 , . . . , in
1
i1 ,...,in 1
X n
X n
m
= (1)k (n k)m .
i1 , . . . , in k
i1 ++in=m k=0
i1 ,...,in 1
Theorem 4.17. Let (n) be the number of integers x in [1, n] that are coprime
with n. Then for any positive integer n = pe11 perr , where p1 , . . . , pr are distinct
primes and e1 , . . . , er are positive integers, the Euler function (n) is given by
r
Y
1
(n) = n 1 .
pk
k=1
n
Thus |Ai1 Aik | = pi1 pik for all 1 i1 < < ik r. Therefore
r
X X
(n) = n+ (1)k |Ai1 Aik |
k=1 1i1 <<ik n
Xr X n
= n+ (1)k
p i 1 pi k
k=1 1i1 <<ik n
1 1
= n 1 + +
p1 pr
1 1 1 1
+ + + + + +
p1 p2 p1 p 3 p1 pr pr1 pr
1 1 1 1
+ + + + +
p1 p2 p3 p1 p2 p4 p1 p2 pr pr2 pr1 pr
1
+ + (1)r
p 1 p 2 pr
Y r
1
= n 1 .
pk
k=1
Example For n = 36 = 22 32 ,
1 1
(36) = 36 1 1 = 12.
2 3
In fact, the integers from 1 to 36 that are coprime with 36 can be listed as
1, 5, 7, 11, 13, 17, 19, 23, 25, 29, 31, 35.
Example A permutation of {1, 2, . . . , n} is called a dearrangement if every i
(1 i n) is not placed at the ith position. We call an arrangement of {1, 2, . . . , n}
to satisfy condition ci if i is placed at the ith position. Let dn be the number of
dearrangements of {1, 2, . . . , n}. Then
dn = N (
c1 c2 cn )
X n X
= n! + (1)k (n k)!
k=1 1i1 <<ik n
n
X n
= (1)k (n k)!
k
k=0
n
X 1
= n! (1)k ' n!e1 .
k!
k=1
For (d0 , k 0 ) 6= (d, k), if f (d, k) = f (d0 , k 0 ), that is, kn/d = k 0 n/d0 , then kd0 = k 0 d.
Since gcd(d, k) = 1 and gcd(d0 , k 0 ) = 1, we have d|d0 , d0 |d, k|k 0 , and k 0 |k. Then
d = d0 and k = k 0 , that is, f is injective.
For any 1 m n, let gm = gcd(m, n), dm = n/gm , km = m/gm . Then
dm |n, km dm , and gcd(dm , km ) = 1, that is, (dm , km ) S. Now we have
f (dm , km ) = km n/dm = m, that is, f is surjective.
Exercises
(1) In how many ways to arrange the letters E, I, M, O, T, U, Y so that YOU,
ME and IT would not occur?
(2) Six passengers on a msall airplane are randomly assigned to the six seats
on the plane. On the return trip they are again randomly assigned seats.
(a) What is the chance that every passenger has the same seats on both
trips?
(b) What is the probability that exactly five passengers have the same
seats ob both trips?
(c) What is the probability that at least one passenger has the seat on
both trips?
(3) Show that for any positive integer n,
X n
(n) = (d) ,
d
d|n
Recurrence Relations
Example The game of Hanoi Tower is to play with a set of disks of graduated
size with holes in their centers and a playing board having three spokes for holding
the disks; see Figure ??. The object of the game is to transfer all the disks from
spoke A to spoke C by moving one disk at a time without placing a larger disk on
top of a smaller one. What is the minimal number of moves required when there
are n disks?
A B C
Solution. Let an be the minimum number of moves to transfer n disks from one
spoke to another. Then {an | n 1} defines an infinite sequence. The first few
terms of the sequence {an } can be listed as
1, 3, 7, 15, . . .
This means that the sequence {an | n 1} satisfies the recurrence relation
an = 2an1 + 1, n 1
(5.1)
a1 = 1.
Given a recurrence relation for a sequence with initial conditions, solving the
recurrence relation means to find a formula to express the general term an of the
sequence.
63
64 5. RECURRENCE RELATIONS
Proof. When the characteristic equation (5.3) has two distinct roots r1 and r2
it is clear that both xn = r1n and xn = r2n are solutions of (5.2).
Now assume that (5.2) has only one root r. Then a2 + 4b = 0 and r = a/2, i.e.,
a2 a
b= and r = .
4 2
n
We verify that xn = nr is a solution of (5.2). In fact,
a n1 a2 a n2 a n
axn1 + bxn2 = a(n 1) + (n 2) =n = xn .
2 4 2 2
Remark There is heuristic method to explain why xn = nrn is a solution when
the two roots are the same. If two roots r1 and r2 are distinct but very close to
each other, then r1n r2n is a soltuion. So is (r1n r2n )/(r1 r2 ). It follows that the
limit
rn r2n
lim 1 = nr1n1
r2 r1 r1 r2
Example Two persons A and B gamble dollars on the toss of a fair coin; A has $70
and B has $30. In each play either A wins $1 from B or loss $1 to B; and the game
is played without stop until one wins all the money of the other or goes forever.
Find the following probabilities.
(a) A wins all the money of B.
(b) A loss all his moeny to B.
(c) The game continues forever.
Solution. Either A or B can keep track of the game simply by counting their own
money; their position (money) can be one of the numbers 0, 1, 2, . . . , 100. Let pn
be the probability that A reaches 100 at position n. After one toss, A enters into
either position n + 1 or position n 1. The new probability that A reaches 100 is
either pn+1 or pn1 . Since the probability of A moving to position n + 1 or n 1
from n is 12 . We thus have the recurrence relation
pn = 21 pn+1 + 12 pn1
p0 = 0
p100 = 1
5.3. HIGHER ORDER HOMOGENEOUS RECURRENCE RELATIONS 67
k
Since n = 2 , we have k = log2 n. Therefore
xn = log2 n + 1.
2k 1
= 2k1 + + 2 + 1 =
21
= n 1 = O(n).
We hope that we understand the nature of divide-and-conquer method by the
above examples. In order to solve a problem of size n, if the size n is large and the
problem is complicated, we divide the problem into a smaller subproblems of the
same type and of the same size d nb e, where a, b Z+ , 1 a < n and 1 < b < n.
Then we solve the a smaller subproblems and use the results to construct a solution
for the original problem of size n. We are especially interested in the case where
n = bk and b = 2.
5.5. DIVIDE-AND-CONQUER METHOD 71
Our concern here is to figure out the time complexity function f (n) which is
given by the recurrence relation
f (1) = c
f (n) = af ( nb ) + h(n), n = bk , k 1
Theorem 5.7. Let f : Z+ R be a function defined by the recurrence relation
f (1) = c
f (n) = af ( nb ) + c, n = bk , k 1
where a, b, c are positive integers and b 2. Then
(
f (n) = c(logb n + 1) if a = 1
logb a
f (n) = c(an a1 1) if a =
6 1
Proof. Applying the recurrence relation, we obtain
f (n) = af ( nb ) + c
af ( nb ) = a2 f ( bn2 ) + ac
a2 f ( bn2 ) = a3 f ( bn3 ) + a2 c
..
.
n n
ak2 f ( bk2 ) = ak1 f ( bk1 ) + ak2 c
k1 n n
a f ( bk1 ) = a f ( bk ) + ak1 c
k
Adding both sides of the k equations and canceling the common summands, we
have n
f (n) = ak f k + c + ac + a2 c + + ak1 c .
b
Since n = bk and f (1) = c, we further have
f (n) = c 1 + a + a2 + + ak .
If a = 1, then f (n) = c(k + 1). Note that n = bk implies k = logb n. Hence
f (n) = c (logb n + 1) .
k+1
c(a 1)
If a 6= 1, then f (n) = a1 .
Since k = logb n, it follows that
logb n log n logb a
ak = alogb n = blogb a = b b = nlogb a .
Therefore
c anlogb a 1
f (n) = .
a1
Exercises
(1) Find an explicit formua for each of the sequences defined by the recurrence
relations with initial conditions.
(a) xn = 5xn1 + 3, x1 = 3.
72 5. RECURRENCE RELATIONS
Note that
X X
X
F (x) 1
F (x)2 = Ci Cj xn = Cn+1 xn = .
n=0 i+j=n n=0
x x
Then
xF (x)2 F (x) + 1 = 0.
We thus have
1 1 4x
F (x) = .
2x
Since
1
X
1 4x = 2 (4x)n
n=0
n
X 1
( 12 1) ( 12 n + 1) 2n
= 1+ 2
2 (1)n xn
n=1
n!
X
(1)(3)(5) (2(n 1) + 1) n
= 2 (1)n xn
n=0
n!
X
1 3 5 (2(n 1) 1) n n
= 2 x
n=0
n!
X
(2(n 1))! n
= 12 x
n=1
n!(n 1)!
X (2n)!
= 12 xn+1 ,
n=0
n!(n + 1)!
we conclude that
1 1 4x X (2n)! n
X 1 2n
F (x) = = x = xn .
2x n=0
n!(n + 1)! n=0
n + 1 n
1
2n
Therefore Cn = n+1 n .
Eulers Problem In how many different ways can a labeled convex n-gon be
divided into triangles by non-intersecting diagonals?
Solution. Let cn be number of ways for an (n + 2)-gon in the problem. Then c1 = 1,
c2 = 2, and c3 = 5. Consider a convex (n + 3)-gon V1 V2 Vn+3 .
In each decomposition of the (n + 3)-gon, the segment V1 Vn+3 is a side of
some triangle in the decomposition; and the third vertex of such a triangle is one
of the vertices V2 , V3 , . . . , Vn+2 . Let the thrid vertex be Vk+2 , 0 k n. Then
we have one (k + 2)-gon V1 V2 Vk+2 and one (n k + 2)-gon Vk+2 Vk+3 Vn+3 .
There are ck ways to divide V1 V2 Vk+2 into triangles and cnk ways to divide
Vk+2 Vk+3 Vn+3 into triangles. We thus have the recurrence relation
n
X
cn+1 = ck cnk ,
k=0
(2n)! ( 2n
n )
where c0 = 1. So cn = n!(n+1)! = n+1 .
5.7. GROWTH OF FUNCTIONS 75
Binary Relations
Example Consider a family A with five children, Amy, Bob, Charlie, Debbie, and
Eric. We abbreviate the names to their first letters so that A = {a, b, c, d, e}.
(a) The brother-sister relation Rbs is the set
Rbs = {(b, a), (b, d), (c, a), (c, d), (e, a), (e, d)}.
(b) The sister-brother relation Rsb is the set
Rsb = {(a, b), (a, c), (a, e), (d, b), (d, c), (d, e)}.
(c) The brother relation Rb is the set
{(b, b), (b, c), (b, e), (c, b), (c, c), (c, e), (e, b), (e, c), (e, e)}.
77
78 6. BINARY RELATIONS
The brother-sister relation Rbs is the inverse of the sister-brother relation Rsb ;
1
that is, Rbs = Rsb . The brother or sister relation is the union of the brother
relation and the sister relation; that is, Rb Rs . The complementary relation of
brother or sister relation is the brother-sister or sister-brother relation; that is,
Rb Rs = Rbs Rsb .
Example
2 2
(a) The graph of the equation, x32 + y22 = 1, defines a binary relation on the
set R of real numbers; its graph is an ellipse.
(b) The relation less than, denoted <, is a binary relation on R, defined
by a < b if and only if a is less than b. As a subset of R2 = R R, the
relation is also given by the set {(a, b) R2 | a is less than b}.
(c) The relation greater than or equal to is a binary relation on R, defined
by a b if and only if a is greater than or equal to b. As a subset of R2 , the
relation is given by the set {(a, b) R2 | a is greater than or equal to b}.
(d) The divisibility relation | about integers, defined by a|b if and only if a
divides b, is a binary relation on the set Z of integers.
Proof. (a) For any y R(A), there is an x A such that xRy. Since A B,
we have y R(B). Thus R(A) R(B).
(b) For any y R(A B), there is an x A B such that xRy. If x A,
then y R(A). If x B, then y R(B). In either case, y R(A) R(B).
Thus R(A B) R(A) R(B). On the other hand, it follows from (a) that
R(A) R(A B) and R(B) R(A B). Therefore R(A) R(B) R(A B).
(c) It follows from (1) that R(A B) R(A) and R(A B) R(B). Thus
R(A B) R(A) R(B).
A path that begins and ends at the same vertex is called a cycle. For a fixed
positive integer k, we define a relation Rk on X as follows:
xRk y there is a path of length k from x to y.
We may also define a relation R on X by letting
xR y there is some path from x to y.
The relation R is sometimes called the connectivity relation for R. It is clear
that
[
R = R R2 R3 = Rk .
k=1
The reachability relation of R is the relation R on X defined by
xR y either x = y or xR y;
that is,
[
R = I R R2 R3 = Rk ,
k=0
where I is the identity relation on X, defined by xIy if and only if x = y. We
always assume that R0 = I for any relation R.
b
b
c
a
c
a
e d
e d
(a) Rbs (b) Rb Rs
Proof. Trivial.
Proof. (a) For any x(R i Ri )z, there exists y Y such that
S xRy and y(i Ri )z.
Then there is one j such that yRi z. Thus x(RRi )z, and so x( i RRi )z. Conversely,
for any x(i RRi )z, there is one i such that x(RRi )z. Then there exists y Y such
that xRy and yRi z. Of course, y(i Ri )z. Thus x(R i Ri )z. The proof for (b) is
similar.
a b = max{a, b}.
82 6. BINARY RELATIONS
Example Many family relations are binary relations on the set of human beings.
(a) The brother relation Rb : xRb y x and y are both males and have the
same parents. (symmetric and transitive)
(b) The sister relation Rs : xRs y x and y are both females and have the
same parents. (symmetric and transitive)
(c) The brother-sister relation Rbs : xRbs y x is male, y is female, x and y
have the same parents.
(d) The sister-brother relation Rsb : xRsb x is female, y is male, and x and
y have the same parents.
(e) The generalized brother relation Rb0 : xRb0 y x and y are both males and
have the same father or the same mother. (symmetric)
(f) The generalized sister relation Rs0 : xRs0 y x and y are both females and
have the same father or mother. (symmetric)
(g) The relation R: xRy x and y have the same parents. (reflexive, sym-
metric, and transitive; equivalence relation)
(h) The relation R0 : xR0 y x and y have the same father or the same mother.
(reflexive and symmetric)
Example
(a) The less than relation < on the set of real numbers is a transitive
relation.
(b) The less than or equal to relation on the set of real numbers is a
reflexive and transitive relation.
(c) The divisibility relation on the set of positive integers is a reflexive and
transitive relation.
(d) Given a positive integer n; the congruence of modulo n is a relation
n on Z, defined by a n b if and only if b a is a multiple of n. The
standard notation for a n b is a b (mod n). The relation n is an
equivalence relation on Z.
S S
This shows that k=1 Rk is transitive and R k=1 Rk . Since any transitive S
relation which contains R must contain Rk for all positive integers k. Then k=1 Rk
is the transitive closure of R.
Theorem 6.18. Let R be a relation on a set X of n elements. Then
t(R) = R R2 Rn1 .
In particular, if R is reflexive, then t(R) = Rn1 .
Sn1
Proof. It suffices to show that Rl k=1 Rk for all l n; and this is equivalent
S l1
to showing Rl k=1 Rk for all l n. Let (x, y) Rl . There exist x1 , . . . , xl1
X such that all (x, x1 ), (x1 , x2 ), . . ., (xl1 , y) belong to R. Since l n, two
elements of x = x0 , x1 , x2 , . . ., xl1 ,xl = y must be the same, say, xi = xj
with i < j. Then (x0 , x1 ), . . ., (xi1 , xi ), (xj , xj+1 ), . . ., (xl1 , xl ) R imply that
Sl1 Sl1
(x, y) = (x0 , xl ) Rl+ij k=1 Rk . Thus Rl k=1 Rk .
If R is reflexive, we have Rk Rk+1 for all k 1. So t(R) = Rn1 .
Proposition 6.19. Let R be a relation on a set X. Then I t(R R1 ) is an
equivalence relation. In particular, if R is reflexive and symmetric, then t(R) is an
equivalence relation.
Proof. Since I t(R R1 ) is reflexive and transitive, we only need to show
that I t(R R1 ) is symmetric. For (x, y) I t(R R1 ), if x = y, obviously
(y, x) I t(R R1 ). If x 6= y, then (x, y) t(R R1 ). Thus (x, y) (R R1 )k
for some k 1; that is, there is a sequence x = x0 , x1 , . . . , xk = y such that
(xi , xi+1 ) R R1 , 0 i k 1. Since R R1 is symmetric, we have
(xi+1 , xi ) R R1 for all 0 i k 1. This means that (y, x) (R R1 )k .
So (y, x) I t(R R1 ). We have proved that I t(R R1 ) is symmetric.
Now if R is reflexive and symmetric, then t(R) = I t(R R1 ) = t(R). So
t(R) is an equivalence relation.
EXERCISES
(1) Let R be a binary relation from X to Y . Let A and B be subsets of X.
(a) If A B, then R(A) R(B).
88 6. BINARY RELATIONS