Bài tập ngôn ngữ hình thức

23 1.3K 8
Bài tập ngôn ngữ hình thức

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

1. Let L = {ab,aa,baa}. Which of the following strings are in L*: abaabaaabaa, aaaabaaaa, baaaaabaaaab baaaaabaa? 2. For which language it is true that L = L*? a. L = {a n b n+1 : n≥0} b. L = {w: n a (w)=n b (w)} 3. Which of the strings 0001, 01001, 0000110 are accepted by the following dfa: 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 = {ab 5 wb 4 : w ∈ {a,b}*} 6. 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} 7. Consider the set of strings on {0,1} in which every 00 is followed immediately by 1. For example 101, 0010, 0010011001 are in the language, but 0001 and 00100 are not. Construct an accepting dfa 8. Show that the language L = {a n : n ≥ 0, n ≠ 4} is regular. 9. Find δ*(q 0, a) and δ*(q 1, λ ) for the following nfa 10. For the following nfa, find δ*(q 0, 1010) and δ*(q 1, 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} 16. 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 24. 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: L 1 = {a n b 2m c 2k } and L 2 = {a 2n b 4m c k } 27. The nor of two languages is defined as follows: nor(L 1 ,L 2 ) = {w: w ∉L 1 and w ∉L 2 } Show that nor is closed for regular lanaguages 28. Let L 1 = L(a*baa*) and L 2 = (aba*). Find L 1 /L 2 29. Suppose L 1 ∪L 2 is regular and L 1 is finite. Can we conclude that L 2 is regular? 30. 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)} 31. Find context-free grammars for the following languages a. L = {a n b m : n ≤ m +3} b. L = {a n b m : n ≠ m -1} c. L = {a n b m : n ≠ 2m} d. L = {a n b m : 2n ≤ m ≤ 3m} e. L = {a n b m c k : n = m or m ≤ k} f. L = {a n b m c k : k = |n-m|} g. L = {a n ww R b n : w ∈ {a,b}*} h. L = {a n b n } 2 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 33. 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 grammars 41. Eliminate useless and unit productions for the following grammar: S  a | aA | B | C A  aB | λ B  Aa C  cCD D  ddd 42. Eliminate all λ-production from S  AaB | aaB A  λ B  bbA | λ 43. Transform the following grammars to Chomsky normal form: S  aSb | ab S  aSaA | A A  abA |b S  abAB A  bAB | λ B  BAa | A | λ 44. Convert the following grammars into Greibach normal form: S  aSb | ab S  ab | aS | SS 45. Transform the following grammars to Chomsky normal form: S  aSb | ab S  aSaA | A A  abA |b S  abAB A  bAB | λ B  BAa | A | λ 46. Convert the following grammars into Greibach normal form: S  aSb | ab S  ab | aS | SS 47. Prove that the following dpa does not accept any string not in {ww R } Q = {q 0 ,q 1 ,q 2 }, ∑ = {a,b}, Γ = {a,b,z}, F = {q 2 } δ(q 0 ,a,a) = {(q 0 ,aa)} δ(q 0 ,b,a) = {(q 0 ,ba)} δ(q 0 ,a,b) = {(q 0 ,ab)} δ(q 0 ,b,b) = {(q 0 ,bb)} δ(q 0 ,a,z) = {(q 0 ,az)} δ(q 0 ,b,z) = {(q 0 ,bz)} δ(q 0 ,λ,a) = {(q 1 ,a)} δ(q 0 ,λ,b) = {(q 1 ,b)} δ(q 1 ,a,a) = {(q 1 ,λ)} δ(q 1 ,b,b) = {(q 1 ,λ)} δ(q 1 ,λ,z) = {(q 2 ,λ)} 48. Construct npda’s that accept the following languages on ∑ = {a,b,c} a) L = {a n b 2n } b) L = {wcw R } c) L = {a 3 b n c n } d) L = {a n b m , n ≤ m ≤ 3n} e) L = {w: n a (w) = n b (w)} f) L = {w: n a (w) = 2n b (w)} 49. Prove that the following pda accepts the language L = {a n+1 b 2n } δ(q 0 ,λ,z) = {(q 1 ,Sz)} δ(q 1 ,a,S) = {(q 1 ,SA),(q 1 , λ )} δ(q 1 ,b,A) = {(q 1 ,B)} δ(q 1 ,b,B) = {(q 1 , λ )} δ(q 1 ,λ,z) = {(q 2 , λ )} 50. Construct an npda corresponding to the following grammar S  aABB | aAA A  aBB | a B  bBB | A 51. 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? abaabaaabaa aaaabaaaa baaaaabaa 53. For which language it is true that L = L*? a. L = {a n b n+1 : n≥0} b. L = {w: n a (w)=n b (w)} a. No (give a counter-example) b. Yes (Proof is left for students) 54. Which of the strings 0001, 01001, 0000110 are accepted by the following 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 = {ab 5 wb 4 : 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} 58. Consider the set of strings on {0,1} in which every 00 is followed immediately 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 δ*(q 0, a) and δ*(q 1, λ ) for the following nfa δ*(q 0, a) = {q 0 ,q 1 ,q 2 } δ*(q 1, λ ) = {q 0 ,q 1 ,q 2 } 61. For the following nfa, find δ*(q 0, 1010) and δ*(q 1, 00) δ*(q 0, 1010) = {q 0 ,q 2 } δ*(q 1, 00) = {} 62. Find an nfa with three states that accepts the language {ab,abc}* 63. Convert the following nfa into dfa a. b.

Ngày đăng: 13/05/2014, 20:49

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan