CMSC 330 HOMEWORK EXERCISES #1
Regular Expressions and DFAs
Problems.
In each of the following problems you are given a language and are asked to produce a
regular expression and/or finite automaton for the language.
In some cases you are asked to give either a DFA or regular expression (your
choice) and in other cases to give both a DFA and regular expression. When
writing regular expressions, use an e to denote the empty
string. Write DFAs in the form of a transition diagram.
The underlying alphabet is S = {a, b}.
The notation #a(w) appearing below means the number of a's
occurring in string w.
For example, #a(bbaba) = 2.
- (Either DFA or Reg. Exp) {w | w begins with abab}.
- (Either) {w | w ends with abab}.
- (Either) {w | w begins with ab and ends with ba}.
(Note: The string aba is in this language!)
- (Either) {w | either #a(w) is divisible by 3 or w
begins with bbb}.
- (Either) {w | #a(w) º 2 (mod 5)
}.
(Recall that i º j (mod k) if and
only if (i-j) is divisible by k.)
- (Either) {w | #a(w) º 1 (mod 3)
and #b(w) is odd}.
- (Either) {w | #a(w) is even or |w| is even}.
- (Both DFA and Reg. Exp) {w | aaa is a substring of w}.
- (Both) {w | aaa is not a substring of w}.
- (Either) {w | w contains exactly one occurrence of the substring
aaa}.
(Note: the string aaaa has two occurrences of aaa!)
- (DFA only) {w | neither aa nor bb is a substring of w}.