Tutorial Letter 203/2/2018: Theoretical Computer Science 1
Tutorial Letter 203/2/2018: Theoretical Computer Science 1
Semester 2
School of Computing
Discussion of assignment 03
Dear Student,
By this time you should have received the tutorial matter listed below. These can be downloaded
from myUnisa.
2
COS1501/203
Suppose U = {2, 4, 6, a, b, c, {b, c}} is a universal set with the following subsets:
A = {6, b, c, {b, c}} and B = {2, 6, b, c}.
Question 1
Which one of the following relations from A to B is functional?
1. {(2, 6), (6, b), (b, c), (c, {b, c}}
2. {(6, 6), (c, c), (b, 2), ({b, c}, 6)}
3. {(6, 2), (b, 6), (c, b), (6, {b, c})}
4. {(b, 2), (b, 6), (b, b), (b, c)}
Answer: Alternative 2
Discussion
First we look at the definition for functionality:
Suppose R B × C is a binary relation from a set B to a set C. We may call R functional if the
elements of B that appear as first co-ordinates of ordered pairs in R do not appear in more than
one ordered pair of R.
1. Let L = {(2, 6), (6, b), (b, c), (c, {b, c}} (say). L is not functional since 2 ∉ A. Therefore
(2, 6) cannot be in L, since L is not defined from A to B.
2. Let M = {(6, 6), (c, c), (b, 2), ({b, c}, 6)} (say). M is functional because each first co-ordinate is
in A, and each first co-ordinate is only used once.
3. Let N = {(6, 2), (b, 6), (c, b), (6, {b, c})} (say). N is a not functional because the element 6
appears twice as first co-ordinate in the relation.
4. Let S = {(b, 2), (b, 6), (b, b), (b, c)} (say). N is a not functional because b appears as first co-
ordinate in every ordered pair in the relation.
From the arguments provided we can deduce that alternative 2 should be selected.
3
Question 2
Let F = {(6, {b, c}), (b, 2), (c, c), ({b, c}, 6)} be a function from A to U. Which one of the following
alternatives is true for function F?
Answer: Alternative 4
Discussion
First we look at the definition of a function:
Suppose R B × C is a binary relation from a set B to a set C. We may call R a function from B
to C if every element of B appears exactly once as the first co-ordinate of an ordered pair in R
(i.e. f is functional), and the domain of R is exactly the set B, i.e. dom(R) = B.
We also look at the definition of an injective and surjective function.
Injective function:
A function f: B C is injective iff f has the property that
whenever f(a1) = f(a2) then a1 = a2 (or whenever a1 a2 then f(a1) f(a2)) .
Surjective function:
Given a function f: B C we say that f: B C is surjective iff the range of f is equal to the
codomain of f, ie f(B) = C.
Each first co-ordinate is paired with only one unique second co-ordinate, therefore F is an injective
function. But F is not surjective. Although ran(A) = {2, 6, c, {b, c})} U, it is not true that ran(A) =
U.
From the arguments provided we can deduce that alternative 4 should be selected.
Question 3
Which one of the following relations is a bijective function on the set B = {t | (−4 t 4, t Z}?
Hint: First list the elements of set B.
Answer: Alternative 4
Discussion
Let us first look at the definition of a bijective function. A function is bijective iff it is both a
surjective and an injective function. A function f: A → B is injective iff it has the property that
4
COS1501/203
whenever f(a1) = f(a2) then a1 = a2. Alternatively, a function f: A → B is injective iff it has the
property that whenever a1 ≠ a2 then f(a1) ≠ f(a2). Given a function f: A → B, we say that
f: A → B is surjective iff the range of f is equal to the codomain of f, ie f[A] = B.
The set B is defined as B = {t | (−4 t 4, t Z}, ie B = {-3, -2, −1, 0, 1, 2, 3}. Now let us look at
the different alternatives:
1. Let L = {(-3, -3), (-1, -1), (1, 1), (3, 3)} (say). Although L is injective, (ie each first co-ordinate is
paired with only one unique second co-ordinate), L is not a function since dom(L) B.
Furthermore, L is not surjective because ran(L) = {-3, -1, 1, 3} B. Thus L is not a bijective
function.
2. Let N = {(0, -3), (0, -2), (0, -1), (0, 0), (0, 1), (0, 2), (0, 3)} (say). N is not a function because 0
appears as first co-ordinate in every ordered pair, thus dom(N) B.
3. Let S = {(-3, 0), (-2, -1), (-1, -1), (0, 0), (1, -3), (2, -3), (3, 3)} (say). There isn’t a one-to-one
relationship between the first and second co-ordinates, because first co-ordinates -2 and -1 both
have -1 as second co-ordinate, and the first co-ordinates 1 and 2 both have -3 as second co-
ordinates. Therefore S is not injective. Furthermore, S is not surjective because ran(S) =
{-3, -1, 0, 3} B. Thus S is not a bijective function.
4. Let M = {(-3, 0), (-2, -3), (-1, 3), (0, -1), (1, -2), (2, 2), (3, 1)} (say). It is clear that M is surjective
and injective. M is injective because each first co-ordinate is paired with only one unique second
co-ordinate. M is surjective, because the range of M is exactly equal to its codomain, which is B.
From the discussion we can deduce that alternative 4 provides the only bijective function on set
B.
Refer to study guide, pp 105-107, 112. Also refer to the diagram on p 108 for clarification.
5
Let f be a function on Z+ (the set of positive integers) defined by
(x, y) f iff y = 2x2 – 7 (f Z+ Z+)
and g be a function from Z+ to Q (the set of rational numbers) defined by
𝟑
(x, y) g iff y = 𝟓x + 5 (g Z+ Q).
Answer questions 4 to 7 by using the given functions f and g.
Question 4
Which one of the following is NOT an ordered pair in g?
𝟒
1. (3, 6𝟓)
𝟏
2. (4, 7𝟓)
3. (5, 8)
𝟑
4. (6, 8𝟓)
Answer: Alternative 2
Discussion
The first co-ordinates of ordered pairs in g are elements of Z + and the second co-ordinates are
elements of Q.
𝟒
Thus (3, 6𝟓) g.
𝟏
2. Is (4, 7𝟓) g?
Let x = 4 then
𝟑
y = 𝟓x + 5
𝟑
= 𝟓 . (4) + 5
2
= 75
2 1
Thus (4, 7 5) g but (4, 7 5) g.
6
COS1501/203
3. Is (5, 8) g?
Let x = 5 then
𝟑
y = 𝟓x + 5
3
= (5) + 5
5
15
= +5
5
= 8
Thus (5, 8) g.
𝟑
4. Is (6, 8𝟓) g?
Let x = 6 then
𝟑
y = 𝟓x + 5
3
= (6) + 5
5
18
= +5
5
𝟑
= 8𝟓
5.
𝟑
Thus (6, 8𝟓) g.
From the arguments provided we can deduce that alternative 2 should be selected.
Question 5
Which one of the following alternatives represents the range of g (ie ran(g))?
5
1. {y | 3 (y – 5) Q }
3
2. {y | 5 x + 5 Q }
3
3. {y | for some y Q, y = 5 x + 5 Q}
4. Q
Answer: Alternative 1
7
5
Ordered pairs (3 (y – 5) , y) are elements of g. By the definition of g it is the case that ran(g) Q.
It is important to make sure that the first co-ordinates are paired with second co-ordinates are
elements of Q since g is a function from Z+ to Q.
From the arguments provided, alternative 1 is the correct alternative.
Question 6
The relation f is NOT surjective. Which of one of the following values for y provides a
counterexample that can be used to prove that f is not surjective?
1. y = 43
2. y = 25
3. y = 12
4. y=1
Answer: Alternative 3
The function f is NOT surjective thus ran(f) ≠ Z + (Z + is the codomain). A counterexample provides
𝑦+7
a value y Z + for which there is no element x Z ,+ ie x = √ Z + such that y = 2x2 – 7 Z
2
+.
1. Let y = 43 then
43+7
x=√ 2
50
= √2
= √25
= 5 Z+ thus 43 ran(f).
2. Let y = 25 then
25+7
x=√ 2
32
= √2
= √16
= 4 Z+ thus 25 ran(f)
3. Let y = 12 then
12+7
x=√ 2
8
COS1501/203
19
=√ Z+
2
19
Thus (√ 2 , 12) f.
This means that 12 ran(f) since no x Z+ exists such that (x, 12) f. Thus y = 12 can be used
in a counterexample to prove that f is not surjective, ie ran(f) ≠ Z+.
4. Let y = 1 then
1+7
x=√ 2
8
= √2
= √4
= 2 Z+ thus 1 ran(f).
.
From the arguments provided we can deduce that alternative 3 should be selected.
Question 7
Which one of the following alternatives represents the image of x under g ○ f (ie g ○ f(x))?
6 2 4
1. x +5
5
18 2
2. x + 12x + 43
25
9 2
3. x –8
25
4. 4x2 – 21
Answer: Alternative 1
Discussion
Given the functions g: A B and f: B C the composite function
g ○ f: A C is defined by g○ f(x) = g(f(x)).
g ○ f(x)
= g(f(x))
3
= (f(x))+ 5
5
3
= 5(2x2 – 7)+ 5
6 2 21
= x – +5
5 5
9
6 2 4
= x +5
5
Let A = {□, ◊, ☼, ⌂}. Consider the following table for the binary operation *: A A A:
* □ ◊ ☼ ⌂
□ ⌂ ☼ ◊ ⌂
◊ ☼ ⌂ □ ◊
☼ ◊ ◊ ⌂ ☼
⌂ ⌂ ◊ ☼ ☼
Question 8
The binary operation * does not satisfy associativity. Which one of the following alternatives can
be used in the calculations of a counterexample to prove that * does NOT satisfy associativity?
1. Determine (☼ * □) * ◊ and ☼ * (□ * ◊).
Answer: Alternative 2
Discussion
Definition of associativity for a binary operation:
A binary operation : X X X is associative iff (y x) z = y (x z) for all x, y, z X. To
prove that is not associative a counterexample can be used to show that for some x, y, z X it
is the case that (y x) z ≠ y (x z).
10
COS1501/203
Question 9
Which of the following is true regarding an identity element for operation * ?
Discussion:
Definition of an identity element of a binary operation:
An element e of X is an identity element in respect of the binary operation : X X X iff e x
= x e = x for all x X. To prove that e is not the identity element, a counterexample can be used
to show that for some x X it is the case that e x ≠ x e.
Answer: Alternative 3
3. In a similar fashion as in alternatives 1, 2 and 4 we can also prove that □ is not an identity
element, which means none of the elements of A is an identity element. If an operation has
an identity element, the row to the right of the identity element must be the same as the top
row of the table. Similarly the column below the identity element must be the same as the
leftmost column of the table.
11
4. ☼ is not the identity element. We provide a counterexample: From the table ☼ * □ = ◊ ≠ □
and □ * ☼ = ◊ ≠ □. Thus this alternative provides a counterexample that proves that is ☼ not
the identity element.
From the above arguments we can deduce that alternative 3 should be selected.
Question 10
Perform the following matrix multiplication operation:
−4 0
1 2 3
[ ] . [−2 −1]
4 0 −3
0 1
Which one of the following alternatives represents the correct answer to the above operation?
−8 −16
2. [ ]
1 −3
−4 0
3. [−4 0 ]
0 −3
−8 1
4. [ ]
−16 −3
Answer: Alternative 4
Discussion
A 2 3 matrix multiplied by a 3 2 matrix gives a 2 2 matrix.
We determine aij:
a11 = 1(-4) + 2(-2) + 3(0) = -8
a12 = 1(0) + 2(-1) + 3(1) = 1
12
COS1501/203
Question 11
Let p and q be simple declarative statements. Which one of the following statements is not a
logical equivalence – in other words which one of the expressions is false? (Hint: Use truth tables
to get to a conclusion)
1. (¬p ∨ q) ≡ ((¬(¬p)) q)
2. (¬q (p ∧ q)) ≡ ((¬q ∨ p) ∧ ¬q)
3. ((q ∧ p) (¬p ∨ ¬q)) ≡ (p ¬q )
4. (p ∨ (q p)) ≡ (p ∨ ¬q)
Answer: Alternative 2
Discussion:
Remember that if such an equivalence is true, it means that the expression is a tautology, which
can easily be determined using truth tables. The ≡ equivalence symbol has the same meaning as
the symbol. We also show how the LHS and RHS of the expression can be simplified using
the important logical equivalences in the study guide p. 147, and then a conclusion can be made.
T T F T T T T
T F F T F F T
F T T F T T T
F F T F T T T
From the last column it is clear that the expression is a tautology, in other words
(¬p ∨ q)) ≡ ((¬(¬ p)) q).
We also show how to simplify the LHS and RHS by using logical equivalences:
LHS: (¬p ∨ q)
≡ pq (*Comment: This is proven on p 147 of the study guide by using truth
tables. You should always remember this, because you will be using
it very often in proofs.)
RHS: ((¬(¬p)) q)
≡ pq (double negation rule)
13
2. Is (¬q (p ∧ q)) ≡ ((¬q ∨ p) ∧ ¬q)?
p q ¬q p∧q ¬q ∨ p (¬q (p ∧ q) ((¬q ∨ p) ∧ ¬q) (¬q (p ∧ q)) ((¬q ∨ p) ∧ ¬q)
T T F T T T F F
T F T F T F T F
F T F F F T F F
F F T F T F T F
From the last column it is clear that the expression is not a tautology, but a contradiction.
Now we simplify the LHS and RHS and see if we get the same result:
LHS: ¬q (p ∧ q)
≡ ¬(¬q) ∨ (p ∧ q) (* see comment alternative 1)
≡ q ∨ (p ∧ q) (law of double negation)
≡ (q ∨ p) ∧ (q ∨ q) (distributive laws)
≡ (q ∨ p) ∧ q (idempotent laws)
This expression has the same format as the RHS (¬q ∨ p) ∧ ¬q. Clearly, the LHS and RHS are not
equivalent. If you are not convinced, draw truth tables for the simplified LHS and the RHS.
Alternative 2 is therefore the correct alternative to choose.
14
COS1501/203
4. (p ∨ (q p)) ≡ (p ∨ ¬q)
p q ¬q qp p ∨ (q p) (p ∨ ¬q)
T T F T T T T
T F T T T T T
F T F F F T F
F F T T T T T
Now we simplify the LHS and RHS and see if we get the same result:
LHS: p ∨ (q p)
≡ p ∨ (¬q ∨ p) (* see comment alternative 1)
≡ (p ∨ p) ∨ ¬q (associative laws)
≡ p ∨ ¬q (idempotent laws)
which is exactly the RHS of the expression. Thus the expression is true.
Question 12
Consider the expression ((p q) r) (r ∧ (¬q ∨ ¬p)) as well as an incomplete truth table
representing the expression.
p q r ((p q) r) (r ∧ (¬q ∨ ¬p))
T T T
T T F
T F T
T F F
F T T
F T F
F F T
F F F
Which one of the alternatives represents the correct truth values for the last column?
15
1.
F
T
T
F
T
T
T
T
2.
T
T
T
T
T
F
T
F
3.
T
T
T
T
T
T
T
T
4.
F
F
F
F
F
F
F
F
Correct alternative: 1
16
COS1501/203
Discussion:
We determine the truth values in all the columns:
T T T F F T F T F F
T T F F F T F F T F
T F T F T F T T T T
T F F F T F T T F F
F T T T F T T T T T
F T F T F T T F T F
F F T T T T T T T T
F F F T T T T F T F
Question 13
Which one of the alternatives provides the negation of the statement
𝑥
∃x ∈ R, [(2 ≥ 0) ∧ (x – 4 < 0)]?
𝑥
1. ∀x ∈ R, [(2 < 0) ∧ (x – 4 ≥ 0)]
𝑥
2. ∃x ∈ R, [(2 < 0) ∨ (x – 4 ≥ 0)]
𝑥
3. ∀x ∈ R, [(2 < 0) ∨ (x ≥ 4)]
𝑥
4. ∀x ∈ R, [(2 ≤ 0) ∨ (x > 4)]
Correct alternative: 3
Discussion:
We will derive the negation of the given statement step by step:
𝑥
¬[∃x ∈ R, [(2 ≥ 0) ∧ (x – 4 < 0)]] (always write down this step)
𝑥
≡ ∀x ∈ R, ¬[(2 ≥ 0) ∧ (x – 4 < 0)]
𝑥
≡ ∀x ∈ R, ¬(2 ≥ 0) ∨ ¬(x – 4 < 0) (de Morgan’s law)
𝑥
≡ ∀x ∈ R, (2 ≱ 0) ∨ (x – 4 ≮ 0)
𝑥
≡ ∀x ∈ R, (2 < 0) ∨ (x – 4 ≥ 0)
𝑥
≡ ∀x ∈ R, (2 < 0) ∨ (x ≥ 4)
From the derivation above it is clear that alternative 3 is the correct alternative.
17
Question 14
The negation of the statement
∀x ∈ Z+, [(x2 > 2x) ∨ (x – 1 ≥ 0)]
can be written as:
∃x ∈ Z+, [(x2 – 2x ≤ 0) ∧ (x – 1 < 0)].
Which one of the following alternatives is true regarding the statement and its negation?
Correct alternative: 4
Discussion:
Let us look at the statement first:
∀x ∈ Z+, [(x2 > 2x) ∨ (x – 1 ≥ 0)]
This statement states, that for all positive integers x, it is true that (x2 > 2x) or (x – 1 ≥ 0). This
means that at least (x2 > 2x) or (x – 1 ≥ 0) must be true for the statement to be true. Both may
also be true. (Refer to the truth table for the disjunction ‘∨’.)
We substitute a few positive integers for x in both (x2 > 2x) and (x – 1 ≥ 0) and see where that
takes us:
x x2 > 2x x–1≥0
etc… etc…
We can see that for all x > 4, both x2 > 2x and x – 1 ≥ 0 will always be true. We actually only need
one of the statements to be true for [(x2 > 2x) ∨ (x – 1 ≥ 0)] to be true, so for x =1 and x = 2 the
statement [(x2 > 2x) ∨ (x – 1 ≥ 0)] is also true, even though x2 > 2x is false, because
x – 1 ≥ 0 is true in both cases. We can therefore deduce that the original statement is true.
What about the negation statement?
∃x ∈ Z+, [(x2 – 2x ≤ 0) ∧ (x – 1 < 0)]
The negation statement reads that there exists a positive integer, such that both (x2 – 2x ≤ 0) and
(x – 1 < 0) are true. We will substitute some positive values for x in the statements
18
COS1501/203
(x2 – 2x ≤ 0) and (x – 1 < 0) and see whether we can find at least one positive integer for which
[(x2 – 2x ≤ 0) ∧ (x – 1 < 0)] is true.
x x2 – 2x ≤ 0 x–1<0
We need not go any further. We can see that x – 1 < 0 will always be false for all positive integers,
which implies that it is impossible for both (x2 – 2x ≤ 0) and (x – 1 < 0) to be true for any positive
integer. The negation of the original statement is therefore false. From the discussion above,
alternative 4 is the correct alternative.
Question 15
Which one of the alternatives is a proof by contradiction for the statement
“If 2x2 – 3x + 7 is odd, then x is even.”
2. Assume that 2x2 – 3x + 7 is odd. Then x can be even or odd. We assume that x is odd.
Let x = 2k + 1, then
2x2 – 3x + 7 = 2(2k+1)2 – 3(2k + 1) + 7
= 2(4k2 + 4k +1) – 6k – 3 + 7
= 8k2 + 8k + 2 – 6k – 3 + 7
= 8k2 + 2k + 6
= 2(4k2 + k + 3), which is even (2 multiplied by any integer is even)
Correct alternative: 2
Discussion: It is very important that you know how to apply each of the proof methods discussed
in the study guide.
We look at each of the alternatives:
1. The proof provided in this alternative is a proof by contrapositive. Another way to look at this
proof method is the following:
The contrapositive of p q is ¬q ¬p. This means that p q is logically equivalent to ¬q ¬p.
The contrapositive of the statement ‘if 2x2 – 3x + 7 is odd, then x is even’ is:
If x is not even, then 2x2 – 3x + 7 is not odd,
ie if x is odd, then 2x2 – 3x + 7 is even.
This is exactly what is proven in alternative 1.
2. This alternative provides a proof by contradiction. We assume the ‘if’ part of the given statement
is true, ie “2x2 – 3x + 7 is odd” is true, then we assume the opposite of the ‘then’ part. The ‘then’
part states that “x is even”, so we assume the opposite, ie “x is odd”, and then try to get to a
contradiction. This alternative provides the required proof by contradiction.
3. This alternative is not a proof. One cannot substitute values for x in a proof. One example (ie
choosing a value for x and substituting it in the expression) does not provide a general proof to
show that
“If 2x2 – 3x + 7 is odd, then x is even”.
4. This proof is not valid. If p is the statement ‘2x2 – 3x + 7 is odd’ and q is the statement ‘x is
even’, we have to prove that p q is true. The proof in this alternative proves that q p is true.
UNISA 2018
20