Tma4140 Mock-Exam 2022 Solutions
Tma4140 Mock-Exam 2022 Solutions
!!! Note that this is a mock exam for fall 2022, not the real exam !!!
Language: English
Number of pages: 14
Number of pages enclosed: 0
Checked by:
Informasjon om trykking av eksamensoppgave
Originalen er:
1-sidig □ 2-sidig ⊠
sort/hvit □ farger ⊠ Date Signature
skal ha flervalgskjema □
Mock Exam Solutions TMA4140 Discrete Mathematics Fall 2022 Page 1 of 14
i) q ∨ (q → ¬q)
ii) ¬((¬r ∧ r) → s)
iii) ((t → s) → t) → t
Solution.
a. i) q ∨ (q → ¬q)
q ¬q (q → ¬q) q ∨ (q → ¬q)
0 1 1 1
1 0 0 1
A tautology.
Page 2 of 14 Mock Exam Solutions TMA4140 Discrete Mathematics Fall 2022
ii) ¬((¬r ∧ r) → s)
r ¬r ¬r ∧ r s (¬r ∧ r) → s ¬((¬r ∧ r) → s)
1 0 0 1 1 0
0 1 0 1 1 0
0 1 0 0 1 0
1 0 0 0 1 0
A contradiction.
iii) ((t → s) → t) → t
t s t→s (t → s) → t ((t → s) → t) → t
1 1 1 1 1
1 0 0 1 1
0 1 1 0 1
0 0 1 0 1
A tautology.
a. (4 points) Let X, Y be arbitrary sets. Use the laws of set theory to show
that:
If (X ∪ Y ) ⊆ (X ∩ Y ) then X = Y.
b. (6 points) Use the laws of set theory to show that for sets X, Y, Z we have
that
(Y − Z) ⊆ X if and only if (X ∩ Y ) ⊆ Z.
Solution.
b. To prove an if and only if statement we must show that each condition implies
the other. We will start by assuming that (Y − Z) ⊆ X is true and that
(X ∩ Y ) ⊆ Z follows. Consider the case where (X ∩ Y ) ⊆ Z is not true i.e.
that (X ∩ Y ) ̸⊆ Z. Then ∃x ∈ X ∩ Y such that x ̸∈ Z. Because x ∈ X ∩ Y
we know that x ∈ Y and thus x ∈ Y − Z. But Y − Z ⊆ X and this implies
x ∈ X, a contradiction. Then if (Y − Z) ⊆ X is true (X ∩ Y ) ⊆ Z must also
be true.
We now assume that (X ∩Y ) ⊆ Z is true and show that (Y −Z) ⊆ X follows
using the same approach; namely we consider the case where (X ∩ Y ) ⊆ Z is
true and that (Y − Z) ̸⊆ X in order to find a contradiction. If (Y − Z) ̸⊆ X
then ∃x ∈ X where x ∈ Y − Z as well. This also implies that x ∈ Y , but if
x ∈ X and x ∈ Y then x ∈ X ∩Y ⊆ Z, a contradiction. Then if (X ∩Y ) ⊆ Z
is true (Y − Z) ⊆ X must also be true.
Page 4 of 14 Mock Exam Solutions TMA4140 Discrete Mathematics Fall 2022
Solution.
Solution. Denote the Boolean algebra by B. The axioms are the following:
(x · x · x · y · y + x · y · y) · (x · x + x · y · y · y).
x · x = x: (x · y + x · y) · (x + x · y).
Commutative: (y · x + y · x) · (x + x · y).
Distributive and absorption: y · (x + x) · x.
x + x = 1: y · (1) · x.
Identity law: y · x.
and
Solution.
a. See diagram:
Mock Exam Solutions TMA4140 Discrete Mathematics Fall 2022 Page 7 of 14
343
49
c. (6 points)
Solution.
a. For the base case let n = 1, then 4 k=1 (k +2k)(k+4) = (12 +1)(1+4)(1+5)
P1 2
b. For the base case let n = 1: k(k!) = (1 + 1)! − 1, we have that 1(1!) =
P1
k=1
2! − 1 = 1.
Assume this is true up to n = i:
k(k!) = (i + 1)! − 1
Pi
k=1
We start with our assumption and add 2k + 1 to both sides of the in-
equality: k 2 + 2k + 1 ≥ 2k + 1 + (2k + 1). Note that because n > 2 we
Mock Exam Solutions TMA4140 Discrete Mathematics Fall 2022 Page 9 of 14
Then we factor the left side and replace (2k + 1) with 2 on the right
side: (k + 1)2 ≥ 2k + 3 = 2(k + 1) + 1, which is what we wanted to
show. Then n2 ≥ 2n + 1 for n > 2.
ii) Testing the natural numbers n = 1, 2, 3, 4, 5, ... we see that 2n ≥ n2 does
not hold for n = 3 but seems to hold beyond that. Then we will use
n = 4 as our base case and assume 2n ≥ n2 holds up to n = k : 2k ≥ k 2 .
We then want to show that this holds for n = k + 1 : 2k+1 ≥ (k + 1)2 .
Starting with our assumption 2k ≥ k 2 we multiply both sides of the
inequality by 2: 2 · 2k ≥ 2 · k 2 which yields 2k+1 ≥ k 2 + k 2 . We know
from i) that k 2 ≥ 2k + 1 for k > 2, so then we can replace k 2 with 2k + 1
without affecting the inequality: 2k+1 ≥ k 2 + 2k + 1 = (k + 1)2 which is
what we wanted to show. Then 2n ≥ n2 for n = 1, 2 and all n ≥ 4.
Solution.
b. (6 points)
i) (1 point) There are three possible symbols and we are sampling six, so
there are 36 = 729 different strings of length six in the language L.
ii) (2 points) We have 729 possible strings, and we subtract the strings with
none or one a. There are 26 = 64 strings that only contains b’s and c’s.
Further, if we have a string with a only in the first position, then there
are 25 such strings. The symbol a can be in six different positions, so
there are 6 · 25 = 192 strings with exactly one a. In conclusion, there
are 729 − 64 − 192 = 473 different strings with at least two a’s.
iii) (3 points) This is an unordered sampling with repetition with n = 3
symbols and k = 6 samples. This can be visualized with 2 walls (|),
for example as a’s|b’s|c’s, and 6 stars (∗), and we get samples
of the
form ∗ ∗ ∗ ∗ ∗∗| | or ∗|∗ ∗ ∗∗|∗ and so on. There are n+k−1
k
possible
outcomes, and we get 8
6
= 8!
6!·2!
= 8·7
2
= 28 distinct combinations.
0 1 0 1 0 1
1 0 1 0 1 0
0 1 0 1 0 1
1 0 1 0 1 0
0 1 0 1 0 1
1 0 1 0 1 0
Solution.
b. (6 points)
(a) (1 points) More than two vertices has an odd degree, so there can not
exist an Euler trail. In this case, every vertex has an odd degree.
(b) (1 points) It is not the case that all vertices has an even degree, so there
can not exist an Euler circuit. This is a necessary requirement.
(c) (2 points) There are many Hamiltonian paths in this graph. We can
choose any starting vertex, and go back and forth between vertices in
{1, 3, 5} and vertices in {2, 4, 6}, for example 1 → 2 → 3 → 4 → 5 → 6.
Page 12 of 14 Mock Exam Solutions TMA4140 Discrete Mathematics Fall 2022
(d) (2 points) Similar to above, choose any starting vertex and go back and
forth between the sets, for example 1 → 2 → 3 → 4 → 5 → 6 → 1.
a. (4 points) Let (n, e) = (143, 11) be the public key in the RSA cryptosystem.
Find the secret key (p, q, d) and decrypt the ciphertext c = 5 to find the
secret message m.
3x + 2 ≡ 3 (mod 7)
x−4≡1 (mod 5)
5x ≡ 1 (mod 9)
Solution.
b. We first note that all moduli are relatively prime and we will then be able
to find a unique solution modulo 5 · 7 · 9 = 315. We then subtract to get x
isolated on the left side, and get
3x ≡ 1 (mod 7)
x≡0 (mod 5)
5x ≡ 1 (mod 9)
Mock Exam Solutions TMA4140 Discrete Mathematics Fall 2022 Page 13 of 14
Multiply with 3−1 ≡ 5 (mod 7) in the first row and 5−1 ≡ 2 (mod 9) in the
third row to get
x≡5 (mod 7)
x≡0 (mod 5)
x≡2 (mod 9)
a. (2 points) Draw the transition diagram of the finite state machine F with
input I = {a, b}, output O = {0, 1} and states S = {s0 , s1 } (initial state
is s0 ) and the following transition table. What is the output for the input
string abba?
F η µ
a b a b
s0 s1 s0 0 0
s1 s0 s0 1 1
b. (3 points) Draw the transition diagram of a finite state machine with input
and output O = I = {0, 1}, which outputs 1 when it sees the first 0 in the
input string and continues outputting 1 until it sees another 0; thereafter it
outputs 0. In all other cases it outputs 0.
c. (5 points) Draw the transition diagram of a finite state automaton with input
I = {a, b} that accepts strings with an even number of a’s.
Page 14 of 14 Mock Exam Solutions TMA4140 Discrete Mathematics Fall 2022
Solution.
a. The output for the input string abba is 0100. See diagram:
start
a, 0
s0 s1
b, 0
a, 1, b, 1
b. See diagram:
start
0, 1 0, 0
s0 s1 s2
1, 0 1, 1
(1, 0), (0, 0)
c. See diagram:
start
a
s0 s1
b a
b