0% found this document useful (0 votes)
466 views

Unit-2 Regular Expression and Languages

Here are the steps to design the DFA for the given regular expression 0+10*+01*0: 1. The NFA will have the following states: q0 (initial state), q1, q2, q3, q4, q5 (final state) 2. The transitions are: q0 - 0-> q1, 1-> q2 q1 - 0-> q3, 1-> q4 q2 - 0-> q5 q3 - 0-> q3, 1-> q4 q4 - 0-> q3, 1-> q4 q5 - ε 3. Eliminating ε transitions: No ε transitions.

Uploaded by

57- Mansi Raut
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
466 views

Unit-2 Regular Expression and Languages

Here are the steps to design the DFA for the given regular expression 0+10*+01*0: 1. The NFA will have the following states: q0 (initial state), q1, q2, q3, q4, q5 (final state) 2. The transitions are: q0 - 0-> q1, 1-> q2 q1 - 0-> q3, 1-> q4 q2 - 0-> q5 q3 - 0-> q3, 1-> q4 q4 - 0-> q3, 1-> q4 q5 - ε 3. Eliminating ε transitions: No ε transitions.

Uploaded by

57- Mansi Raut
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 42

Unit-2 Regular Expression and

Languages
Regular Expression
Definition:
• The language accepted by finite automata can be easily described by
simple expressions called Regular Expressions.
• It is the most effective way to represent any language.
• The languages accepted by some regular expression are referred to as
Regular languages.
• A regular expression can also be described as a sequence of pattern that
defines a string.
• Regular expressions are used to match character combinations in strings.
String searching algorithm used this pattern to find the operations on a
string.
For instance:
• In a regular expression, x* means zero or more occurrence of x. It can
generate {e, x, xx, xxx, xxxx, .....}
• In a regular expression, x+ means one or more occurrence of x. It can
generate {x, xx, xxx, xxxx, .....}
Example 1
• Write the regular expression for the language accepting all
combinations of a's, over the set ∑ = {a}

Solution:
• All combinations of a's means a may be zero, single, double
and so on.
• If a is appearing zero times, that means a null string. That is we
expect the set of {ε, a, aa, aaa, ....}.
• So we give a regular expression for this as:
• R = a*  
• That is Kleen closure of a.
Example 2
• Write the regular expression for the language accepting all
combinations of a's except the null string, over the set ∑ = {a}

Solution:
• The regular expression has to be built for the language
• L = {a, aa, aaa, ....}  
• This set indicates that there is no null string. So we can denote
regular expression as:
• R = a+
Example 3
• Write the regular expression for the language accepting all the
string containing any number of a's and b's.

Solution:

• The regular expression has to be built for the language


• L = {ε, a, aa, b, bb, ab, ba, aba, bab, .....}, any combination of a
and b.
• The regular expression will be:
• r.e. = (a + b)* 
• The (a + b)* shows any combination with a and b even a null
string.
Regular Expression and Power, Concatenation and Union
Regular Expression
Regular Expression
Examples of Regular Expression

Example 1
• Write the regular expression for the language accepting all the string which are starting
with 1 and ending with 0, over ∑ = {0, 1}.

Solution:
• In a regular expression, the first symbol should be 1, and the last symbol should be 0. The
r.e. is as follows:
 
R = 1 (0+1)* 0  
Example 2
• Write the regular expression for the language starting and
ending with a and having any having any combination of b's in
between.

Solution:
• The regular expression will be:
• R = a b b* a
• L+ = L.L*
Example 3
• Write the regular expression for the language starting with a
but not having consecutive b's.

Solution: 
• The regular expression has to be built for the language:
• L = {a, aba, aab, aba, aaa, abab, .....}  
• The regular expression for the above language is:
• R = (a + ab)*  
Example 4
• Write the regular expression for the language accepting
all the string in which any number of a's is followed by
any number of b's is followed by any number of c's.

Solution:
•  As we know, any number of a's means a* any number of
b's means b*, any number of c's means c*.
• Since as given in problem statement, b's appear after a's
and c's appear after b's.
• So the regular expression could be:
• R = a* b* c*  
Example 5
• Write the regular expression for the language over ∑ = {0}
having even length of the string.

Solution:
• The regular expression has to be built for the language:
• L = {ε, 00, 0000, 000000, ......}  
• The regular expression for the above language is:
• R = (00)*  
Example 6
• Write the regular expression for the language having a string
which should have at least one 0 and at least one 1.

Solution:
• The regular expression has to be built for the language
• L = {01,10,101,100,011,010,0110,…}
• The regular expression will be:
• R = [(0 + 1)* 0 (0 + 1)* 1 (0 + 1)*] + [(0 + 1)* 1 (0 + 1)* 0 (0 + 1)*
]  
Example 7
• Describe the language denoted by following regular
expression
• r.e. = (b* (aaa)* b*)*  

Solution:
• The language can be predicted from the regular expression
by finding the meaning of it. We will first split the regular
expression as:
• r.e. = (any combination of b's) (aaa)* (any combination of
b's)
• L = {The language consists of the string in which a's appear
triples, there is no restriction on the number of b's}
Example 9
• Write the regular expression for the language containing the
string over {0, 1} in which there are at least two occurrences of
1's between any two occurrences of 0's.

Solution: 
• At least two 1's between two occurrences of 0's can be
denoted by (0111*0)*.
• Similarly, if there is no occurrence of 0's, then any number of
1's are also allowed. Hence the r.e. for required language is:
• R = (1 + (0111*0))*  
Example 11

Find the R.E. corresponding to each of following subsets of


{0,1}*
1) The language of all strings containing exactly two 0’s.
2) the language of all strings that do not end with 01.
3) The language of all strings starting with 11.

Solution:
R.E. = 1*01*01*
R.E.= (1+0)*(00+11+10)
R.E.=11(0+1)*
Conversion of RE to FA

• To convert the RE to FA, we are going to use a method called the subset method.
This method is used to obtain FA from the given regular expression. This method
is given below:

• Step 1: Design a transition diagram for given regular expression, using NFA with ε
moves.
• Step 2: Convert this NFA with ε to NFA without ε.
• Step 3: Convert the obtained NFA to equivalent DFA.
Regular Expressions for Basic Automata
Regular Expressions for basic automata
Regular Expressions for basic automata
Example 1
Design a DFA from given regular expression 10 + (0 + 11)0* 1.
Solution: 
• First we will construct the transition diagram for a given regular expression
Step 1:

Step 2:
Example 2
Design a DFA from given regular expression 10 + (0 + 11)0* 1

Step 3:

Step 4:
Example 3
Design a DFA from given regular expression 10 + (0 + 11)0* 1.

Step 5:

Now we have got NFA without ε. Now we will convert it into required DFA for
that, we will first write a transition table for this NFA.
State 0 1

→q0 q3 {q1, q2}

q1 qf ϕ

q2 ϕ q3

q3 q3 qf

*qf ϕ ϕ
Example 4
Design a DFA from given regular expression 10 + (0 + 11)0* 1.

A transition table for this NFA The equivalent DFA will be:

State 0 1 State 0 1

→q0 q3 {q1, q2} →[q0] [q3] [q1, q2]

q1 qf ϕ [q1] [qf] ϕ

[q2] ϕ [q3]
q2 ϕ q3
[q3] [q3] [qf]
q3 q3 qf
[q1, q2] [qf] [qf]
*qf ϕ ϕ
*[qf] ϕ ϕ
Example 5
Design a NFA from given regular expression 1 (1* 01* 01*)*.

Solution: 
The NFA for the given regular expression is as follows:
Step 1:

Step 2:

Step 3:
Example 6
Construct the DFA for regular expression 0*1 + 10.
Solution:
• We will first construct FA for R = 0*1 + 10 as follows:
Step 1:

Step 2:
Example 7
Construct the DFA for regular expression 0*1 + 10

Step 3:

Step 4:
Example 8
Construct the FA for regular expression (1+10+110)*0
Example 9
Construct the FA for regular expression (010+00)*(10)
Example 10
Construct the FA for regular expression (010+00)*(10)
Example 11
Construct the DFA for regular expression (111+100)*0
NFA

Resulting DFA

Transition Table for NFA to DFA Conversion

State\input 0 1

q0 q5 {q1 ,q3}

{q1 ,q3} q4 q2

q2 Ø q0
Transition Diagram
q4 q0 Ø

q5* Ø Ø
Example 12
Design DFA for R.E. (11+00)*
Example 13
Design DFA for R.E. (11+00)*
Example 14
Design FA for R.E. 10+(0+11)0*1
Example 15
Design FA for R.E. 10+(0+11)0*1
Example 16
Design FA for R.E. 10+(0+11)0*1
Example 17
Design FA for R.E. 0+10*+01*0
Example 18
Design FA for R.E. 0+10*+01*0

You might also like