CMPS 260 Spring 2019
Homework #2: Grammars, Languages, Finite Automata
Due: 3pm, Monday, February 25

1. Present a (context-free) grammar that generates the language { ambn  :  m≥n≥0 }.

2. Present a (context-free) grammar that generates the language { w ∈ {a,b}*  :  na(w) ≥ nb(w) }.

3. Present a dfa that accepts the language { w ∈ {0,1}*  :  00101 is a substring of w }.

4. Present a dfa that accepts the language { w ∈ {0,1}*  :  00101 is a substring of w but 111 is not }.

5. Present a dfa that accepts the language { w ∈ {a,b}*  :  na(w) mod 2 = 0 ∧ nb(w) mod 3 ≠ 0 }.

6. Present a dfa that accepts the language { w ∈ {a,b}*  :  (na(w) + 2nb(w)) mod 3 ≠ 1 }.

7. Present a dfa that accepts the language { w ∈ {0,1}+  :  #(w) mod 6 ∈ {1,4} }

where #(w) denotes the numeric value of w when it is interpreted as a binary numeral. For example, #(010110) = 22.

The following facts about # and mod may be useful to you.

#(0) = 0
#(1) = 1
#(w0) = 2⋅#(w)
#(w1) = 2⋅#(w) + 1

(2k + m) mod n  =  (2(k mod n) + m) mod n

8. For string wa, where w ∈ Σ* and a ∈ Σ, let truncate(wa) = w. That is, truncate "chops off" the last symbol of the string to which it is applied. (Meanwhile, truncate(λ) is undefined.)

Present a coherent argument that if L is a language accepted by some dfa, then so is

truncate(L)  =  { truncate(w)  :  w ∈ L }

Such an argument should be of this form: Assume that you are given a dfa M that accepts L (i.e., L(M) = L); explain how you would modify M to obtain a dfa M' that accepts truncate(L) (i.e., L(M') = truncate(L)).