You are on page 1of 12

Név: Neptun-kód:

Assignment
(Solved for practicing)
Grade: Points: /100
Theory: 50 Points
Definitions (Give every definition formally!):
1. Define ~M! 3 Points

– let M = (K, Σ, δ, s, F) be a DFA, x, y  Σ*


– if  q  K such that (s, x) |-M* (q, e), (s, y) |-M* (q, e) → x ~M y
– both strings drive M from s to the same state

2. Define the parse tree! 6 Points

a
– this is the parse tree for each a  Σ
• its root: 'a'
• its leaf: 'a'
• its yield: 'a'
A

– this is a parse tree if A → e is a rule in R


• its root: A
• its leaf: e
• its yield: e
A1 An
...
T1 Tn

y1 yn
A

A1 A2 ... An

T1 T2 Tn
y1 y2 yn

– if the above graphs are parse trees, where n ≥ 1, with roots labeled A1,
A2, … An respectively, and with yields y1…yn, and A → A1 A2 …An is a
rule in R then

– this is a parse tree


• its root: A
• its leaves: the leaves of its constituent parse trees
• its yield: y1y2…yn
– nothing else is a parse tree

3. Define the 1-step leftmost derivation! 3 Points

if x = wAβ, y = wαβ, w  Σ*, α, β  V*, A  V - Σ,


A → α  R then x =>L y

4. Define the compatible transitions! 3 Points

compatible transitions ((p, a, ), (q, )) and ((p, a', '), (q', ')):
'a' is consistent with a' and  is consistent with '

5. Define the Chomsky normal form! 3 Points


the rules of a CFG has the next form R  (V - Σ)  V2

6. Define the configuration of a random access TM! 6 Points

C = (κ, R0, R1,…, Rk-1, T):


– C  {0, 1, ... p} × Nk × T
– if κ = 0 → halted configuration
– T  {N-{0}} × {N-{0}}, there are no pairs (i, m), (j, n) such that i = j
• (i, m)  T ↔ T[i] = m
if T[i] is not defined → T[i] = 0
Questions:
7. Prove this theorem: 9 Points
The class of deterministic context-free languages is properly contained in the
class of context-free languages.

suppose L = {anbmcp : m, n, p ≥ 0, n ≠ m or m ≠ p} is deterministic context-free


LC = {anbmcp : m, n, p ≥ 0, n = m = p}  {w  a*b*c*} is deterministic context-
free according to the previous theorem
LC  {w  a*b*c*} is context-free according to a former theorem (context-
free  regular = context free)
but LC  {w  a*b*c*} = {w  anbncn} is not context-free

8. True or false? Why? 10 Points


a. A state of a DFA is unreachable if there is no edge leading to it.
FALSE (Starting state is always reachable)
b. The result of two derivations are the same if the rules applied are the
same.
FALSE (Rules can be applied on different non-terminals)
c. Every CFG has a Chomsky normal form, which generates the same
language.
FALSE (The Chomsky form cannot generate e and 1 length words)
d. There always exists a leftmost derivation for a string.
FALSE (It exists if the string can be derivated)
e. Every PDA can be transformed to a non-deterministic PDA.
TRUE (Every deterministic automaton can be extended to be non-
deterministic and generate the same language.)
9. Give an example for a PDA, where non-determinism cannot be resolved with
looking ahead 1 symbol! 4 Points
An example:
Practice: 50 Points
10. Perform a state minimization of the following DFA: 10 Points
b

c b
c
b c
a a a a a
c

b c

b
b c
b a a a c

c b

a,b,c

The minimal DFA (construction omitted here):


11. Let grammar G = (V, Σ, R, E), where: 8 Points
 V = {+, *, (, ), id, T, F, E}
 Σ = {+, *, (, ), id }
 R = {E →E + T, E →T, T →T * F, T →F, F→(E), F →id, F →id(E) }
Tasks:
 Give a derivation of:
o E+(F+(id)*F)

E => E+T => E+F => E+(E) => E+(E+T) => E+(T+T) => E+(F+T) =>
=> E+(F+T*F) => E+(F+F*F) => E+(F+(E)*F) => E+(F+(T)*F) =>
=> E+(F+(F)*F) => E+(F+(id)*F)

o (id*(id))

E => T => F => (E) => (T) => (T*F) => (F*F) => (id*F) => (id*(E)) =>
=> (id*(T)) => (id*(F)) => (id*(id))

 Give a parse tree for both!


o The first one is not a string just a partially defined string,
hence it doesn’t have a parse tree.
o
E

( E )

T * F

F ( E )

id T

id

 Give the leftmost derivation of the first, and the rightmost derivation of the
second parse tree!
o The first one doesn’t have a parse tree, hence it also does not
have a leftmost derivation by definition.
o The leftmost derivation is already constructed in the first task.
12. Let grammar G = (V, Σ, R, S), where 8 Points
 V = {a, b, c, d, A, B, C, D, S}
 Σ = {a, b, c, d}
 R = {S → ABCD, A → ab, B → e, C → e, D → cd}
Give the Chomsky normal form of grammar G!

• V = {a, b, c, d, A, D, S}
• Σ = {a, b, c, d}
• R = {S → AD, A → ab, D → cd}

13. Let grammar G = (V, Σ, R, S), where 8 Points


 V = {S, (, )}
 Σ = {(, )}
 R = {S → e | SS | (S)}
Decide algorithmically whether (()))( is an element of L(G) or not! (Algorithmic
proof needed!)
From the Chomsky form: R = {S →SS, S →(S1, S1→S), S → ()}
6 {(}

5 {)} {}

4 {)} {} {}

3 {)} {} {} {}

2 {(} {S} {S1} {} {}


1 {(} {} {} {S} {S1} {}
The last cell is empty, so the grammar does not generate the string.
14. Construct the copying machine with a 2-tape TM! (with machine schema)
6 Points

x1 ≠ x2 ≠
Π Π
1,2 2 2 1,2
>R x L →R
Π x1
1
Π

(1) (2) (3)

15. Write a program for a random access TM to perform the following computation
while x>5 do 10 Points
x = x-2y+1

R1:=x, R2:=y

1. load 1
2. sub =5
3. jzero 10
4. load 1
5. sub 2
6. sub 2
7. add =1
8. store 1
9. jump 1
10. halt

You might also like