Give a regular expression for the language on ∑={a,b,c} containing no run of a’s of length greater than two.17.. Give a regular expression for the language on ∑={a,b} containing all str
Trang 11 Let L = {ab,aa,baa} Which of the following strings are in L*:
4 Give dfa’s for the sets consisting of
a all strings with exactly one a.
b all strings with no more than three a’s
5 Give a dfa for the language L = {ab5wb4: w ∈ {a,b}*}
6 Find dfa’s for the following languages on ∑ = {a,b}
8 Show that the language L = {a n : n ≥ 0, n ≠ 4} is regular
9 Find δ*(q0, a) and δ*(q1,λ) for the following nfa
Trang 210 For the following nfa, find δ*(q0,1010) and δ*(q1,00)
11 Find an nfa with three states that accepts the language {ab,abc}*
12 Convert the following nfa into dfa
13 Convert the following nfa into dfa
14 Find all strings in L((a+b)*b(a+ab)*) of length less than four.
15 Find a regular expression for the set {a n b m : (n+m) is even}
Trang 316 Give a regular expression for the language on ∑={a,b,c} containing no run of a’s of length greater than two.
17 Give a regular expression for the language on ∑={a,b} containing all
strings not ending in 01
18 Give a dfa that accepts L((a+b)*b(a+ab)*)
19 Find regular expressions for the language accepted by the following automaton:
20 Construct a dfa that accepts that language generated by the following grammar
S abA
A baB
B aA | Bilbo
21 Construct left-linear grammar for the language in Problem 8
22 Construct right-linear and left-linear grammars for the language L = {a n b m ,n≥2,m≥3}
23 Construct a dfa that accepts that language generated by the following grammar
S abA
A baB
B aA | bb
Trang 424 Construct left-linear grammar for the language in Problem 2
25 Construct right-linear and left-linear grammars for the language L = {a n b m ,n≥2,m≥3}
26 Find intersection of the two following languages: L1 = {a n b 2m c 2k } and L2
= {a 2n b 4m c k}
27 The nor of two languages is defined as follows:
nor(L1,L2) = {w: w ∉L1 and w ∉L2 }
Show that nor is closed for regular lanaguages
28 Let L1 = L(a*baa*) and L2 = (aba*) Find L1/L2
29 Suppose L1∪L2 is regular and L1 is finite Can we conclude that L2 is regular?
30 Prove that the following languages are not regular
32 Show a derivation tree, together with the corresponding leftmost and
rightmost derivations of the string aabbbb with the grammar
S AB | λ
A aB
B Sb
Trang 533 Find a context-free grammar for the set of all regular expressions on the
alphabet {a,b}* Give a derivation tree for (a+b)*+a+b
34 Find an s-grammar for L(aaa*b+b)
35 Show that every s-grammar is unambigous
36 Show that the following grammars is ambigous
S AB | aaB
A a | aA
B b
S aSbS|bSaS|λ
37 Is it possible for a regular grammar to be ambigous?
38 Find an s-grammar for L(aaa*b+b)
39 Show that every s-grammar is unambigous
40 Consider the following grammar:
S aSb | SS | λ
Eliminate left-recursive for the grammar
Show a derivation for the string w = aabbab using both orignal and rewriten
Trang 643 Transform the following grammars to Chomsky normal form:
Trang 751 Show that L = {a n b 2n} is a deterministic context-free language
52 Let L = {ab,aa,baa} Which of the following strings are in L*:
abaabaaabaa, aaaabaaaa, baaaaabaaaab, baaaaabaa?
Trang 854 Which of the strings 0001, 01001, 0000110 are accepted by thefollowing nfa:
0001
01001
55 Give dfa’s for the sets consisting of
a all strings with exactly one a.
b all strings with no more than three a’s
56 Give a nfa for the language L = {ab5wb4: w ∈ {a,b}*}
57 Find dfa’s for the following languages on ∑ = {a,b}
a L = {w: |w| mod 3 = 0}
b L = {w: |w| mod 5 ≠ 0}
c L = {w: n a (w) mod 3 > 1}
Trang 958 Consider the set of strings on {0,1} in which every 00 is followedimmediately by 1 For example 101, 0010, 0010011001 are in the language,but 0001 and 00100 are not Construct an accepting dfa
59 Show that the language L = {a n : n ≥ 0, n ≠ 4} is regular
60 Find δ*(q0, a) and δ*(q1,λ) for the following nfa
Trang 1062 Find an nfa with three states that accepts the language {ab,abc}*
63 Convert the following nfa into dfa
a
b
Trang 11a
b
Optimize the DFA if you want (read Section 1.3 for DFA optimization):
Thus, the language is, surprisingly, (0+1)*
64 Find all strings in L((a+b)*b(a+ab)*) of length less than four.
Trang 12Method 1:
A string of the given language can be considered as a sequence of patterns
each of which is either ax, x or aax (when a run of 2 a’s appears, it must be followed immediately by b to make sure that the run stops with no more a) where x is either b or c The sequence can stop exceptionally by either aa or
a.
The corresponding regular expression:
(a(b+c)+(b+c)+aa(b+c))(aa+a+λ)
Method 2:
One can easily construct a DFA for the language as follows:
The required regular expression can then be derived from the DFA, which should be the same as that given from Method 1
67 Give a regular expression for the language on ∑={a,b} containing all
strings not ending in ab
(a+b)*(aa+ab+ba) + b + λ
68 Give a dfa that accepts L((a+b)*b(a+ab)*)
Trang 1369 Find regular expressions for the language accepted by the following automaton:
Trang 1474 The nor of two languages is defined as follows:
Since L1 is finite, so is L2 ∩ L1 Hence L2 ∩ L1 is also regular (3).
From (1),(2) and (3), L2 is regular.
Note: If L1 is regular but not finite, we could not conclude anything about L2since the fact (3) above can not be claimed to complete the proof One can
easily find a counter-example showing that whereas L1∪L2 and L1 are
regular, L2 can still be not regular.
77 Prove that the following languages are not regular
a L = {a n b m , n ≤ m}
b L = {w: n a (w) ≠ n b (w)}
Read Linz’s book
78 Find context-free grammars for the following languages
Trang 1579 Show a derivation tree, together with the corresponding leftmost and rightmost
derivations of the string aabbbb with the grammar
S AB | λ
A aB
Trang 16B Sb
S => AB => aBB => aSbB => aABbB => aaBBbB => aaSbBbB => aabBbS => aabSbbB
=> aabbbB => aabbbSb => aabbbb
80 Find a context-free grammar for the set of all regular expressions on the alphabet
{a,b}* Give a derivation tree for (a+b)*+a+b
E E + T | T
T T.F | F
F (E) | E*| a | b
The tree is left for students to construct
81 Show that the following grammars is ambigous
S => aSbS => abSaSbS =>* abab
S => aSbS => aSbaSbS =>* abab
Draw the corresponding trees for the above derivations to observe the ambiguities.
82 Is it possible for a regular grammar to be ambigous?
S aAB | aaB
A a
B b
Trang 1783 Find an s-grammar for L(aaa*b+b)
S aS1 | b
S1 aA
A aA | b
84 Show that every s-grammar is unambigous
Consider an s-grammar Gs If Gs is ambigous, there is at least a string s = a1 a2…a n ∈
L(G s) of which two distinct derivation tree exits, namely T1 and T2 Let D1 and D2 be the two leftmost derivations of T1 and T2 respectively Since T1 and T2 are distinct, D1 and D2
must be different However, since Gs is an s-grammar, w should have only one unique
leftmost derivation as S=> a1 x1 => a1a 2 x2 =>…=> a1a2…an, hence the conflict.
85 Consider the following grammar:
S aSb | SS | λ
Eliminate left-recursive for the grammar.
S aSbT | T
T ST | λ
Show a derivation for the string w = aabbab using both orignal and rewriten grammars
S => SS => aSbS =>aaSbbS => aabbS => aabbaSb => aabbab
S => aSbT => aaSbTbT => aaTbTbT => aabTbT => aabbT => aabbST => aabbaSbTT => aabbabTT => aabbabTT => aabbabT => aabbab
86 Eliminate useless and unit productions for the following grammar:
Trang 1887 Eliminate all λ -production from
Trang 19Convert to Chomsky form:
S A’S 1 | A’S3 | A’S4 | A’B’
Trang 20(One can realize that A2 a now becomes useless and removable from the grammar)
90 Prove that the following ndpa does not accept any string not in {ww R}
Trang 21δ(q1,a,a) = {(q1,λ )}
δ(q1,b,b) = {(q1,λ )}
δ(q1,λ,z) = {(q2,λ )}
One can observe that the following move sequences cannot happen on the ndpa:
(q1,x,y) |* (q0,x’,y’) ∀x,x’∈ ∑*, y,y’∈ ∑ *; and
(q2,x,y) |* (q1,x’,y’) ∀x,x’∈ ∑*, y,y’∈ ∑ *.
Thus any string w accepted by the ndpa must be of the sequence form as follows: