Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

2G1505 Automata Theory

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

2G1505 Automata Theory

Solutions to Exam of: Dilian Gurov


17 December 2003 KTH/IMIT/LECS

1. Convert the nondeterministic automaton given below to an equivalent deterministic one using the
subset construction. Omit inaccessible states. Draw the graph of the resulting DFA.

a b
→ q1 q1 , q 2 q3 F
q2 − q4 F
→ q3 q4 −
q4 − q1 , q 4

Solution: (given as a table)

a b
→ {q1 , q3 } {q1 , q2 , q4 } {q3 } F
{q1 , q2 , q4 } {q1 , q2 } {q1 , q3 , q4 } F
{q1 , q3 , q4 } {q1 , q2 , q4 } {q1 , q3 , q4 } F
{q1 , q2 } {q1 , q2 } {q3 , q4 } F
{q3 , q4 } {q4 } {q1 , q4 }
{q1 , q4 } {q1 , q2 } {q1 , q3 , q4 } F
{q4 } {} {q1 , q4 }
{q3 } {q4 } {}
{} {} {}

2. For the deterministic automaton given below, apply the minimization algorithm of Lecture 14 to
compute the equvalence classes of the collapsing relation ≈ defined in Lecture 13. Show clearly the
computation steps. List the equivalence classes, and apply the quotient construction to derive a
minimized automaton. Draw its graph.

a b
→ q0 q0 q1
q1 q2 q3
q2 q2 q3
q3 q2 q4 F
q4 q0 q1

Solution: (incomplete) After applying the minimization algorithm we obtain that q0 ≈ q4 and q1 ≈ q2 .
Thus we obtain the following minimized automaton (given as a table).

a b
→ {q0 , q4 } {q0 , q4 } {q1 , q2 }
{q1 , q2 } {q1 , q2 } {q3 }
{q3 } {q1 , q2 } {q0 , q4 } F
3. Let A ⊆ Σ∗ be a language. We define its prefix closure as:

pref A = {x ∈ Σ∗ | ∃y ∈ Σ∗ . x · y ∈ A}

Prove that regular languages are closed under prefixing: if language A is regular, then so is pref A.
Solution: Let A ⊆ Σ∗ be regular. Then there must be a DFA MA = (Q, Σ, δ, s, F ) such that
L(MA ) = A. Now, based on MA , define another automaton M = (Q, Σ, δ, s, F 0 ) so that:
n o
F 0 = q ∈ Q | ∃y ∈ Σ∗ . δ̂(q, y) ∈ F

We will show that this automaton accepts the language pref A, and hence that pref A is regular.
Claim. L(M ) = pref A
Proof.

x ∈ L(M ) ⇔ δ̂(s, x) ∈ F 0 {def. L(M )}


⇔ ∃y ∈ Σ∗ . δ̂(δ̂(s, x), y) ∈ F {def. F 0 }
⇔ ∃y ∈ Σ∗ . δ̂(s, x · y) ∈ F {HW 1.3, page 301}
⇔ ∃y ∈ Σ∗ . x · y ∈ A {L(MA ) = A}
⇔ x ∈ pref A {def. pref A}

4. Consider the language:


A = {x ∈ {a, b}∗ | ]a(x) < ]b(x)}

(a) Give a context–free grammar G for A. Explain your choice of productions.


Solution: There are many possible solutions. One way of looking at the strings of the language
is to devide these into the ones which have exactly one occurrence of b more than occurrences of
a, and those that have more. A string is in the first group exactly when it can be represented
as a string of the shape e1 · b · e2 , where e1 and e2 are strings with an equal number of a’s and
b’s. Thus, e1 and e2 can be produced by the grammar E →  | aEb | bEa | EE. A string is in
the second group exactly when it is the concatenation of two strings of A. So we arrive at the
following grammar:
S → EbE | SS
E →  | aEb | bEa | EE
(b) Construct an NPDA accepting A on empty stack. Explain its workings.
Solution: Again, there is a number of good solutions. One elegant solution using ε-transitions
(proposed by one of the students at the exam) is based on the observation that if we use the
”standard” productions for comparing occurrences:
a b
hq, ⊥i ,→ hq, A⊥i hq, ⊥i ,→ hq, B⊥i
a b
hq, Ai ,→ hq, AAi hq, Bi ,→ hq, BBi
a b
hq, Bi ,→ hq, εi hq, Ai ,→ hq, εi

then a string is in A exactly when after reading it the stack contains only B’s (on top of ⊥). Note
that there must be at least one such B. So, we can obtain the desired behaviour by adding two
more productions:
b
hq, ⊥i ,→ hq, Bi
ε
hq, Bi ,→ hq, εi
5. Apply the Pumping Lemma for context–free languages (as a game with the Demon) to show that the
language: n o
A = an bn aj | j ≤ n
is not context–free.
Solution:

– Demon picks an arbitrary k ≥ 0.


+ We pick z = ak bk ak which is in A.
– Demon picks u, v, w, x, y such that z = uvwxy, |vx| > 0, |vwx| ≤ k.
+ If vwx = al bm for some l, m ≥ 0, we pick i = 0. Otherwise we pick i = 2.

Since |vwx| ≤ k, vwx has either the shape al bm or bm al for some l, m such that l + m ≤ k. In the first
case xv 0 wx0 y must be of the shape ap bq ak for some p, q such that p + q < 2k, and thus is not in A.
In the second case, xv 2 wx2 y will either not be in L(a∗ b∗ a∗ ) at all, and thus not in A, or else xv 2 wx2 y
must be of the shape ak bp aq for some p, q such that p + q > 2k, and thus not in A. Hence, we win the
game in all cases, which shows that A is not context–free.

6. Give a detailed description (preferably as a graph) of a total Turing machine accepting the language:
 
n(n+1)
n
A= a b 2 |n≥0

Explain the underlying algorithm.


Solution (just a very brief sketch for now) We use the well–known equation ni=1 = n(n+1)
P
2 . We
proceed in rounds, in each round marking an a and then marking as many b’s as there are marked a’s
(which equals the number of the current round).

You might also like