Jan 18, 2013 ... DVA325 Formal Languages, Automata and Theory of Computation, ..... Linz Peter
, An Introduction to Formal Languages and Automata, Jones ...
DVA325 Formal Languages, Automata and Theory of Computation, Mälardalen University –School of Innovation, Design and Engineering,
Final exam 18 Jan 2013
REGULAR LANGUAGES (14 POINTS) Problem 1 (6 points) For the following NFA (Sudkamp)
a q0
b
a
q1
a
λ
q2 c
a) Write the transition function and extended transition function (with λ‐transitions) b) Convert the NFA to DFA
Solution 1 a) The transition function for M
δ
a
b
c
λ
q0
{q0 , q1 , q2 }
∅
∅
∅
q1
∅
{q1 }
∅
∅
q2
∅
∅
{q 2 }
{q1 }
The extended transition function with λ‐transitions t
a
b
c
q0
{q0 , q1 , q2 }
∅
∅
q1
∅
{q1}
∅
q2
∅
{q1}
{q1 , q2 }
1
DVA325 Formal Languages, Automata and Theory of Computation, Mälardalen University –School of Innovation, Design and Engineering,
Final exam 18 Jan 2013
b) Conversion of the NFA to DFA We find the corresponding DFA by subset construction algorithm: a
⎯→ {q0, q1, q2} {q0} ⎯ b
⎯→ {∅} {q0} ⎯ {q0}
⎯⎯ → {∅}
A
B
c
a
{q0 }
a
{q0 , q1 , q2 }
c
a
⎯→ {q0, q1, q2} {q0, q1, q2} ⎯ b
⎯→ { q1} {q0, q1, q2} ⎯
{q1 , q2 }
b
b, c
⎯⎯ → {q1, q2} c
{q0, q1, q2} a
⎯→ {∅} { q1} ⎯ b
⎯→ { q1} { q1} ⎯
C
b
a, c
∅
c
{q1}
D
E
b
→ {∅} { q1} ⎯⎯ c
a
⎯→ {∅} {q1, q2} ⎯
a
b
⎯→ { q1} {q1, q2} ⎯
→ {q1, q2} {q1, q2} ⎯⎯ c
2
DVA325 Formal Languages, Automata and Theory of Computation, Mälardalen University –School of Innovation, Design and Engineering,
Final exam 18 Jan 2013
Problem 2 (4 points) Minimize the following automaton (Sudkamp)
a
A
B
b
b b
D
b
C
a
a
b E
a
Solution 2 From the transition table below C, D, E are indistinguishable: A B C D E
a B ∅ E E E
b D C D D D
a B ∅ CDE ∅
b CDE CDE CDE ∅
The minimal DFA is: A B CDE ∅
a
A
b
B
a
b
CDE
∅
a,b
3
DVA325 Formal Languages, Automata and Theory of Computation, Mälardalen University –School of Innovation, Design and Engineering,
Final exam 18 Jan 2013
Problem 3 (4 points) Prove by using Pumping lemma that the following language is not regular (Linz): L = {a n b l | n is an integral multiple of l}
Solution 3 We use the Pumping lemma as follows. Assume (by contradiction) that L is regular. From Pumping lemma, ∃ m such that ∀ w ∈ L, |w| ≥ m, ∃ x, y, z ∋ |xy| ≤ m, |y| = k > 0, w = xyz and xyiz ∈ L ∀ i ≥ 0. Let w = xyz = ambm ∈ L (m = 1∗m) m Since |xy| ≤ m, xy ⊂ a ∴ y = ak Consider xy2z ∈ L a(m+k)bm ∈ L ∴ ∃ n ∋ (m+k) = n∗m (by definition of L) but
km | m>n
n>m
m>n
S → AS1
S → S1B
S → AS1|S1B
S1 → aS1b|λ
S1 → aS1b|λ B → bB|b
S1 → aS1b|λ
A → aA|a
A → aA|a B → bB|b.
4
DVA325 Formal Languages, Automata and Theory of Computation, Mälardalen University –School of Innovation, Design and Engineering,
Final exam 18 Jan 2013
Problem 5 (6 points) The PDA is given by the following graph: (Sipser) b, a → λ
q0
λ, λ → $
c, λ → λ
λ ,$ → λ
q2
q3
λ, λ → λ q1
λ, λ → λ
q4
λ, λ → λ
b, λ → λ
a, λ → a
q5
λ ,$ → λ
q6
c, a → λ
a) What language is accepted by the automaton? b) Test run on the strings aabbc and aabcc.
Solution 5 i
j
k
a) The language is: L ={a b c | i, j, k ≥ 0 and i = j or i = k} b) Test run on the strings aabbc and aabcc.
State q0 q1 q1 q1 q2 q2 q2 q3 q3
String aabbc aabbc abbc bbc bbc bc c c
λ
Stack
λ
$ a$ aa$ aa$ a$ $
λ λ
Accepted!
State q0 q1 q1 q1 q4 q5 q5 q5 q6
String aabcc aabcc abcc bcc bcc cc c
λ λ
Stack
λ
$ a$ aa$ aa$ aa$ a$ $
λ
Accepted!
5
DVA325 Formal Languages, Automata and Theory of Computation, Mälardalen University –School of Innovation, Design and Engineering,
Final exam 18 Jan 2013
Problem 6 (4 points) Which of the following languages is context‐free? Justify! If context‐free construct a CFG or a PDA, if not use Pumping lemma. a) L=
{ a m bn c p d r | m + n + p = r; m, n , p, r ≥ 0}
b) L=
{ a k b k | k ≥ 0 } with the alphabet Σ = {a, b}.
with the alphabet Σ = {a, b, c, d}.
2
Solution 6 a) Context‐free. Grammar:
S → aSd | A A → bAd | B B → cBd | λ b) Not context‐free. Pumping lemma, see Lecture 10, p.123.
6
DVA325 Formal Languages, Automata and Theory of Computation, Mälardalen University –School of Innovation, Design and Engineering,
Final exam 18 Jan 2013
RECURSIVELY ENUMERABLE LANGUAGES (12 POINTS)
Problem 7 (4 points) Is the function g(x) primitive recursive? If yes, define it as a primitive recursive function (you can use basic primitive recursive functions from the course). (Salling)
x
0 1 2 3 4 5 6 7 8 9 10 11 12
g(x) 1 1 3 2 5 3 7 4 9 5 11 6
1
13 7
Solution 7 Function g(x) is primitive recursive. From the function table we see that for even x it returns x+1 and for odd x it gives (x+1)/2. Thus, we can define g as follows: g(0) = 1 g(x) = if (even(x), f(x), h(x)) f(x) = succ (x) h(x)= quotient (succ(x),2)
Problem 8 (4 points) How does the following TM work? Trace the execution of this machine on three input strings (Krasnogor). #→# , R
0 → 0, R 1 → 1, R
q0
0 →# , R
q1
0 → 0, L 1 → 1, L #→# , L
q2
0 →# , L
q3
#→ # , R
0 → 0, R
1 →# , R
p
1 → 1, R
q5
#→# , R #→# , L
1 →# , L
q4
Solution 8: This is a Turing Machine that recognizes palindromes over the alphabet {0,1}. For example fM(1) = yes, fM(10101)= yes, fM(1101011)= yes, but fM(1101)= no The actions carried out by the machine are: 1.
Search the first symbol
2.
Remember the first symbol and go to the end of string
3.
Delete the last symbol if it is the same as the one remembered
4.
If there is only one symbol, the string is accepted.
7
DVA325 Formal Languages, Automata and Theory of Computation, Mälardalen University –School of Innovation, Design and Engineering,
Final exam 18 Jan 2013 Test run Processing string ”0” #q00# → ##q1# → #q2## → ##p# → halts and accepts Processing string ”10” #q010# → ##q50# → ##0q5# → ##q40#→ halts and fails Processing string ”10101” #q010101# → ##q50101# → ##0q5101 → ##01q501# → ##010q51# → ##0101q5# → ##010q41# → ##01q30## → ##0q310## → ##q3010## → #q3#010## → ##q0010## → ###q110## → ###1q10## → ###10q1## → ###1q20## → ###q31### → ##q3#1### → ###q01### → ####q5### → ###q4#### → ####p### → halts and accepts
Problem 9 (4 points) Is the language L decidable? Justify your answer! (Hopcroft) a) L = { | L(M) is infinite and M is an arbitrary DFA }. b) L = { | L(M) is infinite and M is an arbitrary TM }
Solution 9: a)
DECIDABLE. It is enough to check if M contains any loops, which can be done in a finitely meny steps.
b)
UNDECIDABLE. Follows from Rice’s theorem: Any nontrivial property of the language recognized by a Turing machine is undecidable. The property of being infinite Turing recognizable language is nontrivial as not all Turing recognizable languages have that property.
References Sudkamp, Languages and Machines, Addison Wesley 1998 Sipser Michael, Introduction to the Theory of Computation, PWS 1997 Linz Peter, An Introduction to Formal Languages and Automata, Jones & Bartlett, 2006 Salling: Formella språk, automater och beräkningar 2001 Hopcroft, Motwani, Ullman, Introduction to Automata Theory, Languages, and Computation, Addison Wesley 2001
8