Understanding Regular Expressions and Automata
Understanding Regular Expressions and Automata
Module 2
December 8, 2025
Learning Objectives and Outcomes
1 Regular Expression
4 My-Hill-Nerode Theorem
Regular Expression
Regular Expression
Regular Expression
Regular Expression
r=(aa)∗ (bb)∗ b
r=(aa)∗ (bb)∗ b
denotes the set of all strings with even number of a’s followed
by an odd number of b’s
r=(aa)∗ (bb)∗ b
denotes the set of all strings with even number of a’s followed
by an odd number of b’s
L(r)={a2n b 2m+1 |n≥0, m≥0}
r=(aa)∗ (bb)∗ b
denotes the set of all strings with even number of a’s followed
by an odd number of b’s
L(r)={a2n b 2m+1 |n≥0, m≥0}
For Σ ={0,1}. Give a regular expression ’r’ such that
L(r)={w∈ Σ∗ |w has atleast one pair of consequtive zeroes}
r=(aa)∗ (bb)∗ b
denotes the set of all strings with even number of a’s followed
by an odd number of b’s
L(r)={a2n b 2m+1 |n≥0, m≥0}
For Σ ={0,1}. Give a regular expression ’r’ such that
L(r)={w∈ Σ∗ |w has atleast one pair of consequtive zeroes}
Solution: r=(0 + 1)∗ 00(0 + 1)∗
r=(aa)∗ (bb)∗ b
denotes the set of all strings with even number of a’s followed
by an odd number of b’s
L(r)={a2n b 2m+1 |n≥0, m≥0}
For Σ ={0,1}. Give a regular expression ’r’ such that
L(r)={w∈ Σ∗ |w has atleast one pair of consequtive zeroes}
Solution: r=(0 + 1)∗ 00(0 + 1)∗
Find R.E. for language
L={w ∈ {0, 1}∗ |w has no pair of consecutive zeroes}
r=(aa)∗ (bb)∗ b
denotes the set of all strings with even number of a’s followed
by an odd number of b’s
L(r)={a2n b 2m+1 |n≥0, m≥0}
For Σ ={0,1}. Give a regular expression ’r’ such that
L(r)={w∈ Σ∗ |w has atleast one pair of consequtive zeroes}
Solution: r=(0 + 1)∗ 00(0 + 1)∗
Find R.E. for language
L={w ∈ {0, 1}∗ |w has no pair of consecutive zeroes}
Solution: r=(1 + 01)∗ (0 + λ)
r=(1∗ 011∗ )∗ (0 + λ) + 1∗ (0 + λ)
r=(aa)∗ (bb)∗ b
denotes the set of all strings with even number of a’s followed
by an odd number of b’s
L(r)={a2n b 2m+1 |n≥0, m≥0}
For Σ ={0,1}. Give a regular expression ’r’ such that
L(r)={w∈ Σ∗ |w has atleast one pair of consequtive zeroes}
Solution: r=(0 + 1)∗ 00(0 + 1)∗
Find R.E. for language
L={w ∈ {0, 1}∗ |w has no pair of consecutive zeroes}
Solution: r=(1 + 01)∗ (0 + λ)
r=(1∗ 011∗ )∗ (0 + λ) + 1∗ (0 + λ)
Find all strings in L((a + b)∗ b(a + ab)∗ ) of length less than 4
r=(aa)∗ (bb)∗ b
denotes the set of all strings with even number of a’s followed
by an odd number of b’s
L(r)={a2n b 2m+1 |n≥0, m≥0}
For Σ ={0,1}. Give a regular expression ’r’ such that
L(r)={w∈ Σ∗ |w has atleast one pair of consequtive zeroes}
Solution: r=(0 + 1)∗ 00(0 + 1)∗
Find R.E. for language
L={w ∈ {0, 1}∗ |w has no pair of consecutive zeroes}
Solution: r=(1 + 01)∗ (0 + λ)
r=(1∗ 011∗ )∗ (0 + λ) + 1∗ (0 + λ)
Find all strings in L((a + b)∗ b(a + ab)∗ ) of length less than 4
Find R.E. for set {an b m :(n+m) is even}
L(a∗ + a∗ (a + b)c∗)
State Elimination method
Arden’s Theorem
1 ϕ+R=R
2 ϕR = R ϕ = ϕ
3 ΛR = RΛ =R
4 Λ∗ = Λ and ϕ∗ = Λ
5 R+R=R
6 R ∗R ∗ = R ∗
7 RR ∗ = R ∗ R
8 (R ∗ )∗ = R ∗
9 Λ + RR ∗ = R ∗ = Λ + R ∗ R
10 (PQ)∗ P = P(QP)∗
11 (P + Q)∗ = (P ∗ Q ∗ )∗ =(P ∗ + Q ∗ )∗
12 (P+Q)R = PR + QR and R(P+Q) = RP + RQ
ϵ-NFA
=⇒ Moving without reading a symbol from Input Tape.
ϵ-NFA
=⇒ Moving without reading a symbol from Input Tape.
State/Input 0 1 ϵ
A B,C A B
B - B C
C C C -
ϵ-NFA
=⇒ Moving without reading a symbol from Input Tape.
State/Input 0 1 ϵ
A B,C A B
B - B C
C C C -
Epsilon Closure
ϵ-closure for a given state X is a set of States which can be
reached from states X with only (null) or ϵ moves including the
state X itself.
ϵ-NFA
=⇒ Moving without reading a symbol from Input Tape.
State/Input 0 1 ϵ
A B,C A B
B - B C
C C C -
Epsilon Closure
ϵ-closure for a given state X is a set of States which can be
reached from states X with only (null) or ϵ moves including the
state X itself.
Example: ϵ closure (A)={A,B,C}
ϵ closure (B)={B,C}
ϵ closure (C)={C}
Department of Computer Science and Engineering RE December 8, 2025 16/68
Regular Expression
Steps:
1 Take ϵ closure of initial state as begining state
2 Find states that can be traversed from present from present
state for each input symbol
3 If any new state is found, repeat step 2 till we get no new
state in the transition table.
4 Mark states containing final states as new final state.
State/Input 0 1
{A,B,C} {B,C} {A,B,C}
Steps:
1 Take ϵ closure of initial state as begining state
2 Find states that can be traversed from present from present
state for each input symbol
3 If any new state is found, repeat step 2 till we get no new
state in the transition table.
4 Mark states containing final states as new final state.
State/Input 0 1
{A,B,C} {B,C} {A,B,C}
{B,C} {C} {B,C}
Steps:
1 Take ϵ closure of initial state as begining state
2 Find states that can be traversed from present from present
state for each input symbol
3 If any new state is found, repeat step 2 till we get no new
state in the transition table.
4 Mark states containing final states as new final state.
State/Input 0 1
{A,B,C} {B,C} {A,B,C}
{B,C} {C} {B,C}
{C} {C} {C}
Steps:
1 Take ϵ closure of initial state as begining state
2 Find states that can be traversed from present from present
state for each input symbol
3 If any new state is found, repeat step 2 till we get no new
state in the transition table.
4 Mark states containing final states as new final state.
State/Input 0 1
{A,B,C} {B,C} {A,B,C}
{B,C} {C} {B,C}
{C} {C} {C}
Arden’s Theorem
Let P and Q be two regular expressions over Σ. If P doesnot
contain Λ, then the following equation in R i.e. R=Q+RP
has a unique solution R=QP ∗
Proof:
R = Q + RP (1)
putting ”R=Q+RP” in equation 1
R=Q+QP+RPP
putting R recursively again and again
we get:
R=Q+QP+QP 2 +QP 3 + . . .
R= Q (Λ + P + P 2 + P 3 + . . .)
R=QP ∗
Arden’s Theorem
Let P and Q be two regular expressions over Σ. If P doesnot
contain Λ, then the following equation in R i.e. R=Q+RP
has a unique solution R=QP ∗
Proof:
R = Q + RP (1)
putting ”R=Q+RP” in equation 1
R=Q+QP+RPP
putting R recursively again and again
we get:
R=Q+QP+QP 2 +QP 3 + . . .
R= Q (Λ + P + P 2 + P 3 + . . .)
R=QP ∗
Assumptions:
The transition diagram must not have null transitions.
It must only 1 initial state
Arden’s Theorem I
1. Find R.E. for the following DFA
q1 = q1 0 + q3 0 + ∧ (2)
q2 = q1 1 + q2 1 + q3 1 (3)
q3 = q2 0 (4)
putting equation 4 in equation 3
q2 = q1 1 + q2 1 + q3 1
= q1 1 + q2 1 + (q2 0)1
= q1 1 + q2 (1 + 01)
Department of Computer Science and Engineering RE December 8, 2025 19/68
Regular Expression
Arden’s Theorem II
Applying Arden’s Theorem
q2 = q1 1(1 + 01)∗ (5)
putting 5 in equation 2
q1 = q1 0 + q3 0 + ∧
= q1 0 + q2 00 + ∧
= q1 0 + (q1 1(1 + 01)∗ 00) + ∧
q1 (0 + 1(1 + 01)∗ 00) + ∧
using arden’s theorem again
∗
q1 = ∧(0 + 1(1 + 01)∗ 00)
∗
(0 + 1(1 + 01)∗ 00)
∗
As q1 is the final state. ∴ r= (0 + 1(1 + 01)∗ 00)
Department of Computer Science and Engineering RE December 8, 2025 20/68
Regular Expression
Arden’s Theorem
Arden’s Theorem I
Consider the transition system below. Prove that the strings
∗
recognized are (a + a(b + aa)∗ b) a(b + aa)∗ a
Solution:
q1 = q1 a + q2 b + ∧ (6)
q2 = q1 a + q2 b + q3 a (7)
q3 = q2 a (8)
Arden’s Theorem II
Putting equation 8 in equation 7
q2 = q1 a + q2 b + q2 aa
q2 = q1 a + q2 (b + aa)
q2 = q1 a(b + aa)∗
q1 = q1 a + q2 b + ∧
= q1 a + q1 a(b + aa)∗ b + ∧
= q1 (a + a(b + aa)∗ b) + ∧
∗
= ∧(a + a(b + aa)∗ b)
∗
= (a + a(b + aa)∗ b)
putting this in q2
∗
q2 = (a + a(b + aa)∗ b) a + q2 b + q2 aa
∗
= (a + a(b + aa)∗ b) a + q2 (b + aa)
∗
= (a + a(b + aa)∗ b) a(b + aa)∗
putting q2 in q3
∗
q3 = (a + a(b + aa)∗ b) a(b + aa)∗ a (9)
Arden’s Theorem I
Prove that the finite automaton whose transition diagram
below accepts the set of all strings over alphabet {a,b} with
an equal number of a’s and b’s, such that each prefix has
atmost one more a than the b’s and atmost one more b than
the a’s
Arden’s Theorem II
Solution:
q1 = q2 b + q3 a + ∧ (10)
q2 = q1 a (11)
q3 = q1 b (12)
q4 = q2 a + q3 b + q4 a + q4 b (13)
putting q2 and q3 in q1
q1 = q1 ab + q1 ba + ∧
q1 = q1 (ab + ba) + ∧
q1 = ∧(ab + ba)∗
q1 = (ab + ba)∗
Department of Computer Science and Engineering RE December 8, 2025 26/68
Regular Expression
Arden’s Theorem
Arden’s Theorem
2-way DFA
2-way DFA allows the read head to move left or right on the
input
Two end-markers
Needs only 1 accept or reject state.
A tuple M = {Q, Σ, ⊢, ⊣, δ, s, t, r }
where Q is the set of states
Σ is the input alphabet set
⊢ is the left end marker
⊣ is the right end marker
δ is Q × (Σ ∪ {⊢, λ}) → Q × {L, R}
s is start state
t is the accept state
r is reject state such that r ̸= t
2-Way DFA
Determine the acceptability of 101001 for the following:
State/ Σ 0 1
→ q0 (q0 ,R) (q1 , R)
q1 (q1 ,R) (q2 , L)
q2 (q0 ,R) (q2 , L)
where Q={q0 , q1 , q2 }, s=q0 , t=q1 , r=q2
State/Σ 0 1
q0 q0 , q3 q0 , q4
q3 qf
q4 qf
qf qf qf
Example:
Initial state q0 is marked with an arrow. The table defines δ and λ:
Determine transition states and output string for input string 0111.
Example:
Initial state q0 is marked with an arrow. The table defines δ and λ:
Determine transition states and output string for input string 0111.
Solution: Transition states:
0\0 1\0 1\0 1\1
q0 −−→ q3 −−→ q0 −−→ q1 −−→ q2 0
OutputString: 00010
Example:
Consider a mealy machine for q1 as initial state.
Determine the transition of states and corresponding output string for input string
0011.
Example:
Consider a mealy machine for q1 as initial state.
Determine the transition of states and corresponding output string for input string
0011.
0\0 0\1 1\0 1\0
Solution: q1 −−→ q3 −−→ q2 −−→ q4 −−→ q3
Output String: 0100
q20 q40
q2 q4
q21 q41
Solution:
q20 q40
q2 q4
q21 q41
Solution:
Present a=0 a=1
State State Output State Output
→ q1
q20
q21
q3
q40
q41
Department of Computer Science and Engineering RE December 8, 2025 53/68
Finite Automata with Output
q20 q40
q2 q4
q21 q41
Solution:
Present a=0 a=1
State State Output State Output
→ q1
q20 q40
q2 q4
q21 q41
Solution:
Present a=0 a=1
State State Output State Output
→ q1 q3
q20 q40
q2 q4
q21 q41
Solution:
Present a=0 a=1
State State Output State Output
→ q1 q3 0
q20 q40
q2 q4
q21 q41
Solution:
Present a=0 a=1
State State Output State Output
→ q1 q3 0 q20
q20 q40
q2 q4
q21 q41
Solution:
Present a=0 a=1
State State Output State Output
→ q1 q3 0 q20 0
q20
q20 q40
q2 q4
q21 q41
Solution:
Present a=0 a=1
State State Output State Output
→ q1 q3 0 q20 0
q20 q1
q20 q40
q2 q4
q21 q41
Solution:
Present a=0 a=1
State State Output State Output
→ q1 q3 0 q20 0
q20 q1 1
q20 q40
q2 q4
q21 q41
Solution:
Present a=0 a=1
State State Output State Output
→ q1 q3 0 q20 0
q20 q1 1 q40
q20 q40
q2 q4
q21 q41
Solution:
Present a=0 a=1
State State Output State Output
→ q1 q3 0 q20 0
q20 q1 1 q40 0
q21
q20 q40
q2 q4
q21 q41
Solution:
Present a=0 a=1
State State Output State Output
→ q1 q3 0 q20 0
q20 q1 1 q40 0
q21 q1
q20 q40
q2 q4
q21 q41
Solution:
Present a=0 a=1
State State Output State Output
→ q1 q3 0 q20 0
q20 q1 1 q40 0
q21 q1 1
q20 q40
q2 q4
q21 q41
Solution:
Present a=0 a=1
State State Output State Output
→ q1 q3 0 q20 0
q20 q1 1 q40 0
q21 q1 1 q40
q20 q40
q2 q4
q21 q41
Solution:
Present a=0 a=1
State State Output State Output
→ q1 q3 0 q20 0
q20 q1 1 q40 0
q21 q1 1 q40 0
q3
q20 q40
q2 q4
q21 q41
Solution:
Present a=0 a=1
State State Output State Output
→ q1 q3 0 q20 0
q20 q1 1 q40 0
q21 q1 1 q40 0
q3 q21
q20 q40
q2 q4
q21 q41
Solution:
Present a=0 a=1
State State Output State Output
→ q1 q3 0 q20 0
q20 q1 1 q40 0
q21 q1 1 q40 0
q3 q21 1
q20 q40
q2 q4
q21 q41
Solution:
Present a=0 a=1
State State Output State Output
→ q1 q3 0 q20 0
q20 q1 1 q40 0
q21 q1 1 q40 0
q3 q21 1 q1
q20 q40
q2 q4
q21 q41
Solution:
Present a=0 a=1
State State Output State Output
→ q1 q3 0 q20 0
q20 q1 1 q40 0
q21 q1 1 q40 0
q3 q21 1 q1 1
q40
q20 q40
q2 q4
q21 q41
Solution:
Present a=0 a=1
State State Output State Output
→ q1 q3 0 q20 0
q20 q1 1 q40 0
q21 q1 1 q40 0
q3 q21 1 q1 1
q40 q41
q20 q40
q2 q4
q21 q41
Solution:
Present a=0 a=1
State State Output State Output
→ q1 q3 0 q20 0
q20 q1 1 q40 0
q21 q1 1 q40 0
q3 q21 1 q1 1
q40 q41 1
q20 q40
q2 q4
q21 q41
Solution:
Present a=0 a=1
State State Output State Output
→ q1 q3 0 q20 0
q20 q1 1 q40 0
q21 q1 1 q40 0
q3 q21 1 q1 1
q40 q41 1 q3
q20 q40
q2 q4
q21 q41
Solution:
Present a=0 a=1
State State Output State Output
→ q1 q3 0 q20 0
q20 q1 1 q40 0
q21 q1 1 q40 0
q3 q21 1 q1 1
q40 q41 1 q3 0
q41
Department of Computer Science and Engineering RE December 8, 2025 54/68
Finite Automata with Output
q20 q40
q2 q4
q21 q41
Solution:
Present a=0 a=1
State State Output State Output
→ q1 q3 0 q20 0
q20 q1 1 q40 0
q21 q1 1 q40 0
q3 q21 1 q1 1
q40 q41 1 q3 0
q41 q41
Department of Computer Science and Engineering RE December 8, 2025 54/68
Finite Automata with Output
q20 q40
q2 q4
q21 q41
Solution:
Present a=0 a=1
State State Output State Output
→ q1 q3 0 q20 0
q20 q1 1 q40 0
q21 q1 1 q40 0
q3 q21 1 q1 1
q40 q41 1 q3 0
q41 q41 1
Department of Computer Science and Engineering RE December 8, 2025 54/68
Finite Automata with Output
q20 q40
q2 q4
q21 q41
Solution:
Present a=0 a=1
State State Output State Output
→ q1 q3 0 q20 0
q20 q1 1 q40 0
q21 q1 1 q40 0
q3 q21 1 q1 1
q40 q41 1 q3 0
q41 q41 1 q3
Department of Computer Science and Engineering RE December 8, 2025 54/68
Finite Automata with Output
q20 q40
q2 q4
q21 q41
Solution:
Present a=0 a=1
State State Output State Output
→ q1 q3 0 q20 0
q20 q1 1 q40 0
q21 q1 1 q40 0
q3 q21 1 q1 1
q40 q41 1 q3 0
q41 q41 1 q3 0
Department of Computer Science and Engineering RE December 8, 2025 54/68
Finite Automata with Output
q20 q40
q2 q4
q21 q41
Solution:
Present a=0 a=1 Output
q1 q3 q20
q20 q1 q40
q21 q1 q40
q3 q21 q1
q40 q41 q3
q41 q41 q3
q20 q40
q2 q4
q21 q41
Solution:
Present a=0 a=1 Output
q1 q3 q20 1
q20 q1 q40
q21 q1 q40
q3 q21 q1
q40 q41 q3
q41 q41 q3
q20 q40
q2 q4
q21 q41
Solution:
Present a=0 a=1 Output
q1 q3 q20 1
q20 q1 q40 0
q21 q1 q40
q3 q21 q1
q40 q41 q3
q41 q41 q3
q20 q40
q2 q4
q21 q41
Solution:
Present a=0 a=1 Output
q1 q3 q20 1
q20 q1 q40 0
q21 q1 q40 1
q3 q21 q1
q40 q41 q3
q41 q41 q3
q20 q40
q2 q4
q21 q41
Solution:
Present a=0 a=1 Output
q1 q3 q20 1
q20 q1 q40 0
q21 q1 q40 1
q3 q21 q1 0
q40 q41 q3
q41 q41 q3
q20 q40
q2 q4
q21 q41
Solution:
Present a=0 a=1 Output
q1 q3 q20 1
q20 q1 q40 0
q21 q1 q40 1
q3 q21 q1 0
q40 q41 q3 0
q41 q41 q3
q20 q40
q2 q4
q21 q41
Solution:
Present a=0 a=1 Output
q1 q3 q20 1
q20 q1 q40 0
q21 q1 q40 1
q3 q21 q1 0
q40 q41 q3 0
q41 q41 q3 1
q20 q40
q2 q4
q21 q41
Solution:
Present a=0 a=1 Output
→ q0 q3 q20 0
q1 q3 q20 1
q20 q1 q40 0
q21 q1 q40 1
q3 q21 q1 0
q40 q41 q3 0
q41 q41 q3 1
Department of Computer Science and Engineering RE December 8, 2025 62/68
Finite Automata with Output
q21 q31
q2 q3
q22 q32