Professional Documents
Culture Documents
1
Index
Lecture 7 – Regular Language and Expression : Definition 3
2
Lecture 7
Lecture No 7:
Regular Language and Regular
Expression (RE): Definition
Regular Expression (RE)
• The language accepted by finite automata can be described by
simple expressions called Regular Expressions.
3.∅ . R = R . ∅ = ∅
4.ε* = ε and ∅* = ε
5.R + R = R (Idempotent law)
6.RR* = R*R
7.R*R* = R*
Lecture 7 – Regular Language and
7
Expression : Definition
Identities Related to Regular Expressions(cont..)
8. (R*)* = R*
9. (PQ)*P =P(QP)*
10. L (M + N) = LM + LN (Left distributive law)
11. (M + N) L = ML + NL (Right distributive law)
12. ε + RR* = ε + R*R = R*
13. (P + Q)* = (P*Q*)* = (P*+Q*)*
L(r) = {1}
r =1 State
Current Current input
r =0 L(r) = {0}
r = a. (a + b) L(r) = { aa , ab }
r = (aa)* L( r ) = {ԑ, aa, aaaa, aaaaaa, .......}
Lecture No 8:
Equivalence of RE and ε-NFA
Regular Expression to Finite Automata
• We can obtain equivalent DFA for given Regular expression .
• Flow is as shown below :
Regular
Expressi
on
NFA with
Є moves DFA
NFA
without
Є moves
a
s ff
Lecture 8: Equivalence of RE and ε-
18
NFA
RE to NFA with ԑ moves Conversion(cont..)
⮚ Step 2 :
Let R1 and R2 are two regular expressions having Start and Final States as S1,
F1 and S2, F2 respectively.
R1 R2
S1 F1 S2 F2
2.1 🡪 R1.R2 (Concatenation/ Series) :
R1 Є R2
S1 F1 S2 F2
OR
R1 R2
S1 F1 F2
Lecture 8: Equivalence of RE and ε-
19
NFA
RE to NFA with ԑ moves Conversion(cont..)
2.2 R1 + R2 ( Parallel ) :
R1
Step 1: S1 F1
R2
S2 F2
Step 2:
R1
Є S1 F1 Є
S3 F3
R2
Є S2 F2 Є
Lecture 8: Equivalence of RE and ε-
20
NFA
RE to NFA with ԑ moves Conversion(cont..)
2.3 R1* (Closure) :
Step 1:
R1
S1 F1
Zero
Step 2: Occurrence
Є
R1 F
S S1 F1
Є Є Є
Single More than
Occurrenc one
e Occurrence
Lecture 8: Equivalence of RE and ε-
21
NFA
RE to NFA with ԑ moves Conversion(cont..)
Step 2:
R1 F
S S1 F1
Є Є
Single Є More than
Occurrenc one
e Occurrence
Lecture 8: Equivalence of RE and ε-
22
NFA
Example 1:
Q. Draw NFA with Є-moves for the RE a. (a + b). b.
Step 1: Draw (a + b)
a
Є Є
b
Є Є
Lecture
Lecture 8:
16:Equivalence
EquivalenceofofRE
REand
andε-ε-NFA
23
NFA
Example 1: (cont..)
Step 2: Concatenate ‘a’ and (a + b)
a
Є Є
a
Є b
Є
Step 3: Concatenate a.(a + b) with b.
a
Є 3 4 Є
1 2 7 8
a b
Є b
5 6 Є
Lecture 8: Equivalence of RE and ε-
24
NFA
Example 2:
Q. Draw NFA with Є-moves for the RE a. (a + b)*.
Step 1: Draw (a + b)
a
Є Є
b
Є Є
a
Є Є
Є Є
Є b
Є
a
Є 4 5 Є
1 2 3 8 9
a Є b Є
Є 6 7 Є
Є
Є
a* 🡪
Є a Є
Є
b* Є
🡪
Є b Є
28
Lecture
Lecture 8:
16:Equivalence
EquivalenceofofRE
REand
andε-ε-NFA Є
NFA
Example 3: (cont..)
Step 2: Draw (a*+b*) i.e. parallel path
Є
Є a Є 5
2 3 4
Є Є Є
1 10
Є
Є Є
Є b Є
6 7 8 9
Є
Lecture 8: Equivalence of RE and ε-
29
NFA
Example 4:
Q. Draw NFA with Є-moves for the RE 1(011)*0.
Step 1: Draw NFA for 011.
0 1 1
Є
Lecture 8: Equivalence of RE and ε-
30
NFA
Example 4: (cont..)
Step 3: Finally draw NFA for 1.(011)*. 0
Є
Є 0 1 1 6 Є 7
1 2 3 4 5 8
1 0
Є
1
Є Є
Є
Є Є
1
Є Є
Є Є Є
Є Є
Є
Step 3: Draw NFA for 00.
0 0
Lecture
Lecture 8:
17:Equivalence
Equivalenceof
ofRE
REand
andε-ε-NFA
33
NFA
Example 5: (cont..)
Step 4: Draw parallel path for (1 + Є)* + 00.
Є
Є 4 1 5 Є
Є 2 3 8 9
Є Є Є Є
Є 6 7 Є
1 13
Є
Є Є
0 0
10 11 12
Lecture 9:
Equivalence of RE to DFA
Conversion: Indirect Method
NFA with ε- Transitions
• ε-closure of a state
– ε-closure of state ‘q’ is set of states ‘p’ such that
there is a path “from q to p” labelled ‘ε’ directly
or indirectly.
– It is a set of states with distance zero from state
‘q’.
– The state itself is included in its ε-closure.
ε ε
• ε-closure of A={A, B, C}
• ε-closure of B={B, C}
• ε-closure of C={C}
Note: The states which includes final state of ε-NFA in its ε-closure will
be considered as Final state in converted NFA.
A A,B,C 0 A, C A,B,C
A A,B,C B B,C 0 C C
C C C C 0 C C
C C 1 C C
Converted NFA
Converted DFA
State 0 1 State 0 1
C* C C B,C* C B,C
C* C C
Converted DFA
State 0 1
->A* A B,C
B,C* C B,C
C* C C
1 1 5 5
2 2,3,7 6 6, 7, 3
3 3 7 7
4 4 8 8
Lecture 9: Equivalence of RE to DFA
43
Conversion: Indirect Method
Example 2 continued..
NFA
DFA
State 0 1 State 0 1
->1 - 2.3.7
-->1 - 2,3,7
2 4,8 -
2,3,7 4,8 -
3 4 -
4,8* - 5
4 - 5
5 - 6,7,3
5 - 6,7,3
6,7,3 4,8 -
6 4,8 -
7 8 -
8* - -
Lecture 9: Equivalence of RE to DFA
48
Conversion: Indirect Method
Example 2 continued..
Minimized DFA
State 0 1
State 0 1
-->1 - 2,3,7
-->1 - 2,3,7
2,3,7 4,8 -
2,3,7 4,8 -
4,8* - 5
4,8* - 5
5 - 6,7,3
5 - 2,3,7
6,7,3 4,8 -
Minimized DFA
State 0 1
-->1 - 2,3,7
2,3,7 4,8 -
4,8* - 1
53 Practice Problems
Regular Expression Examples(cont..)
4. Describe ( a ( aa )* b ( bb )* )*
🡪String of odd number of consecutive a’s followed by string of odd
number of consecutive b’s.
🡪 It is alternating sequence of odd a’s and odd b’s, starting with a
ending with b.
5. Define the language such that all words that starts with and
ends with different letter over ∑= {x,y}.
🡪 RE= x (x+y)* y + y (x+y)* x
54 Practice Problems
Regular Expression Examples(cont..)
7. Represent the language over ∑= {0, 1} containing all possible
combinations of 0’s and 1’s but not having two consecutive 0’s.
🡪Language containing strings that start with ‘1’ and do not have two
consecutive 0’s is represented by the RE , R1= (1 + 10)*
🡪Similarly the language containing strings that start with 0 and do not
have 2 consecutive 0’s can be represented as, R2= 0.(1 + 10)*.
🡪Combining two RE we get, R= (1 + 10)* + 0.(1 + 10)*
8. Define the language over ∑= {0, 1, 2} such that every string from
the language contains any number of 0’s followed by any number of
1’s followed by any number of 2’s.
🡪 Any number of 0’s means zero or more occurrences of 0’s. It is denoted
by 0*. Similar thing for input 1 and 2 also.
🡪 RE= 0*1*2*
55 Practice Problems
Regular Expression Equivalence
9. Show that (a. b)* ≠ a*.b*.
Solution :
Let R1 = (a. b)* and R2 = a*.b*
L(R1) = { Є, ab, abab, ababab,……} ------- (1)
L(R2) = L(u). L(v) where u = a* and v = b*
= { Є, a, aa, aaa,……}.{ Є, b, bb, bbb,……}
= { Є, a, b, aa, bb, ab, abb, aaa, bbb……} ------- (2)
Comparing equation (1) and (2) we can say,
(a. b)* ≠ a*.b*
56 Practice Problems
Regular Expression Equivalence (cont..)
10. Show that (a + b)* = (a + b)* + (a + b)*
Solution :
Let R1 = (a + b)* and R2 = (a + b)* + (a + b)*
L(R1) = { Є, a, b, aa, ab, bb, ba ….……} ------- (1)
L(R2) = L(u) U L(v) where u = (a + b)* and v = (a + b)*
= { Є, a, b, aa, ab, bb, ba ….……} U { Є, a, b, aa, ab, bb, ba ….……}
= { Є, a, b, aa, ab, bb, ba ….……} ------- (2)
Comparing equation (1) and (2) we can say,
(a + b)* = (a + b)* + (a + b)*
57 Practice Problems
Regular Expression Equivalence (cont..)
11. Show that (a* b*)* = (a + b)*
Solution :
Let R1 = (a* b*)*
L(R1) = {{ Є, a, aa, aaa, aaaa ….……}.{ Є, b, bb, bbb, bbbb ….……}}*
= { Є, a, b, aa, bb, ….……} *
= { Є, a, b, aa, bb, ab, ba ….……} ------- (1)
Let R2 = (a + b)*
L(R2) = { Є, a, b, aa, ab, bb, ba ….……} ------- (2)
Comparing equation (1) and (2) we can say,
(a* b*)* = (a + b)*
58 Practice Problems
Example 12:
Q. Draw NFA with Є-moves for the RE (11 + 01)*.
Step 1: Draw NFA for RE=11 .
1 1
0 1
59 Practice Problems
Example 12: (cont..)
Step 3: Draw parallel path for 11 and 01 i.e.
(11 + 01).
1 1
Є Є
Є 0 1 Є
60 Practice Problems
Example 12: (cont..)
Step 4: Finally draw repetition for (11+01)
i.e. (11+01)*
Є
3 1 4 1 5
Є Є
1 2 9 10
Є Є
Є 0 1 Є
6 7 8
61 Practice Problems
Thank You