Assignment#1
Assignment#1
2. Write set of strings and complement set for each of the following languages.
a) L1 = {w {a, b}*: each a in w is immediately preceded and immediately followed by a b}.
Ans. Set of strings L1 can have: L1 = {bab, bbabab, babbb…}
The complement will be the set of strings that do not satisfy the provided criteria and would be:
L1’= {a, aab, aaa, baab…}
b) L2 = {w {a, b}*: w has abba as substring}.
Ans. abba as substring means it can come either at the beginning, end and in the middle. L2 =
{abba, aabba, aaabbabbb…}
The complement will the set of strings that do not satisfy the criteria or those that don’t have
abba as a substring.
L2’ = {aaa, bbb, bbbaab, abababaa…}
c) L3 = {w {a, b}*: w has neither aa nor bb as a substring}.
Ans. Set of strings L3 can have: L3 = {a, b, ab, bab, aba, ababa…}
The complement will simply have strings containing aa and bb: L3 = {aabb, aabbabab,
aabaabb…}
d) L4 = {w {a, b}*: w has an even number of substring ab}.
Ans. The set of Strings L4 can have: L4 = {abab, aaababababbbb, aaabbabbb…}.
The complement will be those that do not satisfy the criteria for L4: L4’= {ab, aaa, ababab,
abaaa, bbbab…}
e) L5 = {w {a, b}*: w has both ab & ba as substrings}.
Ans. The set of strings L5 can have: L5 = {abba, abaaba, bbbabbbab…}.
The complement L5’ = {aaa, abaa, baaa, bbbba …}.
3. Construct DFA for each of the following languages using any Automata Simulator.
(Hand drawn answer is not accepted). Also give formal description of each DFA.
a) L6 = {w {a, b}*: w contains a’s and b’s and end in bb}.
Following is the DFA for L6:
Formal Description:
Q (The finite set of states): {start, s0, s1, s2}
∑ (The finite set of symbols): {a, b}
δ: Q x Σ Q:
δ (start, a) = s0
δ (start, b) = start
δ (s0, a) = s0
δ (s0, b) = s1
δ (s1, a) = s0
δ (s1, b) = s2
δ (s2, a) = s0
δ (s2, b) = s2
b) L7 = {w {a, b}*: w contains different first and last letters. If a string begins with a, to be
accepted it must end with a b and vice versa}.
Following is the DFA for L7:
Formal Description:
Q (The finite set of states): {start, s0, s1, s2, s3}
∑ (The finite set of symbols): {a, b}
δ: Q x Σ Q
δ (start, a) = s0
δ (start, b) = s2
δ (s0, a) = s0
δ (s0, b) = s1
δ (s1, a) = s0
δ (s1, b) = s1
δ (s2, a) = s3
δ (s2, b) = s2
δ (s3, a) = s3
δ (s3, b) = s2
c) L8 = {w {a, b}* :when w starts with a and has odd number of a’s or starts with b and has
even number of b’s }.
Following is the DFA for L8:
Formal Description:
Q (The finite set of states): {start, s0, s1, s2}
∑ (The finite set of symbols): {a, b}
δ: Q x Σ Q
δ (start, a) = s1
δ (start, b) = s0
δ (s0, a) = s2
δ (s0, b) = start
δ (s1, a) = start
δ (s1, b) = s2
δ (s2, a) = s0
δ (s2, b) = s1
d) L9 = {w {a, b}* : w has three consecutive b’s (not necessarily at the end)}.
Following is the DFA for L9:
Formal Description:
Q (The finite set of states): {start, s0, s1, s2}
∑ (The finite set of symbols): {a, b}
δ: Q x Σ Q
δ (start, a) = start
δ (start, b) = s0
δ (s0, a) = start
δ (s0, b) = s1
δ (s1, a) = start
δ (s1, b) = s2
δ (s2, a) = s2
δ (s2, b) = s2
Formal Description:
Q (The finite set of states): {start, s0, s1, s2}
∑ (The finite set of symbols): {a, b}
δ: Q x Σ Q
δ (start, a) = s1
δ (start, b) = s0
δ (s0, a) = s2
δ (s0, b) = start
δ (s1, a) = start
δ (s1, b) = s2
δ (s2, a) = s0
δ (s2, b) = s1