0% found this document useful (0 votes)
26 views5 pages

HW 1

Uploaded by

Breeha Qasim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views5 pages

HW 1

Uploaded by

Breeha Qasim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Homework 1: Regular Languages: Automata and Expressions

CS 212 Nature of Computation


Habib University
Homework 1 Team 11
Fall 2023

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 = {w ∈ Σ∗ | na (w) ≥ 2, nb (w) ≤ 1}.

3. 30 points Given the languages, A and B, we derive the language, C = {w ∈ A | w ∈ B}.


Prove or disprove the following claim.
Claim 1. If A and B are regular languages, then so is C.

4. 35 points Given the languages, A and B, we define the following operation.

A ⌣a B = {u ∈ A | ∃v ∈ B ∋ na (u) = na (v)}

Prove or disprove the following claim.


Claim 2. The class of regular languages is closed under ⌣a .

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

Given the languages A and B, and C = {w ∈ A | w ∈ B}, we need to prove or disprove


that if A and B are regular languages, then C is also a regular language.
By definition, C is the language that consists of all the strings w that belong to both A
and B. So C = A ∩ B.
If A and B are regular languages, then there must exist some finite automata that recognizes
them. Let M1 and M2 be the DFAs that recognize A and B respectively. Then:
- M1 = (Q, Σ, δA , qo , FA ) recognizes A
- M2 = (R, Σ, δB , ro , FB ) recognizes B
Then we can construct a DFA M3 for C that keeps track of the pair of states (qi , rj ), where
qi ∈ Q and rj ∈ R. In this construction, the states of the new DFA are pairs of states from
the A and B, that is, the Cartesian Product of the two languages
Q × R = {(q, r) | q ∈ Q and r ∈ R}
P
Then M3 = (Q × R, , δ, (qo , ro ), FA × FB ).
For M3 ,
- Set of states Q × R, the Cartesian Product of Q and R to include all pairs of states
in both the machines as mentioned above.
P
- remains the same as the input alphabet.
- We have the transition function δ defined as
X
δ((q, r), a) = (δA (q, a), δB (r, a)) ∀q, r ∈ Q, R and ∀a ∈
- The start state is (qo , ro ) which is the pair of start states of M1 and M2 .
- The set of accept states is again the Cartesian Product of the accept states of M1
and M2 , that is, all pairs of states (qf , rf ) where qf ∈ FA and rf ∈ FB .

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

Given the regular languages A and B, A ⌣a B = {u ∈ A | ∃v ∈ B ∋ na (u) = na (v)}. This


operation takes two languages A, and B, and produces a new language that contains all
strings u ∈ A that have the same number of occurrences of a as some string v ∈ B.
Let C be the language obtained by the operation A ⌣a B. Then C = A ⌣a B.
If A and B are two regular langauges, then there must exist some finite automata that
recognizes them. Let M1 and M2 be the DFAs that recognize A and B respectively. Then:
- M1 = (Q, Σ, δA , qo , FA ) recognizes A
- M2 = (R, Σ, δB , ro , FB ) recognizes B
Then we can construct an NFA MC that recognizes C as follows. To decide whether u ∈ A
P some string v ∈ B
for some arbitrary string u, and in parallel nondeterministically guess
such that v contains the same number of a’s in u. Then MC = {Q, , δ, qo , F } where:
1. Q = Q1 × Q2 , the Cartesian Product of the states of M1 and M2 .
P
2. remains the same as the input alphabet.
3. qo = qo
4. F = FA × FB
P
5. δ((q, r), s) where q ∈ Q, r ∈ R, s ∈ ε ,

 {δA (q, s), δB (r, s)}, s = a
δ((q, r)s) = {δA (q, s), r}, s=b
{q, δB (r, s)}, s=ε

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

You might also like