Notes DM
Notes DM
Notes DM
These notes contain the material from Discrete Mathematics that you need
to know in order to take the course in Computability and Complexity. Try
to solve all problems. Most of them are simple; their purpose is just to
refresh you memory. If you cannot solve many of them, I would strongly
recommend that you take a course in Discrete Mathematics.
1 Logic
1
Problem 2 Fill in the truth tables:
Problem 4 Assuming that p and r are false, and that q and s are true, find
the truth value of the following propositions:
1. p → q;
2. p → q;
3. p → q;
4. (p → q) ∧ (q → r);
5. (p → q) → r;
6. (p → (q → r).
2 Set theory
2
Problem 5 Which of the following statements are true?
∅⊆∅
∅∈∅
∅ ⊆ {∅}
∅ ∈ {∅}
{a, b} ⊆ {a, b, {a, b}}
{a, b} ∈ {a, b, {a, b}}
{a, b} ∈ 2{a,b,{a,b}}
{a, b} ⊆ 2{a,b,{a,b}}
Idempotency A ∪ A = A; A ∩ A = A
Commutativity A ∪ B = B ∪ A; A ∩ B = B ∩ A
Associativity (A ∪ B) ∪ C = A ∪ (B ∪ C)
(A ∩ B) ∩ C = A ∩ (B ∩ C)
Distributivity (A ∪ B) ∩ C = (A ∩ C) ∪ (B ∩ C)
(A ∩ B) ∪ C = (A ∪ C) ∩ (B ∪ C)
DeMorgan’s Laws U − (B ∪ C) = (U − B) ∩ (U − C)
U − (B ∩ C) = (U − B) ∪ (U − C)
Definition 2
A partition of a nonempty set A is a subset Π of 2A such that ∅ is not an
element of Π and each element of A is in one and only one set in Π.
3
Problem 9
Let S = {1, 2, 3, 4, 5}.
(a) What partition of S has the most (the fewest) members?
(b) List all partitions of S with exactly two (three) members.
Definition 3
Binary relation R is a subset of A × B.
Inverse R−1 of R; if R is a binary relation between A and B then
R−1 ⊆ B × A; (b, a) ∈ R−1 iff (a, b) ∈ R.
Composition QR Q ⊆ A × C and R ⊆ C × B is defined by
(a, b) ∈ QR iff (a, c) ∈ Q and (c, b) ∈ R for some c ∈ C.
4
Definition 5
Function from a set A into a set B is a binary relation R on A and B such
that for each element a ∈ A, ∃ exactly one element b ∈ B with (a, b) ∈ R.
f : A → B; A is the domain of f ; f (A) ⊆ B is the range of f .
A function is one-to-one if for any two distinct elements a and b, f (a) 6= f (b).
Definition 6
Let D be a set, n ≥ 0, and R ⊆ Dn+1 be an (n + 1)-ary relation on D. Then
B ⊆ D is said to be closed under R if
Problem 12
Is a set closed under a function f also closed under an appropriately defined
relation R? How to define R?
Problem 13
Given a set A ⊆ D and a relation R on D, is there a subset B ⊆ D which
contains A and is closed under R?
Problem 14
5
Given a set A ⊆ D and a relation R on D, is there a subset B ⊆ D which
(1) contains A; (2) closed under R; (3) is minimal in some natural sense?
Theorem 1
Let R be a relation on D and let A ⊆ D. Then there is a set B ⊆ D such
that
• A ⊆ B;
• B is closed under R;
• for any C ⊆ D satisfying the previous two conditions,
B ⊆ C.
Definition 7
The set B described in the previous theorem is called the closure of A under
relations R1 , . . . , Rn.
Definition 8
Let A be a finite set, D = A × A, and R ⊆ D. Let also Q and Q′ be a 3-ary
and unary relation on D, respectively, given by Q = {((a, b), (b, c), (a, c)) :
a, b, c ∈ A} and Q′ = {(a, a) : a ∈ A}. Then the closure of R under Q and Q′
is called the reflexive, transitive closure of R and is denoted R∗.
Theorem 2
The reflexive, transitive closure R∗ of a binary relation R is equal to
Problem 15
Prove theorem 2.17.
6
3 Principle of Mathematical Induction
1. 0 ∈ A;
2. ∀n ∈ N , if {0, . . . , n} ⊆ A, then n + 1 ∈ A.
Then A = N .
Induction step: prove that the induction hypothesis, P (n), implies that
P is true of n + 1: P (n) =⇒ P (n + 1)
8
4 Pigeonhole principle
1st form: If n pigeons fly into k pigeonholes and k < n, then some pigeon-
hole contains at least two pigeons.
2nd form: If A and B are nonempty finite sets and |A| > |B|, then for any
function f : A → B, ∃a, b ∈ A, such that f (a) = f (b).
3rd form: Let f be a function from a finite set A to a finite set B, let
|A| = n, |B| = m, and k = ⌈n/m⌉. If k ≥ 1, then there are at least k
values a1 , . . . , ak such that f (a1) = . . . = f (ak ).
9
increasing subsequence starting at ij+1 , its length is L, which yields a length
L + 1 monotone increasing subsequence starting at aij . This contradicts the
conclusion from the Pigeonhole Principle, and thus, proves the claim.
Finally, we see that
ai1 > ai1 > . . . > an+1 ,
which proves the theore.
Problem 21 Prove that any subset A of a set {1, 2, 3, . . . , 2n} which has at
least n+1 elements, contains two numbers such that one of them is a multiple
of the other.
Terminology:
alphabet Σ: a finite set of symbols; binary alphabet: {0,1};
string over Σ:a finite sequence of symbols from Σ;
empty string e: ;
Σ∗: the set of all strings over an alphabet Σ
length of a string: the number of symbols in the string;
occurrences: COMMITTEE;
position w(i): ranges from 1 to the length of the string;
substring: COMMITTEE —— MIT;
suffix (prefix): COMMITTEE —— TEE (COM);
10
Operations on strings:
Operations on languages:
Complement A = Σ∗ − A;
Union: L ∪ M;
Lk = LL . . . L;
L∗ = {e} ∪ L ∪ L2 ∪ . . .;
L+ = L ∪ L2 ∪ . . ..
Problem 22 What is ∅∗ ?
11
Problem 28 Prove that (wR )R = w
12
Problem 30 Prove that {a, b}∗ = {a}∗ {{b}{a}∗}∗.
The left part of B consists of all strings in the alphabet {a, b}; every such a
string can be written as ap0 bq0 ap1 bq1 . . . apn−1 bqn−1 , for n ≥ 0 and non-negative
integers p0 , q0, p1, q1, . . ..
The right part of B can be re-written as follows:
a∗ {ba∗ }∗ == {e ∪ a ∪ a2 . . .}{e ∪ L ∪ L2 . . .}∗ = ∪as Lt ,
where s, t ≥ 0 are integers and L = ba∗ = b ∪ ba ∪ ba2 ∪ . . .
Thus, to prove B, we need to find, for every p0 , q0, p1, q1, . . ., integers s and t
such that as Lt contains
13
FINITE REPRESENTATION OF LANGUAGES.
Problem 31 For each of the sets below, give examples of strings in and not
in the sets (Σ = {a, b})
14
(a) {w : for some u ∈ ΣΣ, w = uuR u}
(b) {w : ww = www}
(c) {w : for some u and v, uvw = wvu}
(d) {w : for some u, www = uu}
(a) ∅∗ ∪ a∗ ∪ b∗ ∪ (a ∪ b)∗
(b) ((a∗b∗)∗ (b∗a∗ )∗)∗
(c) (a∗b)∗ ∪ (b∗a)∗
(d) (a ∪ b)∗a(a ∪ b)∗
1. 0 ∈ A;
2. ∀n ∈ N , if {0, . . . , n} ⊆ A, then n + 1 ∈ A.
Then A = N .
15
The task: Given property P = P (n), prove that it holds for
all integers n ≥ 0.
Induction step: prove that the induction hypothesis, P (n), implies that
P is true of n + 1: P (n) =⇒ P (n + 1)
16
Induction step. Suppose, given n ≥ 11, P holds true for all integers up n.
Then 2
P (n) =⇒ n − 2 < n 12−n
2
=⇒ (n + 1) − 2 − 1 < (n+1) −(n+1)−2n−1+1
12
(n+1)2 −(n+1)
=⇒ (n + 1) − 2 < 12 − 2n12 + 1
(n+1)2 −(n+1)
=⇒ (n + 1) − 2 < 12 (since n > 10)
7 Pigeonhole principle
1st form: If n pigeons fly into k pigeonholes and k < n, then some pigeon-
hole contains at least two pigeons.
2nd form: If A and B are nonempty finite sets and |A| > |B|, then for any
function f : A → B, ∃a, b ∈ A, such that f (a) = f (b).
17
3rd form: Let f be a function from a finite set A to a finite set B, let
|A| = n, |B| = m, and k = ⌈n/m⌉. If k ≥ 1, then there are at least k
values a1 , . . . , ak such that f (a1) = . . . = f (ak ).
18
Problem 39 Prove that any subset A of a set {1, 2, 3, . . . , 2n} which has at
least n+1 elements, contains two numbers such that one of them is a multiple
of the other.
Terminology:
alphabet Σ: a finite set of symbols; binary alphabet: {0,1};
string over Σ:a finite sequence of symbols from Σ;
empty string e: ;
Σ∗: the set of all strings over an alphabet Σ
length of a string: the number of symbols in the string;
occurrences: COMMITTEE;
position w(i): ranges from 1 to the length of the string;
substring: COMMITTEE —— MIT;
suffix (prefix): COMMITTEE —— TEE (COM);
Operations on strings:
19
Operations on languages:
Complement A = Σ∗ − A;
Union: L ∪ M;
Lk = LL . . . L;
L∗ = {e} ∪ L ∪ L2 ∪ . . .;
L+ = L ∪ L2 ∪ . . ..
Problem 40 What is ∅∗ ?
20
Problem 48 How many eight digit numbers are there that contain a 5 and
a 6? Explain.
Problem 55 Find pairs (b, c) such that gcd(b, c) equals (a) b/2; (b) b/3.
Problem 57 Using the Euclidean algorithm, find the greatest common divi-
sor of (1) 1008 and 539; (2) 662 and 414. Show all stages of the algorithm
in both cases.
21
Problem 58 If a, b, x, y are nonzero integers such that ax + by = 3, is
gcd(a, b) = 3? Explain.
(a) Gn = O(n2 )
(b) Gn = G0 + G1 + . . . Gn−1
(c) Gn < 2n (n = 0, 1, . . .)
22
Problem 66 For any w ∈ {0, 1}∗, if w starts with 0 and ends with 1, then
it contain s a substring 01.
23
Problem 68 For every integer n ≥ 1,
Xn √ √
i > 2n n/3.
i=1
X √
n+1 n
X √ √
i=( i) + n + 1 (1)
i=1 i=1
24
Problem 71 Let Σ be an alphabet. Under what conditions two distinct non-
empty strings x, y satisfy xy = yx? Either prove it cannot occur, or describe
precisely the circumstances under which it can.
1. L1 L2 = L2 L; and
2. Neither language is a subset of the other.
25
9 Order of functions
Notations:
N : (resp. N +) set of natural (resp. positive natural) numbers;
Factorials: n! = 1 · 2 · 3 · . . . · n.
√ √
2πn ( ne )n ≤ n! ≤ 2πn ( ne )(n+1/12);
√
n! ≈ 2πn ( ne )n (1 + Θ( n1 ));
Fibonacci numbers: F0 = 0; F1 = 1; Fi = Fi−1 + Fi−2.
√ √
1+ 5 1− 5 φi√
−φ̂i
If φ = 2 ≈ 1.61803 . . . and φ̂ = 2 ≈ −0.61803 . . ., then Fi = 5
.
Frequently occurring complexity functions:
O(n) Linear function; when the size of the input doubles
the amount of work doubles;
N log N often arises when the algorithm breaks up the problem into
small subproblems; when the data doubles, the function
more than doubles, but not by much;
2 3
N (resp. N ) Quadratic (resp. Cubic) order; doubling the data size
quadruples (resp. increases by a factor of 8) the work;
N
2 Exponential order assumed to be impractical.
26
Given two functions f, g : R+ → R+
g = O(f ) ≡ ∃C > 0, n0 > 0
such that g(n) ≤ Cf (n) for all n > n0
Function g(n) does not grow at a faster rate than f (n)
27
Problem 76
Which of the statements below is correct and which is false?
1. n2 = O(n3 );
2. n3 = O(n2 );
3. 2n+3 = O(2n );
4. (n + 1)! = O(n!);
5. if f (n) = O(n) then [f (n)]2 = O(n2 );
6. if f (n) = O(n) then 2f (n) = O(2n );
7. if f (n) = O(g(n)) and g(n) = O(h(n)) then f (n) = O(h(n));
8. there are two functions f (n) and g(n) such that
f (n) 6= O(g(n)) and g(n) 6= O(f (n)).
28
Problem 77
Prove that
29
Problem 78
Prove by induction that ith Fibonacci number satisfies the equality
i √
Fi = (φi − φ )/ 5,
√ √
1+ 5 1− 5
where φ = 2 (the golden ratio) and φ = 2 (the conjugate) of φ.
Problem 79
Prove by induction that ∀i > 0, Fi ≤ φi .
Problem 80
Show that quicksort’s best running time is Θ(n log n).
Problem 81
Construct a linear algorithm for sorting n non-negative integers of size ≤ Cn
for some constant C.
30