0% found this document useful (0 votes)
52 views16 pages

Tma4140 Mock-Exam 2022 Solutions

The document is a mock exam for a discrete mathematics course containing 10 problems related to topics such as logic, sets, functions, Boolean algebra, relations, induction, combinatorics, graphs, number theory, and finite state machines. The exam is 14 pages long and has a total of 100 points. Students are allowed to bring a stamped yellow sheet with handwritten formulas and notes as examination support material. The summary identifies the course, topic breakdown, point distribution, and permitted examination aids for the mock exam.

Uploaded by

samsonhatyoka100
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views16 pages

Tma4140 Mock-Exam 2022 Solutions

The document is a mock exam for a discrete mathematics course containing 10 problems related to topics such as logic, sets, functions, Boolean algebra, relations, induction, combinatorics, graphs, number theory, and finite state machines. The exam is 14 pages long and has a total of 100 points. Students are allowed to bring a stamped yellow sheet with handwritten formulas and notes as examination support material. The summary identifies the course, topic breakdown, point distribution, and permitted examination aids for the mock exam.

Uploaded by

samsonhatyoka100
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Department of Mathematical Sciences

Examination paper for TMA4140 Discrete Mathematics

Academic contact during examination: Navn Navnesen


Phone: +47 XX XX XX XX

Examination date: December 2022


Examination time (from–to): 00:00 - 23:59
Permitted examination support material: Permitted examination aids code C: Specified printed
and hand-written support material is allowed. A specific basic calculator is allowed. We specify
that it is allowed to bring a stamped yellow A4 sheet with your own handwritten formulas and
notes. The calculators allowed for examination aids code C is listed on the NTNU website.

!!! 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

This exam has the following structure:

Problem 1: Logic 10 points


Problem 2: Sets 10 points
Problem 3: Functions 10 points
Problem 4: Boolean algebra 10 points
Problem 5: Relations 10 points
Problem 6: Induction 10 points
Problem 7: Combinatorics 10 points
Problem 8: Graphs and trees 10 points
Problem 9: Number theory 10 points
Problem 10: Finite state machines and automata 10 points
Total: 100 points

The answer to every problem requires a detailed argument/computation.

Problem 1 Logic (10 points)

a. (3 points) Use truth tables to determine which of the following statements


are tautologies and which are contradictions (1 point each):

i) q ∨ (q → ¬q)
ii) ¬((¬r ∧ r) → s)
iii) ((t → s) → t) → t

b. (7 points) Let p, q, r, s, t, u be primitive statements. Provide a step by step


verifications of the inference
       
(¬p ∨ q) → r ∧ r → (s ∨ t) ∧ ¬s ∧ ¬u ∧ ¬u → ¬t → p

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.

b. From the laws of inference we have:


Mock Exam Solutions TMA4140 Discrete Mathematics Fall 2022 Page 3 of 14

Problem 2 Sets (10 points)

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.

a. By the law of distributivity we have that ((X ∩X)∪(X ∩Y )) ⊆ (X ∩X ∩Y ).


Simplifying we see that X ∪ (X ∩ Y ) = X, then X ⊆ (X ∩ X ∩ Y ) and
X ⊆ (X ∩ Y ). By definition X ∩ Y ⊆ X. This implies that X = X ∩ Y .
Similarly we have that Y = Y ∩ X. Then X = Y .

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

Problem 3 Functions (10 points)

a. (5 points) Let g : A → B and f : B → C be two functions. Show that if g


and f are both injective, then f ◦ g : A → C is injective.
b. (5 points) Let f : A → B and g : B → C. Show that if g ◦ f : A → C is
surjective, then g is surjective.

Solution.

a. To show that f ◦ g : A → C is injective we must show that ∀a, b ∈ A


f (g(a)) = f (g(b)) =⇒ a = b. Consider the function f , we know that f is
injective (that is: f (a) = f (b) =⇒ a = b. Then from this we know that the
statement f (g(a)) = f (g(b)) =⇒ g(a) = g(b), but g is also injective which
implies that a = b. Then f ◦ g : A → C is injective.
b. We start by assuming that g ◦ f : A → C is surjective and then consider
the case where g is not surjective. g ◦ f : A → C is surjective means that
∀c ∈ C, ∃a ∈ A s.t. g(f (a)) = c where f (a) ∈ B. But if g is not surjective
this implies that ∃c ∈ C s.t. ¬∃f (a) ∈ B s.t. g(f (a)) = c which contradicts
the surjectivity of g ◦ f : A → C. Then if g ◦ f : A → C is surjective g must
also be surjective.

Problem 4 Boolean algebra (10 points)

a. (1 point) Let B be a Boolean algebra. Simplify the following Boolean ex-


pression
(x · x · x · y · y + x · y · y) · (x · x + x · y · y · y).

b. (3 points) Let B be a Boolean algebra. Show that x = 0 if and only if


y = xy + xy for all y.
c. (6 points) Consider the set X = {1, 2, 4, 8} and define the binary operations
+ : X × X → X and · : X × X → X
x + y := lcm(x, y) resp. x · y := gcd(x, y)
(recall define the notions of least common multiple (lcm) the greatest com-
mon divisor (gcd)) and the unary operation : X → X, x 7→ x := 8/x. Is
(X, +, ·, , 1, 8) a Boolean algebra? Provide a detailed justification for your
answer.
Mock Exam Solutions TMA4140 Discrete Mathematics Fall 2022 Page 5 of 14

Solution. Denote the Boolean algebra by B. The axioms are the following:

Commutativity: (∀x, y ∈ B)(x + y = y + x and x · y = y · x)


Identity axioms: (∀x ∈ B)(x + 0 = x and x · 1 = x)
Complement axioms: (∀x ∈ B)(x + x = 1 and x · x = 0)
Distributivity of multiplication over addition: (∀x, y, z ∈ B)(x · (y + z) = x · y + x · z)
Distributivity of addition over multiplication: (∀x, y, z ∈ B)(x + y · z = (x + y) · (x + z))

a. We use the laws of boolean variables to simplify:

(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.

b. Assume that x = 0. Then y = 0 · y + 1 · y = y by dominance and identity


laws. Assume that y = xy + xy ∀y and that x ̸= 0. For example, set y = 1.
Then 1 = x · 0 + x̄ · 1 = x̄, which is a contradiction. Thus x = 0.

c. In order to determine if (X, +, ·, , 1, 8) is a Boolean algebra we must make


sure it meets the conditions required by the definition. Namely that it satis-
fies the commutative, distributive, identity, inverse, and inequality of special
element laws.

• Commutativity follows from lcm(x, y) = lcm(y, x) and gcd(x, y) =


gcd(y, x).
• Additive identity: x+1 = lcm(x, 1) = x. Multiplicative identity: x·8 =
gcd(x, 8) = x.
• Additive inverse: We would expect that x + x = 8, however consider
the case where x = 2. Then we have that x + x = 4 ̸= 8. Then this is
not a Boolean algebra.
• Multiplicative inverse: We would expect that x · x = 1, however again
in the case where x = 2 we have that x · x = 2 ̸= 1. Then this is not a
Boolean algebra.
Page 6 of 14 Mock Exam Solutions TMA4140 Discrete Mathematics Fall 2022

• Distributivity: Note that any element in S can be written as x = 2i ,


with i ∈ {0, 1, 2, 3}. Let x = 2ix , y = 2iy , z = 2iz , then:

x(y + z) =gcd(x, lcm(y, z))


=gcd(x, 2max(iy ,iz ) )
=2min(ix ,max(iy ,iz ))
=2max(min(ix ,iy ),min(ix ,iz ))
=lcm(gcd(x, y), gcd(x, z))
=xy + xz,

and

x + yz =lcm(x, gcd(y, z))


=2max(ix ,min(iy ,iz ))
=2min(max(ix ,iy ),max(ix ,iz ))
=gcd(lcm(x, y), lcm(x, z))
=(x + y)(x + z).

From either of the unmet laws (additive or multiplicative inverse) we can


conclude that (X, +, ·, , 1, 8) is not a Boolean algebra.

Problem 5 Relations (10 points)

a. (4 points) Draw the Hasse diagram for the divisors of 343.

b. (6 points) Recall that a relation R on a set A is antisymmetric if it does not


contain any pair of distinct elements of A each of which is related by R to
the other. Prove that the relation R defined on the set A is antisymmetric
if and only if R ∩ R−1 ⊆ {(a, a) | a ∈ A}.

Solution.

a. See diagram:
Mock Exam Solutions TMA4140 Discrete Mathematics Fall 2022 Page 7 of 14

343

49

b. We will start by assuming that R on the set A is antisymmetric and show


that R ∩ R−1 ⊆ {(a, a) | a ∈ A}. Consider the elements b, c ∈ A such
that (b, c) ∈ R ∩ R−1 . If (b, c) ∈ R−1 then (c, b) ∈ R. Then we have that
bRc and cRb which implies that b = c since R is antisymmetric. Then
(b, c) ∈ {(a, a) | a ∈ A} which implies that R ∩ R−1 ⊆ {(a, a) | a ∈ A}.
We now assume R ∩ R−1 ⊆ {(a, a) | a ∈ A} and show that R on the set A
must be antisymmetric. Consider if R is not antisymmetric. This means that
∃(b, c) ∈ R such that (c, b) ∈ R with b ̸= c. If (c, b) ∈ R then (b, c) ∈ R−1 and
consequently (b, c) ∈ R∩R−1 . By our assumption R∩R−1 ⊆ {(a, a) | a ∈ A},
but (b, c) ∈ R ∩ R−1 is not in {(a, a) | a ∈ A}, this is a contradiction. Then
R must be antisymmetric.

Problem 6 Induction (10 points)

a. (1 point) Show that for all natural numbers: 4 k=1 (k + 2k)(k + 4) =


Pn 2

(n2 + n)(n + 4)(n + 5).

b. (3 points) Show that k(k!) = (n + 1)! − 1.


Pn
k=1

c. (6 points)

i) (2 points) Show that n2 ≥ 2n + 1 for n > 2.


ii) (4 points) Then determine for which natural numbers we have 2n ≥ n2 .
Page 8 of 14 Mock Exam Solutions TMA4140 Discrete Mathematics Fall 2022

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

and 4(3)(5) = (2)(5)(6) = 60.


Assume this is true up to n = i:
4 k=1 (k + 2k)(k + 4) = (i2 + i)(i + 4)(i + 5).
Pi 2

We then want to show that this is true for n = i + 1:


P(i+1)
4 k=1 (k 2 + 2k)(k + 4) = [(i + 1)2 + (i + 1)][(i + 1) + 4][(i + 1) + 5] (Note
that the right side of this equation simplifies to (i + 1)(i + 2)(i + 5)(i + 6)).
P(i+1)
We see that 4 k=1 (k 2 + 2k)(k + 4) = 4 ik=1 (k 2 + 2k)(k + 4) + 4[(i + 1)2 +
P

2(i + 1)][(i + 1) + 4].


Using our assumption we can get rid of the summation:
4 ik=1 (k 2 + 2k)(k + 4) + 4[(i + 1)2 + 2(i + 1)][(i + 1) + 4] = (i2 + i)(i + 4)(i +
P

5) + 4[(i + 1)2 + 2(i + 1)][(i + 1) + 4].


Simplifying by factoring we get (i + 5)(i + 1)[i2 + 8i + 12] = (i + 1)(i + 2)(i +
5)(i + 6).
Then it is true for n = i + 1 and for all natural numbers that 4 nk=1 (k 2 +
P

2k)(k + 4) = (n2 + n)(n + 4)(n + 5).

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 then want to show that this is true for n = i + 1:


k(k!) = [(i + 1) + 1]! − 1.
Pi+1
k=1

We see that i+1 k=1 k(k!) = k=1 k(k!) + (i + 1)(i + 1)! =


i
P P

(i + 1)! − 1 + (i + 1)(i + 1)! = [(i + 1)! + (i + 1)(i + 1)!] − 1 =


(i + 1)![i + 2] − 1 = (i + 2)! − 1 = [(i + 1) + 1]! − 1 which is what we wanted
to show. Then nk=1 k(k!) = (n + 1)! − 1.
P

c. i) For the base case let n = 3. Then we have that 9 ≥ 7.

Assume this is true up to n = k : k 2 ≥ 2k + 1. Then we want to show


that this is true for n = k + 1 : (k + 1)2 ≥ 2(k + 1) + 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

have that 2k + 1 ≥ 7. This allow us to replace (2k + 1) with anything


smaller than or equal to 7 to make the equation go up.

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.

Problem 7 Combinatorics (10 points)

a. (4 points) A string is a palindrome if the string is the same when we read


it from the left and from the right, for example: tacocat. Let the alphabet
be the symbols {a, b, c, d, e}. How many palindromes of length 11 exists over
this alphabet?
b. (6 points) Let L be the language {a, b, c}∗ consisting of all strings over the
alphabet {a, b, c}. How many
i) (1 point) strings in L have length 6?
ii) (2 points) strings in L of length 6 have at least two a’s?
iii) (3 points) strings in L of length 6 are sorted (so that all a’s are in front
of all b’s which are in front of all c’s)?

Solution.

a. (4 points) Any palindrome of length 11 is of the form sxs̄ where x is a single


symbol, s is a string of length 5 and s̄ is the reversed string of s. The
palindrome is then uniquely determined of the string s and the symbol x.
For each symbol in s there are five options, and similarly for x. It follows
that there are 56 = 15625 different palindromes of length 11.
Page 10 of 14 Mock Exam Solutions TMA4140 Discrete Mathematics Fall 2022

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.

Problem 8 Graphs and trees (10 points)

a. (4 points) Let G be a graph with vertices V = {1, 2, 3, 4, 5, 6}. Draw the


graph of the following adjacency matrix, where an index (i, j) in the matrix
is 0 if there is no edge from vertex i to vertex j and 1 if there is. Is the graph
connected? Is the graph complete?

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

b. (6 points) Does the graph have

(a) (1 point) an Euler trail?


(b) (1 point) an Euler circuit?
(c) (2 points) a Hamiltonian path?
(d) (2 points) a Hamiltonian cycle?
Mock Exam Solutions TMA4140 Discrete Mathematics Fall 2022 Page 11 of 14

Figure 1: The graph given by the adjacency matrix in problem 8.

Solution.

a. (4 points) See drawing in the figure. This is a complete bipartite graph


and is denoted K3,3 . The graph is connected since each vertex in {1, 3, 5}
is connected to each vertex in {2, 4, 6}, so there is a path between each pair
of vertices in the graph. The graph is not complete since there is no edge
between vertices in {1, 3, 5} and no edge between vertices in {2, 4, 6}.

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.

Problem 9 Number theory (10 points)

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.

b. (6 points) Find all integer solutions x to the following system of congruences:

3x + 2 ≡ 3 (mod 7)
x−4≡1 (mod 5)
5x ≡ 1 (mod 9)

Solution.

a. We have that n = 143 = 11 · 13 = p · q and it follows that φ(n) =


(p − 1) · (q − 1) = 120. We then find the secret exponent d by solving
e · d ≡ 1 (mod φ(n)). We can compute this using Euclid’s extended al-
gorithm, but in this case we note that 112 = 121 ≡ 1 (mod 120) and it
follows that d = e = 11 (this would of course not be secure...). We com-
pute 5 to the following powers of two modulo 143: 54 = 252 = 625 ≡ 53
and 58 ≡ 532 = 2809 ≡ 92. Then we decrypt the ciphertext by computing
m ≡ cd = 511 = 51+2+8 = 5 · 25 · 92 ≡ 11500 ≡ 60 (mod 143). In conclusion,
we get secret key (p, q, d) = (11, 13, 11) and message m = 60.

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)

The solution is x ≡ ri=1 ai Mi ki (mod M ) where r is the number of con-


P

gruences of the form x ≡ ai (mod mi ), M = m1 · · · · · mr is the product of


all individual moduli, Mi = M/mi , and ki is the inverse of Mi modulo mi .
We compute k1 ≡ 45−1 ≡ 3−1 ≡ 5 (mod 7) and k3 ≡ 35−1 ≡ (−1)−1 ≡ −1
(mod 9). Solution: x ≡ 5 · 45 · 5 − 2 · 35 = 1055 ≡ 110 (mod 315).

Problem 10 Finite state machines and automata (10 points)

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

You might also like