HW 1
HW 1
General instructions
• For drawing finite automata, see this TikZ guide or the JFLAP tool. Hand drawn diagrams
will not be accepted.
• Please ensure that your solutions are neatly formatted and organized, and use clear and
concise language.
• Please consult Canvas for a rubric containing the breakdown of points for each problem.
• For all the problems below, Σ = {a, b}.
• Some of the problems below make use of the following count function.
na (w) = the number of occurrences of a in w, where a ∈ Σ, w ∈ Σ∗ .
Problems
1. 15 points List 2 members and 2 non-members of the language, (a ∪ ba ∪ bb)Σ∗ .
2. 20 points Provide the state diagram of a simplified DFA that recognizes the language,
A ⌣a B = {u ∈ A | ∃v ∈ B ∋ na (u) = na (v)}
1
CS 212 HW 1: Regular Languages , Fall 2023
Solution:
Problem 1
Members: a, ba
Non-members: ε, b
Problem 2
A = {w ∈ Σ∗ | na (w) ≥ 2, nb (w) ≤ 1} describes the language that contains at least
2 occurences of ‘a’, and at most one occurence of ‘b’. The DFA for this language is as
follows:
a
q0 q1 q2
a a
b b b
a
q3 q4 q5
a a
b
b
b
q6
a, b
The above DFA shows that for any string that contains more than 1 ‘b’, then machine goes
to a regular state and stays there. If the string contains 1 or less ‘b’, and 2 or more ‘a’, the
machine goes to an accept state.
Page 2 of 5
CS 212 HW 1: Regular Languages , Fall 2023
Problem 3
Therefore, by this construction of M3 , we have created a DFA that would only reach an
accepting state if both, M1 and M2 reach the accept state. Therefore, the string would
have to be accepted by both M1 and M2 . Hence, for any arbitrary string w that is accepted
by M3 , w ∈ A and w ∈ B.
Hence, if A and B are regular languages, then we can construct a DFA to recognize C =
{w ∈ A | w ∈ B}, therefore, C is also a regular language.
If there are no strings common to both A and B, then C will be an empty language,
meaning it will only consist of the empty string ε. Then C = {ε} which is also a regular
language as again a DFA can be constructed with only 1 state as both the start and accept
state.
Therefore C is a regular language.
Page 3 of 5
CS 212 HW 1: Regular Languages , Fall 2023
Problem 4
The machine must have a parir of all states that exist in A and B, that is, the Cartesian
Product of the two languages, the start state same as qo , accept states FA × FB .
The transition function is defined such that it has a pair of states, and an alphabet;
1. if the current alphabet is a, then it moves on to the next state in A, and the next
state in B, which means that the NFA is now trying to guess a string v ∈ B that
has the same number of occurrences of a as the current input string and the previous
input alphabet
2. if the current alphabet is b, then the NFA moves on to the next state in A while
remaining in the same state in B which again means that the NFA is trying to guess
a string v ∈ B that has the same number of occurrences of a as the current input
string and the previous input alphabet, however, it does not change its state in B
since we are concerned with the number of occurrences of a
3. if we have an ε or an empty string, then it moves on to the next state in B while
remaining in the same state in A
Then the NFA MC accepts a string if and only if ∀u ∈ A, ∃v ∈ B such that na (u) = na (v).
Again this claim can be proved by showing that the language of MC is a subset of the
language of A ⌣a B and vice versa.
Page 4 of 5
CS 212 HW 1: Regular Languages , Fall 2023
Suppose MC accepts a string s, meaning that it reaches the accept state when processing
s. We defined the accept states F as a pair of accept states from MA and MB , i.e., (qf , rf )
where qf ∈ FA , rf ∈ FB . For each alphabet si in s, the transition function ensures that
the NFA moves to the next state in A and B if si = a, and moves to the next state in A
while remaining in the same state in B if si = b. This means that the NFA is guessing a
string v ∈ B that has the same number of occurrences of a as the current input string and
the previous input alphabet. If the NFA reaches the accept state, it implies that MA also
reaches the accept state qf ∈ FA after processing a substring u of s, and MB reaches an
accept state rf ∈ FB after processing a substring v of s. Crucially, since MC accepts s,
there must be a sequence of transitions in MC that correspond to reading the alphabets in
s such that na (u) = na (v) since for each alphabet ‘a’ in s, MC consumes one ‘a’ in both
machines, and for each alphabet ‘b’ in s, MC consumes one ‘b’ in MB . Hence na (u) = na (v),
therefore, L(MC ) ⊆ A ⌣a B.
Now consider strings u ∈ A and v ∈ B, such that na (u) = na (v). Then we can construct a
string s from u and v such that s ∈ A ⌣a B by the definition of the smile operation. Then
s is some concatenation of u and v. When MC processes s, for each alphabet ‘a’ in s, MC
consumes one ‘a’ in both machines, and for each alphabet ‘b’ in s, MC consumes one ‘b’
in MB . Hence MC reaches the accept state in the final state of MA and MB both which
corresponds to qf ∈ FA and rf ∈ FB respectivel. Therefore, A ⌣a B ⊆ L(MC ).
Hence, the class of regular languages is closed under ⌣a .
Page 5 of 5