Problem Sheet (70 points required)
Regular Expression (5mks): January 29th – February 12th
Create a regular expression represenng the language L, defined as the set of binary strings where either
the substring "00" is absent or the length of the string is of the form 3n+1, where n is a non-negave
integer.
It’s a union operaon: substring "00" is absent ∪ length of the string in the form 3n+1
substring "00" is absent
An empty string is accepted ε
For the symbol 1 - it can have a series of 1*
For the symbol 0
o a single 0 0
o where multiple 0 occurs a 1 must be before or after ∪ε))* ∪ ((0∪
(1(0∪ ∪ε)1)*
length of the string in the form 3n+1
If n=0, then length = 3(0)+1 = 1 ∪1 ≡ Σ
0∪
3
If n=1, then length = 3(1)+1 = 3 + 1 Σ .ΣΣ
If n=k, then length = 3k + 1 (Σ3)*.Σ
∗ ∗ ∗
RE: ∪ ∪ ∪ ∪ ∪ ∪ .
DFA Minimiza*on (7mks): February 5th – February 19th
Construct minimum state automata. Equivalent to given automata M formally defined as
({q0,q1,q2,q3,q4,q5,q6,q7}, {a,b}, δ, q6, {q1,q2,q5,q7}).
δ a b
q0 q6 q1
q1 q4 q4
q2 q3 q4
q3 q7 q2
q4 q7 q5
q5 q3 q3
q6 q0 q2
q7 q7 q4
Minimized DFA:
1|Page
Finite Automaton (8mks): February 12th – February 26th
Create a finite automaton (DFA or NFA) with four states (Idle, Lid Up, Lid Down, Flush) to model the
behaviour of an automated toilet. These states are influenced by the following events:
In the Idle state, the presence of a detected person triggers the lifting of the toilet lid, which will
remain open as long as a person is present. The lid will close upon the person's departure.
Once the lid is closed, if no waste is detected, the toilet will return to the Idle state. If waste is
detected, the toilet will initiate a flush and transition back to the Idle state once the waste is
gone.
The accepng state is Idle, indicang that the toilet is clean and ready for subsequent use. The events
should be represented using the following symbols:
n: No Presence Detected
p: Presence Detected
w: Waste
c: Clean
Equivalence (9mks): February 12th – February 26th
Do set A or B
SET A
Part 1 (4mks): Given the regular expression: (00)*(1(01)1+ ∪ 1*) draw an equivalent
nondeterminisc finite automaton (NFA).
Part 2 (5mks): Transform the NFA created in Part 1 to an equivalent determinisc finite automaton (DFA).
NFA
DFA
2|Page
SET B
Part 1 (4mks): Transform the nondeterminisc finite automaton (NFA) below to an equivalent
determinisc finite automaton (DFA).
Part 2 (5mks): Demonstrate the steps involved in converng the DFA created in Part 1 into an equivalent
Regular Expression.
DFA
GNFA
∪ab)b* ∪ ((b∪
RE: (b∪ ∪ab)b*a)(b+a)*(ε∪
∪b*)
3|Page
Context Free Grammar (14mks): February 26th – March 11th
a. (4mks) Give context-free grammar that generates the language:
S → aSc | X
X→ bXc | ε
b. (5mks) Given the regular expression (1∪01)+(00)*1(11)*, provide the equivalent context-free
grammar.
→ 1
→
→ 00 |
→ 11 |
→ 1 | 1
→ 01 | 01
c. (5mks) Given the NFA below, provide the equivalent context-free grammar.
Syntax Analysis (6mks): February 26th – March 11th
CFG G is defined as ({S}, {0, 1, (, ), ∪, ∗, ∅, e}, R, S) where the rules R are outlined as
S → S∪S | SS | S* | (S) | 0 | 1 | ∅| e
Give a derivaon or parse tree for the string (0 ∪ (10)*1)*
S → S*
→ (S)*
→ (S∪S)*
→ (0∪S)*
→ (0∪SS)*
→ (0∪S*S)*
→ (0∪(S)*S)*
→ (0∪(SS)*S)*
→ (0∪(10)*1)*
4|Page
Chomsky Normal Form (6mks): February 26th – March 11th
Convert the following CFG into an equivalent CFG in Chomsky's normal form, using the procedure given
in the Lecture.
S → Aa | b
A → Ac | AS| Sdb | ε
New start
S0 → S
S → Aa | b
A → Ac | AS | Sdb | ε
Remove ε rules.
S0 → S
S → Aa | b | a
A → Ac | AS | Sdb | c | S
Remove unit rules.
S0 → Aa | b | a
S → Aa | b | a
A → Ac | AS | Sdb | c | Aa | b | a
Convert to proper form.
Fix Aa Ac -1mk
S0 → AB | b | a
S → AB | b | a
A → AC | AS | Sdb | c | AB | b | a
B→a
C→c
Fix Sdb -2mks
S0 → AB | b | a
S → AB | b | a
A → AC | AS | SF | c | AB | b | a
B→a
C→c
D→d
E→b
F → DE
Pumping Lemma (7mks): March 11th – March 25th
The Pumping Lemma is an instrument employed in formal language theory to establish that specific
languages lack regularity or context-freeness. The primary disncon of both versions lies in the intricacy
of the decomposions permiJed by each lemma.
1. Show that the language = ! | > !, ! ≥ % is not regular, given a pumping length of 2
and the specific string ∈ . (3mks)
Assume A is regular, then split the string into three parts: x=a y=b z=ababaa. Any value
other than i=1 will not belong to A when y is pumped thus not regular
2. Show that the language ' = ()*)+ | |)| = |*|, )&* ∈ (, -∗ - is not context-free, given a
pumping length of 4 and the specific string ∈ '. (4mks)
Assume B is context-free, then split the string into five parts. Students can present different splits.
Let u=ε v=ab x=a y=b z=abaababa. Any value other than i=1 will not belong to B when
v and y are pumped thus not context-free
5|Page
Pushdown Automata (3mks): March 11th – March 25th
Draw a pushdown automaton that recognizes the following language . = ( | /* 010 -.
Equivalence 2 (8mks): March 11th – March 25th
Do A or B
Eq. A
Given the context-free grammar below provide an equivalent pushdown automaton.
6|Page
Eq. B
Transform the pushdown automaton below to an equivalent context-free grammar.
Turing Machine Configura*on (16mks): March 19th – April 2nd
Consider the following Turing Machine M with input alphabet Σ={a,b}. The Turing machine recognizes
the following language L ={w∈∈{a,b}* |w has equal number of as and bs}
1. The reject state qrej is not shown, include it within the provided state diagram. (1mk)
2. The formal definition of M as a tuple is M = (Q,Σ,Γ,δ,q0,qacc,qrej) specify what is Q,Σ,Γ,δ as it
relates to the provided state diagram. (7mks)
Q={q0, q1, q2, q3, q4, qacc, qreq}
Σ={a, b}
Γ={a, b, X, Y, ⊔}
δ(q0,a)=(q2,X,R) δ(q0,b)=(q3,X,R) δ(q0,⊔)=(qacc,⊔,R)
δ(q1,a)=(q2,X,R) δ(q1,b)=(q3,X,R) δ(q0,⊔)=(qacc,⊔,R) δ(q1,Y)=(q1,Y,R)
δ(q2,a)=(q2,a,R) δ(q2,b)=(q4,Y,L) δ(q2,Y)=(q2,Y,R)
δ(q3,a)=(q4,a,L) δ(q3,b)=(q3,b,R) δ(q3,Y)=(q3,Y,R)
δ(q4,a)=(q4,a,L) δ(q4,b)=(q4,b,L) δ(q4,Y)=(q4,Y,L) δ(q4,X)=(q1,X,R)
7|Page
3. Describe each step of the computation of M on the inputs baabab and aabaab as a sequence of
instantaneous descriptions. (4mks each)
q0baabab⊔ q0aabaab⊔
Xq3aabab⊔ Xq2abaab⊔
q4XYabab⊔ Xaq2baab⊔
Xq1Yabab⊔ Xq4aYaab⊔
XYq1abab⊔ q4XaYaab⊔
XYXq2bab⊔ Xq1aYaab⊔
XYq4XYab⊔ XXq2Yaab⊔
XYXq1Yab⊔ XXYaaq2b⊔
XYXYq1ab⊔ XXYaq4aY⊔
XYXYXq2b⊔ Xq4XYaaY⊔
XYXYq4XY⊔ XXq1YaaY⊔
XYXYXq1Y⊔ XXYq1aaY⊔
XYXYXYq1⊔ XXYXq2aY⊔
XYXYXY⊔qacc XXYXaYq2⊔
XXYXaY⊔qrej
Turing Machine (11mks): March 19th – April 2nd
Design a Turing machine to recognize the language of strings of the form ax by cz such that x≠z and
y>0. Provide both the algorithm (5mks) and its corresponding state diagram (6mks).
M = “On input w
1. Scan string if ε, reject; if not in the form axbycz then reject
2. Return to start
a. If the symbol is an ‘a’ replace it with blank then scan right to find the first c after bs
i. If c is found mark-off and goto stage 2
ii. If no c is found then ACCEPT
b. If the symbol is ‘b’ then scan right to find cs then ACCEPT, else reject”
8|Page
Register Machine (11mks): March 19th – April 9th
Design a Register machine to recognize the language of strings of the form ax by cz such that x≠z and
y>0. You should have a register to store (1) the amount a’s, (2) the amount b’s, (3) the amount c’s, and
(4) the soluon. The register having the soluon should store 0 if language is NOT recognized, otherwise
1 if language is recognized. Provide the graph representaon (7mks), inial configuraon (1mk), and
final configuraon (3mks).
Register Machine Computa*on (10mks): March 28th – April 12th
Exponenaon involves the iterave accumulaon of mulplicaon: starng with 1 as the base case
(3 = ), each subsequent power (345 ) is obtained by mulplying the previous power (34 ) by 3.
Thus, for a posive exponent 4, 34 equals the product of 4 instances of 3. Below is the graphical
representaon of the register machine capable of performing this exponenaon operaon.
65
7
START 8> +> 9> 65
HALT
6>
6>
7 95
+5
Provide the corresponding program along with the computaons based on the inial configuraons
below of registers 6 , 67 , +, 8, 9.
(a) ∃; ∃4 ∃3 +; , .< , , , , , = to compute =
C1 C2 R X Y
0 0 1 0 5
H
9|Page
(b) ∃; ∃4 ∃3 +; , .< , , , , , 7 to compute 7
C1 C2 R X Y
0 0 1 3 2
2
0
2 2 0
0 2
0 2
1
1
2 2 0
0 2
0
4 2 0
0 2
0 4
0
3
2 2 0
0 2
2
4 2 0
0 2
1
6 2 0
0 2
0
8 2 0
0 2
0 8
H
Language (5mks): March 28th – April 12th
What is your understanding of Turing-unrecognizable? Provide an example to support your answer.
Turing-unrecognizable refers to a type of language or problem for which there exists no Turing machine
that can recognize it. In other words, there's no algorithmic procedure that can correctly determine
whether a given input is a member of the set or not.
In simpler terms, it's a problem that cannot be solved by any algorithm or computaJon.
Examples TheoreJcal in nature
These examples demonstrate the existence of problems or languages for which no algorithmic soluon
exists, highlighng the limitaons of computaon.
1. Post Correspondence Problem (PCP): Given a set of tiles, each with two strings written on them,
the PCP asks whether there exists a sequence of tiles that, when stacked together, aligns the
strings on the top and bottom to form the same string. Alan Turing proved that no algorithm can
determine if a solution exists for every possible set of tiles.
2. Busy Beaver Function: The Busy Beaver function, denoted BB(n), represents the maximum
number of steps that an n-state Turing machine can make before halting when started on an
initially blank tape. While it's computable for specific values of n, no algorithm can compute it
for all n. This makes it an example of a Turing-unrecognizable function.
3. Diophantine Equations: Diophantine equations are polynomial equations with integer
coefficients that ask whether there exist integer solutions. While there are algorithms to solve
some specific types of Diophantine equations, there is no general algorithm that can solve all
Diophantine equations. This was proven by Matiyasevich's theorem, which showed that the
10 | P a g e
solution set of any Diophantine equation can be used to encode the halting problem for Turing
machines, hence making Diophantine equations Turing-unrecognizable.
4. Universal Turing Machine Halting Problem: This problem asks, given a description of a Universal
Turing Machine U and a description of another Turing machine M along with an input w,
whether M halts when run on input w. Since this problem is a generalization of the classic
Halting Problem, it is also Turing-unrecognizable.
Real-world scenarios that can be modelled as Turing-unrecognizable problems
it's important to note that these scenarios are oZen abstracted into mathemacal or computaonal
problems to demonstrate their undecidability.
1. Software Verification: In software engineering, ensuring that a computer program behaves
correctly for all possible inputs is akin to solving the Halting Problem. While tools and
techniques exist to verify software properties, complete verification of arbitrary programs is
generally impossible due to undecidability.
2. Compiler Optimization: Optimizing compilers aim to improve the performance of programs by
transforming code while preserving its behaviour. However, determining whether a given
optimization will always improve performance or preserve program semantics in all cases is an
undecidable problem, akin to the Halting Problem.
3. Code Analysis: Static analysis tools analyze source code to identify potential bugs, security
vulnerabilities, or code smells without executing the program. While these tools can catch many
issues, there are cases where they may produce false positives or miss subtle problems due to
the inherent undecidability of certain properties of programs.
4. Network Routing: Routing algorithms in computer networks aim to find the optimal path for
data packets to travel from a source to a destination. The problem of finding the optimal route
can be complex and undecidable in certain network topologies or when considering various
constraints such as traffic congestion or network failures.
5. Security and Vulnerability Analysis: Analyzing software for security vulnerabilities or proving
the absence of certain types of vulnerabilities is akin to solving undecidable problems. While
automated tools can assist in identifying common vulnerabilities, proving the absence of all
possible vulnerabilities is theoretically impossible.
6. Algorithmic Trading: In financial markets, algorithmic trading involves the use of computer
algorithms to make trading decisions. Predicting market behaviour or designing algorithms that
always generate profit is akin to solving undecidable problems, as the complexity and
unpredictability of financial markets make it impossible to guarantee success in all cases.
***END***
11 | P a g e