Chapter 2
Chapter 2
Regular Expressions
Page 1
Regular Expression
• Languages accepted by finite automata are easily described by simple expression is called Regular
Expression.
• Most effective way to represent any language.
• ε is a Regular Expression indicates the language containing an empty string.
(L (ε) = {ε})
• φ is a Regular Expression denoting an empty language. (L (φ) = { })
• x is a Regular Expression where L = {x}
• If X is a Regular Expression denoting the language L(X) and Y is a Regular Expression denoting
the language L(Y), then
– X + Y is a Regular Expression corresponding to the language
L(X) ∪ L(Y) where L(X+Y) = L(X) ∪ L(Y).
– X.Y is a Regular Expression corresponding to the language
L(X) . L(Y) where L(X.Y) = L(X) . L(Y)
– R* is a Regular Expression corresponding to the language L(R*)
where L(R*) = (L(R))* Page 2
Application of RE
1. Effective representation of language
2. Text editor
3. Lexical Analyzer
Page 3
• Some RE Examples
Page 4
•
Page 5
Example 3.3: Construct the RE for language accepting all the stings
which are having any number of a’s is followed by any number b’s is
followed by any number of c’s over the input set ∑ = {a, b, c}
R = (any number of a) (any number of b) (any number of c)
R = a* b* c*
Example 3.4: write a RE to denote the language L over ∑ ={a, b}
such that all the strings do not contain the substring ab
L = {ε, a, b, bb, ba, baa, …..}
R = b* a*
Page 6
Quiz 5%
1. Languages accepted by finite automata are easily described by simple expression is
called_____________________________. 0.5 Mark
2. Write Regular Expression(RE) for all the strings containing any number of a’s and
b’s? 1 Mark
3. Construct the RE for language accepting all the stings which are ending with 00 over
the input set ∑ = {0, 1} ? 1 Mark
4. If L = {starting and ending with ‘a’ and having any combination of b’s in between }
what is RE? and draw its NDFA? 1 Mark
5. Write a RE to denote the language L over ∑ ={a, b} such that all the strings do not
contain the substring ab? 1.5
L =?
R =?
Answer.pptx Page 7
Regular Sets
• Any set that represents the value of the Regular Expression is called
a Regular Set.
Properties of Regular Sets
Page 11
• Case 3 − For a regular expression (a+b), we can construct the
following FA −
Page 12
Method to construct DFA from Null Transition in NDFA
• Step 1 Construct an NFA with Null moves from the given regular
expression.
• Step 2 Remove Null transition from the NFA and convert it into
its equivalent DFA.
Problem
• Convert the following RE into its equivalent DFA − 1 (0 + 1)* 0
Solution:- We will concatenate three expressions "1", "(0 + 1)*" and
"0“
Page 15
Example: Construct RE from the given DFA
Page 16
Page 17
Example : Construct the RE for the given DFA
Page 18
Page 19
Try Yourself
Page 20
Non Regular language
Page 21
Pumping Lemma
Theorem:
Let L be the regular set, then there is a constant n such that if z is any word in L,
and |z|>n, we may write z = uvw in such that |uv| ≤ n, |v| = 1 and for all i ≥ 0
uviw in L. furthermore n is should not grater than the number of states of DFA.
z = uviw i > 0
Page 22
Applications of Pumping Lemma
• Pumping Lemma is to be applied to show that certain languages are not regular.
• It should never be used to show a language is regular.
• If L is regular, it satisfies Pumping Lemma.
• If L does not satisfy Pumping Lemma, it is non-regular.
• Method to prove that a language L is not regular
• At first, we have to assume that L is regular.
• So, the pumping lemma should hold for L.
• Use the pumping lemma to obtain a contradiction −
– Select w such that |w| ≥ c
Page 24
d !
En