Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
09
Introduction Assignment
1. For = {a, b}
a) Write 10 strings of the following languages
i)
All strings with no more than one a
b, bb, bbb, ab, abb, bab, bbba, babbb, bbabb, bbabbb
ii)
aaa, ababab, abaa, ababababa, bababab, aaab, baaa, babababbbb, aaabbb, bbbaaa
b)
BaB | B
bB |
All strings with at least three as
BaBaBaB
bB | aB |
2. Give a simple description of the language generated by the grammar with production
S aA
A bS
S
L = {(ab)n : n>= 0 }
3. Find the grammar that generates the language
L = {wwR : w {a, b}+}.
S
aBa | bBb
B
bBb | aBa |
Page 2
Drive three different sentences in L(G). From these, make a conjecture about L(G).
S
S
S
aa,
aaaa,
aaaaaaaa.
Page 3
a,b
b
q0
q1
q2
b
a
b
q1
a, b
q2
q3
a,b
a
q0
q1
q2
q3
b
All strings of as and bs except that contains substring bba
3. Find a dfa that accept the language defined by the following nfa
q0
q1
q2
q3
1
1
q4
q5
1
1
q0
q1
q2
q3
q4
q5
1
4. Can you construct a dfa or nfa that accepts the following language
L = {wwR : w {a, b}+}.
No: Explain why? Because it is not a regular language, it a context-free language.
Page 4
5. For = {a, b}, Convert the following nfa into an equivalent dfa.
b
q0
b
a
q1
{q1}
a,b
q2
a,b
{q0}
{q2}
{q1, q2}
Page 5
a,b
a
q0
q1
q2
q3
b
a*(ba)*bbb*
b.
q0
q1
q2
q3
1
1
q4
q5
1
111 + (11)*
3. Construct a dfa that accept the language generated by the grammar
S abA
A baB
B aA | bb
a
q0
ab
q1
ba
q2
bb
q3
a,b
q4
a,b
Page 6
(Theorem 4.1)
6. Consider the following languages. For each, state whether or not it is regular. Then prove
your statement.
a. L = {anbm, n =< m }
This is not a regular language. To show that we need to use pumping lemma
1- The opponent: Given a positive integer m
2- We: choose w = aaaa a bbbb b
m
m
3- The opponent: has to decompose w into xyz, |xy| < m
a. xy contains all as, y has at least one a,
b. xy contains all bs, y has at least one b,
c. xy contains some as and some bs, y has as and bs, yi, i > 2, w does not
belong to the language.
d. xy contains some as and some bs, y has at least one b, yi, i =0, we have as
more than bs
4- We: show
a. yi, i > 2, we have as more than bs
b. yi, i =0, we have as more than bs
c. yi, i > 2, w does not belong to the language.
d. yi, i =0, we have as more than bs
Therefore, the language is not regular.
Page 7
Page 8
Page 9
Page 10
Pushdown Automata
1.
b,z/z
,z/z
q1
qf
b,0/00
q0
c,0/
q1
q2
b,0/00
a,z/0z a,0/00
b,0/10
b,1/11
q0
c,1/ c,0/
c,0/
c,1/
,z/z
qf
c,0/
q1
,z/z
qf
In the first solution, we are using a single stack symbol with two states for accepting as then bs.
In the second solution, we are using two different stack symbols for accepting as and bs. But, we are using one
state to accept both of them.
c.
L = {a3nbn : n >= 0 }
a,z/1z
a,1/2
a,2/3
a,3/13
q0
b,3/
b,3/
q1
,z/z
qf
We may use ant three symbols to keep track of every three as. (e.g. x,y,z)
We may use just one symbol and keep adding it. But we need to remove three symbols for each b.
2.
q0
,z/Sz
a,S/B
b,S/BB
b,S/
q1
a,B/BB
b,B/B
a,B/
,z/
qf
Page 11
3.
Page 12
Turing Machine
1.
Construct Turing machines that accepts the following language on {x, y, z}.
a. L = {w: |w| is multiple of 4}
(Draw the transition diagram).
z/z,R
x/x,R
y/y,R
z/z,R
q0
y/y,R
q1
x/x,R
x/x,R
y/y,R
z/z,R
q2
c,0/
x/x,R
y/y,R
z/z,R
q3
/,L
qf
b.
/,R
x/x,R b/b,R
c/c,R a/a,R y/b,R
qx
c/c,R a/a,R
b/b,R
y/y,R
x/x,R
qxy
a/a,R c/c,R
b/b,R
x/a,R
z/c,R
c/c,R a/a,R
c/c,R a/a,R b/b,R
c/c,L a/a,L b/b,L
b/b,R
y/y,R
y/y,R
z/z,R
x/x,L y/y,L z/z,L
y/b,R
z/c,R
qy
qyz
x/a,R
qxyz
z/c,R y/b,R
x/a,R
q1
/,R
z/z,R
x/a,R
b/b,R c/c,R a/a,R
x/a,R
qxz
qf
2.
Construct Turing machines that computes f(x, y) = 3x + y (Draw the transition diagram).
Page 13
3.
Construct Linear bounded automata for L = {wwR: w {a, b, c}+} (Draw the transition diagram).
c/c,L a/a,L
b/b,L
c/c,R a/a,R
b/b,R
qa
a/0,R
b/0,R
]/],L
c/0,R
qaa
b/b,R
c/c,R
a/a,R
0/0,R
q0
]/],L 0/0,L
qb
a/0,L
]/],L 0/0,L
c/c,R a/a,R
b/b,R
qbb
b/0,L
q2
c/0,L
]/],L 0/0,L
qc
qc
qbb
Page 14
RE Language
CSL
CFL
RL
a)
R.E. Language:
b) CSL: anbncn
c)
CFL: anbn
d) RL: a*
X3
b
aba
Y3
X1
abb
bbb
Y1
X4
ba
a
Y4
Page 15