2024 AAATut 1 With Solutions
2024 AAATut 1 With Solutions
Ian Sanders
1 Aim
A brief refresher on Finite Automata, Pushdown Automata and Turing Machines. In this tutorial you will
be expected to trace the execution of given automata and to design automata to accept/recognise various
languages over their given alphabets.
2 Questions
1. Trace the FA given in Figure 1 on words from the alphabet {a, b} and try to determine what it
does.
a
a
S+− X+
a
b b
Y+ Z a,b
Solution
The FA accepts the empty string, a+
(i.e. strings of one of more as), b+ i.e. strings of one of more
+ +
bs) and b a (one of more bs followed by one or more as. It does not accept any word where a b
follows an a.
So we could say that this is an FA accepting all words that do not contain the ab-substring.
End of solution
1
2. Trace the FA given in Figure 2 on words from the alphabet {a, b} and try to determine what it
does.
a b
b
A C+
a a
S−
b
a
B D+
b
b a
Solution
Any word accepted by the top branch starts with an a and ends with a b. Any word accepted by
the bottom branch starts with an b and ends with a a.
The FA accepts words with different first and last letters.
End of solution
3. Design a deterministic finite automaton (DFA) that will recognise all of the words in the language
L over the alphabet {a, b}. Here L is the language that contains at least two ab substrings and
ends on a b. Note that if the word ends in the substring ab, then at least two other occurrences of
substring ab must precede this substring.
For example, aaaaabaaaabbbbbb and ababab are words in L but aaaaabaaaaab and abab are not.
Solution
b a b a a b
b
a b a b
S− A B C D E+
a
End of solution
2
4. Trace the execution of the PDA in Figure 4 to show that it accepts/recognises words in L =
{(ab)n (ba)n−2 | n > 2}.
Note that we do not draw in arcs that would go to a reject state as they would make the diagram
too cluttered. For a determinsitic PDA we assume that these arcs do, however, exist. For example,
if the PDA was in state Read 3 and read a b then there should be an arc to a reject state as this
would imply a word that is not in the language.
Start
b a X
Read 1 Read 3 Pop 1 Pop 2
X
Push X a
X
Read 2 Read 4 Pop 3
∆ b a
∆
Accept Pop 4 Read 5
Solution
The PDA works by pushing an X onto the stack for each ab read (Read 1 and Read 2). When Read
2 reads a b then an a must be read next. If this is a case then an X is popped from the stack. Once
all of the ba have been read then two Xs must still be popped before popping a ∆ to ensure that
the stack is empty.
The smallest word here is when n = 3 i.e. (ab)3 (ba). Trace the PDA with this word and longer
words.
End of solution
3
5. Design a deterministic pushdown automata (DPDA) that accepts the language
L = {(a)n (b)n+1 (bb) | n ≥ 0} over the alphabet Σ = {a, b}.
Solution
Smallest word is bbb or (b)1 (bb)
For the shortest word a b is read and the stack is found to be empty. Then two more bs are read
before checking the stack and the input are empty. Shortest word is accepted.
For a general word, the first loop pushes an X for every a read. When a b is read then an X is
popped. When a b is read and the stack is empty then the DPDA has just read the extra b. Then (as
for the shortest word case) two more bs are read before checking the stack and the input are empty.
b ∆ b
Start Read Pop Read Read
X b
a b
Read
Accept
End of solution
4
6. Trace the execution of the TM in Figure 6 to show that it
• loops on all words that begin with 0,
• changes all other instances of 0 on the input tape into 1.
In this case the input alphabet must obviously be Σ = {0, 1}.
(0, 1, R),(1, 1, R)
(1, 1, R) (∆, ∆, L)
start q1 halt
(0, 0, R)
qs
Figure 4: Changing 0s to 1s
Solution
Any word starting with a 0 is not accepted – the TM will loop forever.
If a word starts with 1, a 1 is written and the head moves right and the TM moves to state q1.
In state q1 every time a 1 is read, a 1 is written and the head moves right. In state q1 every time a
0 is read, a 1 is written and the head moves right.
In both cases the TM stays in state q1.
If in state q1 a ∆ is read then a ∆ is written and the head moves left. The state changes to Halt.
This TM changes any 0 in a binary number, that begins with a 1, to a 1. For example 1011 becomes
1111.
End of solution
5
7. The TM in Figure 5 determines whether a given word contains at least one instance of the substring
bab. If it does then the TM writes a T on the tape after the input word.
Trace the TM on different inputs to show it performs as expected.
(a,a,R)
(b,b,R) (b,b,R)
(a,a,R) (b,b,R)
(a,a,R)
(a,a,R)
Solution
Try a word like aababaaab
The first a takes the TM to state 4. Note each letter is read off the tape and the same letter is written
back.
The second a take it to state 4.
The b in position 3 takes it to state 1
The a takes it to state 2.
The b take it to state 3.
In state 3 bab has already been found.
The remaining letters are just read off and written back until a ∆ is found. In this case a T is
written to the tape immediately after the input word and the TM halts.
Try to trace the TM with other inputs.
End of solution
6
8. Design a Turing Machine (TM) that
(a, a, R),
(b, b, R),
(Y, Y, R) (Y, Y, L)
(b, X, R) (∆, ∆, L)
Start 1 2
(b, B, L)
(a, a, R) (b, X, R) (a, Y, L)
(X, X, R)
7 4 3 6 Halt
(X, X, R)
End of solution