Examination Formal Languages and Automata Theory TDDD14 (Formella Spr˚

advertisement
Examination
Formal Languages and Automata Theory
TDDD14
(Formella Språk och Automatateori)
2011–10–20, 08.00 – 12.00
1. Allowed help materials
• A sheet of notes - 2 sided A5 or 1 sided A4.
The contents is up to you.
The notes should be signed in the same way as the exam sheets
and returned together with the exam.
• English dictionary (printed, not electronic).
 Tillåtna hjälpmedel:

• Ett papper med valfria anteckningar - 2 sidor A5 eller 1 sida A4.


Anteckningarna ska signeras på samma sätt som tentamens

arken och bifogas tentamen vid inlämnandet.

• Engelsk ordbok (på papper, inte elektronisk)
2. You may answer in Swedish or English.
3. Total number of credits is 31.
3: 15 p, 4: 20 p, 5: 25 p.
4. Jour (person on duty): Wlodek Drabent, tel. (013 28) 89 29.
GOOD LUCK !!
1







Make sure that you justify your answers! Unexplained answers will be
granted 0 points. (For example, assume that you are writing a grammar for
a given language. Then you should also explain that the grammar indeed
generates the language).
1. (2p) Using a standard method
construct a DFA equivalent to the
NFA given by the table. (Its set of
states is Q = {A, B, C, D}, the input alphabet Σ = {0, 1}, the start
state is A, and D is the only final
state.)
ε
0
1
→A
{B} {A, B} {A, C}
∅ {B, D}
∅
B
C
∅
{C}
{D}
∅
{D}
D F {A}
2. (2p) Consider the NFA given by the table. Using a standard method,
construct a regular expression defining the same language. (The set
of states of the NFA is Q = {A, B, C, D}, the input alphabet Σ =
{0, 1, 2, 3, 4, 5, 6, 7}, the start state is A, and D is the only final state.)
0
1
2
3
4
5
6
7
→A
{B} {C} ∅
∅
∅
∅
∅
∅
B
∅
∅ {B} ∅ {D}
∅
∅
∅
∅
∅
∅ {C}
∅
{D} ∅ {B}
C
∅
∅
∅
∅
∅
{A} ∅
DF ∅
3. (1p) Consider regular expressions
∗
α = a (b + bb)a (b + bb)a
and β = (ab)∗ + a (b + bb)a.
Give an example of a string in L(α)\L(β), and of a string in L(β)\L(α).
Remember that \ denotes the set difference.
4. (2p) Using a standard method,
construct the minimal DFA equivalent to the DFA given by the table. (Its set of states is Q =
{A, B, C, D, E, F, G}, the input alphabet Σ = {0, 1}, the start state
is A, and G is the only final state.)
2
0
→A
B
B
C
C
D
D
A
E
F
F
A
GF C
1
A
G
F
G
A
G
G
5. (2p) Let L be the language accepted by the DFA from the previous
problem. Consider the relation ≡L on strings over Σ = {0, 1}, defined
by
x ≡L y ⇔ ∀z ∈ Σ∗ (xz ∈ L ⇔ yz ∈ L).
How many equivalence classes does ≡L have? Why? Choose one of the
equivalence classes, and give a DFA’s defining it.
6. (1p) Choose one of the following languages and give a context-free
grammar for it.
L1 = { am bm cn dn | m, n ≥ 0 } ∪ { am bn cn dm | m, n ≥ 0 }
L2 = { am bm cn dn | m, n ≥ 0 } ∩ { am bn cn dm | m, n ≥ 0 }
Make it clear which language you chose, what are the sets generated
by the nonterminal symbols of your grammars, and what is the role of
each production.
7. (6p) For each of the following languages answer whether it is regular,
context-free but not regular, or not context-free. A brief, informal
explanation is sufficient.
Remember that #a(w) denotes the number of occurrences of symbol a in string w.
(a,b) L1 is the language generated by the context-free grammar
S → ABS | A → a | aa
B→b|c
and L2 is the language generated by the context-free grammar
S → ASB | A→a|b
B→c|d
In the grammars, S, A, B are nonterminal symbols, a, b, c, d are
terminal symbols, and S is the start symbol.
(c)
L3 =
x, z ∈ {a, b}∗ , y ∈ {c, d}∗ ,
xyz .
#a(x) = #a(z), |y| = |z|
(d) L4 is the image of L3 under the homomorphism h : {a, b, c, d}∗ →
{0, 1}∗ such that h(a) = h(b) = 01, h(c) = h(d) = .
(e) L5 = { xyx | x, y ∈ {a, b}∗ , |y| = 3 }.
(f) L6 = { xyx | x, y ∈ {a, b}∗ , |x| = 3 }.
3
8. (3p) Prove that a language
L7 = { aj t | t ∈ {b, c}∗ , j = #b(t) = #c(t) }
is not regular or that it is not context-free. Use the appropriate pumping lemma or employ reasoning similar to the proof of the lemma.
9. (1p) Explain briefly the notion of the language of a decision problem.
Hint: The notion is used below.
10. (3p) Show that a problem “a Turing Machine M halts on every input”
is undecidable. Use the fact that it is undecidable whether a Turing
Machine M halts on input .
In other words, show that the language of the problem,
Turing machine M
HEI = hM i ,
halts on every input
is not recursive, using the fact that the language
Turing machine M
HES = hM i halts on input is not recursive.
Hint: You may find it useful that out of any TM M one can construct a TM M 0
which on every input behaves like M on input . The TM M 0 first erases its input
and then runs M on empty input.
11. (4p) Which of the following statements are true, which are false?
Justify your answers.
(a) The language HES from problem 10 is recursively enumerable.
(b) There exists a context-free language which is not recursive.
(c) If L is a regular language then LL is regular.
(d) If L is a regular language then Ld = { xx | x ∈ L } is context-free.
12. (3p) In an attempt to construct LR parsers for certain grammars,
we applied the standard method of constructing a DFA for the viable
prefixes of a grammar. Some fragments of the obtained DFA’s are given
below.
Complete the missing items in the given states, the missing lookahead
sets and the missing symbols labelling the arrows. In each case answer
the following questions. Justify your answers.
4
• Does the fragment of a DFA satisfy the conditions for the grammar
to be LR(0)?
• The same question about the conditions for LR(1).
You may skip adding missing items or lookahead sets if they are not needed to
answer the questions. For instance if you find the items in some state to violate the
LR(1) conditions then you do not need to complete the other states.
a, b, c are terminal symbols and S, A are nonterminal symbols of the grammars; S
is the start symbol.
(a)
↓
S → • Ab { $ }
S → • Ac { $ }
A
a
−→
←−
The productions of the grammar are S → Ab | Ac, A → aAb | b.
(b)
S → • Ab { $ }
S → •A {$}
A→•
{
}
A
−→
−→
The productions of the grammar are S → A | Ab, A → | aAb | b.
13. Explain whether the grammar from problem 12a is LL(1).
5
Download