Professional Documents
Culture Documents
Kca 201 Unit 2 1 Unit 1 Notes
Kca 201 Unit 2 1 Unit 1 Notes
Kca 201 Unit 2 1 Unit 1 Notes
Regular Expression:
Regular expressions are used for representing certain sets of strings(language)in an algebraic
fashion.
1. Any terminal symbols (i.e. an element of ∑), ∈ and Φ are regular expressions (Primitive
regular expressions)
Example 2:
Write the regular expression for the language accepting all the string which are starting with 1 and
ending with 0, over ∑ = {0, 1}.
Solution:
R = 1 (0+1)* 0
Page|2
The two regular expressions P and Q are equivalent (denoted as P=Q) if and only if P represents
the same set of strings as Q does. For showing this equivalence of regular expressions we need to
show some identities of regular expressions.
Let P, Q and R are regular expressions then the identity rules are as given below.
Page|3
Example 01:
Find the regular expression for the set of all strings over {0, 1} beginning with 00.
Solution:
We have the input alphabets are ∑ = {0, 1}
L= {00, 001, 0001, 0011,……}
R.E= 00(0+1)*
Example 02:
Find the regular expression for the set of all strings over {0, 1} end with 00.
Solution:
We have the input alphabets are ∑ = {0, 1}
L = {00, 100, 1000, 10100,……}
R.E = (0+1)*00
Example 03:
Write a R.E for the Language over {0, 1} which are staring with 1 ending with 0.
Solution:
We have the input alphabets are ∑ = {0, 1}
The first symbol is 1
Last symbol is 0
So R. E = 1(0+1)*0
Page|4
Page|5
Solution:
Step 1: the transition diagram for a given regular expression.
Step 2:
Step3:
Step 4:
Page|6
Step 5:
The two popular methods for converting a given DFA to its regular expression are-
Arden’s Theorem-
Arden’s Theorem is used to convert a given DFA to its regular expression.
Let P and Q be the two regular expressions over the input set ∑. The regular expression R is given
as
R= Q+ RP
Rules:
1. Add ‘∈’ in the equation of initial state.
2. Incoming are used.
3. First solve non- final.
4. Finally solve final state.
5. Bring final state in the form R = Q + RP to get the required regular expression.
Page|7
Problem-01: Find regular expression for the following DFA using Arden’s Theorem.
Solution-
Step-01: Form a equation for each state-
A = ∈ + B.1 …… (1)
B = A.0 …… (2)
Step-02: Bring final state in the form R = Q + RP.
Problem-02:
Find regular expression for the following DFA using Arden’s Theorem-
Solution-
Step-01: Form a equation for each state-
Page|8
q1 = ∈ ……(1)
q2 = q1.a ……(2)
q3 = q1.b + q2.a + q3.a …….(3)
Step-02:
Using (1) in (2), we get-
q2 = ∈.a
q2 = a …….(4)
Using (1) and (4) in (3), we get-
q3 = q1.b + q2.a + q3.a
q3 = ∈.b + a.a + q3.a
q3 = (b + a.a) + q3.a …….(5)
Using Arden’s Theorem in (5), we get-
q3 = (b + a.a)a*
Thus, Regular Expression for the given DFA = (b + aa) a*
Problem-03:
Find regular expression for the following DFA using Arden’s Theorem-
Solution-
Page|9
Problem-04:
Find regular expression for the following FA using Arden’s Theorem-
Solution-
Step-01: Form a equation for each state-
q1 = ∈ + q1.a + q3.a ……(1)
q2 = q1.b + q2.b + q3.b ……(2)
q3 = q2.a …….(3)
P a g e | 10
Problem-05:
Find regular expression for the following FA using Arden’s Theorem-
Solution:
A = ε + Aa + Ba ................. (1)
B = Bb + Ab… ................... (2)
Which one is final state?
First solve non-final state
Using Arden’s theorem in equation (2)
B = Abb*
Now, Put value of B in equation (1)
So that,
A = ε + Aa + Abb*a
A = ε + A (a + bb*a)
Using Arden’s theorem
A = ε (a + bb*a)*
Ans
P a g e | 11
Problem-:
Solution:
Here initial state and final state is q1
q1 = q1a + q3a + ε
q2 = q1b + q2b + q3b
q3 = q2 a
Now, we will solve these three equations
q2 = q1b + q2b + q3b
= q1b + q2b + (q2 a) b [substituting value of q3]
= q1b + q2 (b + a b)
Appling Arde’s Theorem
q2 = q1b (b + a b)*
Now,
q1 = q1a + q3a + ε
P a g e | 12
This method involves the following steps in finding the regular expression for any given DFA
Step-01:
If there exists any incoming edge to the initial state, then create a new initial state having no
incoming edge to it.
Example
Step-02:
If there exists any outgoing edge from the final state, then create a new final state having no
outgoing edge from it.
Example
P a g e | 13
Step-03:
If there exists multiple final states in the DFA, then convert all the final states into non-final states
and create a new single final state.
Example-
Step-04:
Eliminate all the intermediate states one by one except initial states and final state. eliminated in
any order.
Solution-
Step-01: Initial state A has an incoming edge.
Step-03:
P a g e | 14
Step-04:
Now, let us eliminate state B.
Step-02:
Now, we start eliminating the intermediate states
P a g e | 15
Problem-03:
Find regular expression for the following FA
Solution-
Step-01: Initial state q1 has an incoming edge
Step-02:
Final state q2 has an outgoing edge
Step-03:
P a g e | 16
From here,
Problem 01:
Prove that L = {aibi | i ≥ 0} is not regular.
Solution:
L= {∈, ab, aabb, aaabbb, aaaaabbbbb,… ............ }
Step 01: Assume L is a regular, then we can make its FA. Suppose FA has n states.
Step 02: Take a string w =anbn
Step 03: Divide w= xyz, |w|≥n such that
P a g e | 17
Let n=4
Then w= aaaabbbb (X= a, y= aaa, z= bbbb)
Case 01:|xy|≤n
4≤ 4 true
Case 02:|y| > 0
3>0 true
Case 03:xyiz ∈ L, for each i≥0
aaaaaaabbbb ∉ L , i = 2
Thus, contradicts our assumption. Hence L is not regular
Problem 02:
Prove that L = {aibj | i ≤j} is not regular.
Solution:
L= {aabb, aabbb, aaabbbb,… ........... }
Step 01:Assume that L is a regular. then we can make its FA. Suppose FA has n states.
Step 02:Take a string w = anbn+1
Step 03: Divide w= xyz, |w|≥n such that
Let n = 2, then w = aabbb (X= a, y= a, z= bb)
Case 01:|xy| ≤ n
2≤ 2 true
Case 02: |y| > 0
1> 0 true
Case 03: xyiz∈L, for each i≥0
aaabbb ∈ L , i = 2
aaaabbb ∉ L, i = 3
Thus, contradicts our assumption. Hence L is not regular
P a g e | 18
Problem 03:
Prove that L = {ap | p is prime} is not regular.
Solution:
L= {a2, a3, a5, a7, a11 ............... }
Step 01: Assume that L is a regular, then we can make its FA. Suppose FA has n states.
Step 02: Take a string w = an
Step 03: Choose a string w= xyz, |w|≥n such that
Let n = 5,
then w = aaaaa(X= a, y= aa, z= aa)
Case 01:|xy| ≤ n
3≤ 5 true
Case 02: |y| > 0
2> 0 true
Case 03:xyiz∈L, for each i≥0
aaaaaaa∈L , i = 2
aaaaaaaaa∉ L , i = 3
Thus, contradicts our assumption. Hence L is not regular
Problem 04:
Prove that L = {ww | w ∈ (0, 1)*} is not regular.
Solution:
L= {∈, 00, 11, 0011, 0101, 1010, 010010 ................}
Step 01: Assume that L is a regular. then we can make its FA. Suppose FA has n states.
Step 02: Take a string S = 0n10n1
Step 03: Choose a string S= xyz, |S|≥n such that
Let n = 3
Then S = 00010001(X= 0, y= 00, z= 10001)
P a g e | 19
Case 01:|xy| ≤ n
3≤ 3 true
Case 02: |y| > 0
2> 0 true
Case 03:xyiz∈L, for each i≥0
00010001∈L, i = 1
0000010001∉ L, i = 2
Thus, contradicts our assumption. Hence L is not regular
Problem 05:
Prove that L={wwR| w ∈{a, b}*} is not regular by using Pumping Lemma.
Or
Show that L ={ wwR : w ∈ Σ*} is not regular by using Pumping Lemma.
Solution:
L= {∈, aa, bb, baab, abba, aabbaa, aaabbaaa ................. }
Step 01: Assume that L is a regular. then we can make its FA. Suppose FA has n states.
Step 02: Take a string S = anb ban
Step 03: Choose a string S= xyz, |S|≥n such that
Let n = 3
Then S =aaabbaaa(X= a, y= aa, z= bbaaa)
Case 01:|xy| ≤ n
3≤ 3 true
P a g e | 20
Problem 06:
Prove that L= {an2|n ≥ 0} is not regular by using Pumping Lemma.
Solution:
L= {∈, a1,a4, a9, a16 ............ }
Step 01: Assume that L is a regular. then we can make its FA. Suppose FA has n states.
Step 02: Take a string w = ap2
Step 03: Choose a string w= xyz, |w|≥n
Let p = 2
Then w =aaaa(X= a, y= a, z= aa)
Case 01:|xy| ≤ n
2≤ 2 true
Case 02: |y| > 0
P a g e | 21
1> 0 true
Case 03:xyiz∈L, for each i≥0
aaaaa ∉ L , i = 2
Thus, contradicts our assumption. Hence L is not regular
P a g e | 22