Regular Languages (14 points) Solution: b)The minimal automaton

advertisement
CD5560 Formal Languages, Automata and Theory of Computation, Mälardalen University – School of Innovation, Design and Engineering, Final exam 18 Mar 2010 Regular Languages (14 points) Problem 1 (5 points) For the following automaton M 0
start
1
B
C
0
0
A
0
1
1
1
0
D
E
1
a) Give transition function b) Minimize automaton Solution:
a) Transition function for M. δ
0 1 A B D B B C C D E D D E E B C b)The minimal automaton 0
1
1
0, 1
A
BD
0
CE
CD5560 Formal Languages, Automata and Theory of Computation, Mälardalen University – School of Innovation, Design and Engineering, Final exam 18 Mar 2010 Problem 2 (5 points) Convert an NFA to DFA using the subset construction Answer The step‐by‐step solution is given in a separate file. Problem 3 (4 points) Prove by using Pumping lemma that the language n
n
L = {a b a | n ≥ 0}
is not regular. Answer m
m We choose the string w = a ba (other choices may be also correct).
Decompose the string w = xyz such that |xy|≤ m and y ≠λ, and choose i to create a string wi = xyiz such that wi is not in L. m−k
m By choosing i = 0, we get w0 = a ba which does not belong to L because the number of a’s before the b is now smaller than the number of a’s after the b. CD5560 Formal Languages, Automata and Theory of Computation, Mälardalen University – School of Innovation, Design and Engineering, Final exam 18 Mar 2010 Context Free Languages (14 points) Problem 4 (4 points) Construct context free grammars to accept the following languages.
a. L = {w | | w | is odd}
b. L = {w | | w | is odd and its middle symbol is 0}
Answer a. S → Σ A| Σ
A→Σ S |λ
b. S
→ 0 | 0 S 0 | 0 S1 | 1S 0 | 1S1 Problem 5 (5 points) Describe the following PDA. Test run. What language accepts by automaton? c, S / S
a, S / AS
a, A / AA
b, S / S
b, A / A
S
c, S / S
a, S / S
c, A / A
a, A / A
λ, S / S
b, A / λ
c, A / A
a, A / A
b, A / λ
a, S / S
Answer L = {xyz | x, z ∈ {a, b}* , y ∈ {c}+ where number of a in x is equal to number of b in z}
Problem 6 (5 points) Using the pumping lemma to prove that the language below is not context‐free. L = {a i b 2i a i i ≥ 0 }
CD5560 Formal Languages, Automata and Theory of Computation, Mälardalen University – School of Innovation, Design and Engineering, Final exam 18 Mar 2010 Answer Assume that the language is context‐free. By the pumping lemma, the string w = akb2kak, where k is the
number specified by the pumping lemma, can be decomposed into sub-string uvwxy that satisfy
the condition length (vwx) ≤ k, length (v) + length (x) > 0, and uviwxiy ∈ L, (i ≥ 0)
Since the length (vwx) ≤ k, the vwx can have the following possibilities:
Case 1: It contains a-s and b-s (aibj or biaj,. o<i+j≤k) Since length (vwx) ≤ k, it cannot have a’s at
both side of b’s,). Then uv2wx2y contains a…b…a…b…a. It will not be in L any more.
Case 2: It is contained in one of ak or b2k or second ak. Since the repetition in uv2wx2y will
increase one of the string’s lengths of ak or b2k or second ak, the ratio of 1:2:1 will not be satisfied.
Then uv2wx2y–L.
There is no decomposition L that satisfies the condition of pumping lemma. Therefore, L is not
context free.
Recursively Enumerable Languages(12 points) Problem 7 (6 points) How does the following TM work? Does it accept the input string? Write
pseudo code. Test run. Input:
aabbcc###…..
x,R
#,R
q0
y,R
z,R
#,R
b,R
c,R
q1
q2
q3
c/z,L
a/x,R
b/y,R
y,R
a,R
b,R
a,L
y,R
z,R
b,L
q4
#,R
c,L
#,R
q6
x,L
c,R
b,R
y,L
z,R
c,R
z,L
q5
Q = {q0,...,q6}
Γ = {a,b,c,x,y,z,#}
B=#
Σ = {a,b,c}
start state = q0
F = {q6}
#,R
a,R
Answer The TM replaces all b’s with # and move them at the end of the string. String is accepted. TM starts from the first symbol in the input aabbcc. The string gets accepted and tape contains xxyyzz##. It matches expression anbncn with n≥1. Problem 8 (6 points) Prove each of the following languages decidable or undecidable!
a) {<M > | L(M) has exactly n elements}
CD5560 Formal Languages, Automata and Theory of Computation, Mälardalen University – School of Innovation, Design and Engineering, Final exam 18 Mar 2010 Answer Undecidable. This is a non‐trivial property of languages, so Rice's Theorem applies. b) {(< M 1 >, (< M 2 >) | L( M 1 ) ∩ L ( M 2 ) = ∅ } ?
Answer Undecidable. We give a reduction from ETM. Suppose that this language is decidable. Let T be a Turing machine that decides it. Then we can construct a Turing machine T´ deciding ETM, that behaves as follows on input <M>. (a) Simulate T on input <M, M´>, where M´ is a Turing machine recognizing the empty language. (b) Accept if and only if T accepts. Suppose that M accepts the empty language. Then T accepts <M, M´>, and so T´ accepts. On the other hand, suppose that M accepts some string. Then T rejects <M, M´>, and so T´ rejects. Thus, T´ decides ETM. References Linz Peter, An Introduction to Formal Languages and Automata, Jones & Bartlett, 2006 Rich Elaine, Automata, Computability and Complexity: Theory and Applications, Prentice Hall, 2007 Sudkamp, Languages and Machines, Addison Wesley 1998 Sipser Michael, Introduction to the Theory of Computation, PWS 1997 Hopcroft, Motwani, Ullman, Introduction to Automata Theory, Languages, and Computation, Addison Wesley 2001 
Download