0% found this document useful (0 votes)
8 views32 pages

TOC UNIT Ii.1

The document covers the Theory of Computation, focusing on Regular Expressions and Finite Automata. It explains the syntax and operations of regular expressions, their equivalence to finite automata, and methods for converting NFAs with ε-transitions to those without. Additionally, it provides examples and step-by-step procedures for constructing NFAs from regular expressions and removing ε-transitions.

Uploaded by

Ashish Jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views32 pages

TOC UNIT Ii.1

The document covers the Theory of Computation, focusing on Regular Expressions and Finite Automata. It explains the syntax and operations of regular expressions, their equivalence to finite automata, and methods for converting NFAs with ε-transitions to those without. Additionally, it provides examples and step-by-step procedures for constructing NFAs from regular expressions and removing ε-transitions.

Uploaded by

Ashish Jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 32

CSE251 IV SEMESTER 202-25 TERM II

THEORY OF COMPUTATION

UNIT-II
REGULAR EXPRESSION AND FINITE AUTOMATA
Regular Expression,Finite automata with null move,Regular Expression to finite
automata
Arden Theorem,Pumping lemma for regular Expressions
FA with output: moore machine,melay machine with Euivalence.

REGULAR EXPRESSION

A Regular Expression (regex or regexp) is a formal language notation used to define


patterns in strings. Regular expressions are widely used in computer science for tasks
like pattern matching, text searching, and defining regular languages. They are
directly equivalent to finite automata, which makes them a key concept in automata
theory.

Syntax of Regular Expressions

The syntax of regular expressions defines how patterns are expressed. Below are the
main components:

1. Alphabet Symbols: Individual characters from the input alphabet (e.g., ‘a’, ‘b’,
‘0’, ‘1’).
2. Concatenation: Writing two expressions next to each other signifies their
sequence. For example, ab matches “a” followed by “b”.
3. Union: Represented by the pipe symbol |. For example, a|b matches either “a” or
“b”.
4. Kleene Star: Represented by *, it denotes zero or more repetitions of a pattern.
For example, a* matches “”, “a”, “aa”, and so on.
5. Parentheses: Used to group expressions for clarity and precedence. For
example, (a|b)c matches “ac” or “bc”.

Operations on Regular Expressions

Regular expressions support three fundamental operations:

1. Union: Combines two patterns such that either can match. For example, a|
b matches “a” or “b”.
2. Concatenation: Matches sequences of patterns. For example, ab matches “a”
followed by “b”.
3. Kleene Star: Allows repetition of a pattern. For example, a* matches “”, “a”,
“aa”, “aaa”, and so on.
These operations form the basis for defining all regular languages, making regular
expressions a powerful tool for describing patterns.

Equivalence with Finite Automata

Regular expressions and finite automata are equivalent in their expressive power. This
means that for every regular expression, there exists a finite automaton (DFA or NFA)
that recognizes the same language, and vice versa.

The equivalence is established through the following:

 From Regular Expression to NFA: Using a method called Thompson’s


construction, an NFA can be constructed for any given regular expression.
 From NFA to DFA: Using the subset construction method, an NFA can be
converted to an equivalent DFA.
 From DFA to Regular Expression: Techniques like state elimination can be
used to derive a regular expression from a DFA.

This equivalence highlights the theoretical foundation of regular expressions and their
practical use in defining and recognizing regular languages.

Example: Regular Expression and Equivalent NFA

Let’s construct an NFA for the regular expression (a|b)*ab, which matches any string
of ‘a’s and ‘b’s that ends with “ab”.

The regular expression can be broken into two parts:

 (a|b)*: Matches any sequence of ‘a’s and ‘b’s, including the empty string.
 ab: Ensures that the string ends with the exact sequence “ab”.

We will construct an NFA for this regular expression using Thompson’s construction
method.

Step 1: Construct NFA for Each Component

To construct the NFA, we break the regular expression into its components and build
NFAs for each part:

 For (a|b): Create two parallel transitions from a state, one for ‘a’ and another for
‘b’.
 For (a|b)*: Add a loop to handle repetition, allowing the NFA to return to the
starting state after reading ‘a’ or ‘b’.
 For ab: Add two sequential transitions: one for ‘a’, then another for ‘b’.

Step 2: Combine NFAs

Next, we combine the NFAs for each part:

 Connect the NFA for (a|b)* to the start of the NFA for ab.
 Ensure the final state of the NFA for ab is the accept state for the combined NFA.
 Include ε-transitions where necessary to combine the components seamlessly.

Step 3: Define the NFA

The resulting NFA has the following components:

States (Q): q₀, q₁, q₂

Alphabet (Σ): {a, b}

Start State: q₀

Accept State: q₂

Transition Function (δ):

δ(q₀, 'a') = {q₀, q₁}


δ(q₀, 'b') = {q₀}
δ(q₁, 'b') = {q₂}
δ(q₁, 'a') = {}
δ(q₂, 'a') = {}
δ(q₂, 'b') = {}

Key Transitions:

 q₀: Handles repetition of ‘a’ and ‘b’ for (a|b)*.

 q₁: Transition for the first ‘a’ in “ab”.

 q₂: Accept state reached after “ab”.

State Diagram

State diagram showing all transitions for ‘a’, ‘b’, and ε, with q₀ as the start state and
q₂ as the accept state.
FINITE AUTOMATA WITH NULL MOVE

In this method, we try to remove all the ε-transitions from the given Non-
deterministic finite automata (NFA) −

The method is mentioned below stepwise −

 Step 1 − Find out all the ε-transitions from each state from Q. That will be called as ε-
closure(qi) where, qi ∈Q.
 Step 2 − Then, δ1 transitions can be obtained. The δ1 transitions means an ε-closure
on δ moves.
 Step 3 − Step 2 is repeated for each input symbol and for each state of given NFA.
 Step 4 − By using the resultant status, the transition table for equivalent NFA without
ε can be built.

NFA with ε to without ε is as follows −

Rule for conversion

δ′(q, a) = ε - closure (δ (δ (q, ε), a))

where δ(q,ε) = ε - closure (q)

Before solving some examples based on conversion of NFA with ε to NFA without ɛ
above rule should be remembered.

Example 1 Convert the given NFA with ɛ to NFA without ε.

Solution: Step 1: We will first obtain ε - closure of each state i.e. we will find out ε -
reachable states from current state.

Hence

ε - closure (q0) = {q0, q1, q2}


ε - closure (q1) = {q1, q2}

ε - closure (q2) = {q2}

As ε - closure (q0) means with null input (no input symbol) we can reach to q0, q1 or
q2. In a similar manner for q1 and q2 ε - closures are obtained.

Step 2: Now we will obtain δ' transitions for each state on each input symbol.

δ' (q0, 0) = ε - closure (δ (δ' (q0, ε), 0))

= ε - closure (δ(ε - closure(q0), 0))

= ε - closure (δ(q0, q1, q2), 0).

= ε - closure (δ(q0, 0) U δ(q1, 0) U δ (q2,0))

= ε - closure (q0 U ϕ U ϕ)

= ε - closure (q0) = {q0, q1, q2}

δ' (q0, 1) = ε - closure (δ (δ`(q0,ε), 1))

= ε - closure (δ (q0, q1, q2), 1)

= ε - closure (δ (q0, 1) U δ (q1, 1) U δ (q2,1))

= ε closure (ϕ U q1 U ϕ)

= ε - closure (q1)

δ' (q0, 1) = {q1, q2}

δ' (q1,0) = ε - closure (δ (δ`(q1,ε), 0))

= ε - closure (δ (ε - closure (q1), 0))

= ε closure (δ (q1,q2), 0)

= ε closure (δ (q1, 0) U δ (q2, 0))

= ε closure (ϕUϕ)

= ε - closure (ϕ)

δ' (q1, 1) = ε - closure (δ (δ` (q1, ε), 1))

= ε - closure (δ (ε - closure (q1), 1))


= ε - closure (δ (q1, q2), 1)

= ε - closure (δ (q1, 1) U δ (q2, 1))

= ε - closure (q1 U ϕ)

= ε - closure (q1)

= {q1, q2}

δ′(q2, 0) = ε- closure (δ (δ` (q2, ε), 0))

= ε - closure (δ (ε - closure (q2), 0))

= ε - closure (δ (q2, 0))

= ε - closure (ϕ)

δ ' (q2, 1) = ε - closure (δ (δ` (q2, ε), 1))

= ε closure (δ (ε - closure (q2), 1))

= ε - closure (δ (q2,1))

= ε - closure (ϕ)

δ' (q2, 1) = ϕ

δ' (q0, 2) = ε - closure (δ (δ` (q2, ε), 2))

= ε - closure (δ (ε -closure (q0), 2))

= ε - closure (δ (q0, q1, q2), 2).

= ε - closure (δ (q0, 2) U δ (q1, 2) U δ (q2, 2))

= ε - closure (q2)

= ε - closure (q2)

= {q2}

δ' (q1,2) = ε - closure (δ (δ` (q1, ε), 2))

= ε - closure (δ (ε - closure (q1), 2))

= ε - closure (δ (q1, q2), 2)


= &- closure (δ (q1, 2) U δ (q2, 2))

= ε closure (ϕ U q2)

= {q2}

δ′ (q2, 2) = ε - closure (δ (δ` (q2, ε), 2))

= ε - closure (δ (ε - closure (q2), 2))

= ε - closure (δ (q2, 2))

= ε - closure (q2)

= {q2}

Now we will summarize all the computed δ' transitions -

δ'(q0, 0) = {q0, q1, q2}, δ'(q0, 1) = {q1, q2), δ'(q0, q2) = {q2}

δ'(q1, 0) = ϕ δ'(q1, 1) = {q1, q2}, δ'(q1, 2) = {q2}

δ'(q2, 0) = ϕ δ'(q2, 1) = ϕ δ'(q2, 2) = {q2}

Step 3:

From this we can write the transition table as -

Step 4:

The NFA will be,

Here q0, q1 and q2 is a final state because ε closure (q0), ε - closure (q1) and ε -
closure (q2) contains final state q2.
Example 2 : Convert the following NFA with e to NFA without ε.

Solution: We will first obtain ε - closure of every state. The ɛ - closure is basically an
ε - transition from one state to other. Hence

ε - closure (0) = {0}

ε - closure (1) = {1}

ε - closure (2) = {2, 3, 4, 6, 9}

ε - closure (3) = {3, 4, 6}

ε - closure (4) = {4}

ε - closure (5) = {5, 8, 3, 4, 6, 9}

= {3, 4, 5, 6, 8, 9} sorted it!

ε - closure (6) = {6}

ε - closure (7) = {7, 8, 3, 4, 6, 9}

= {3, 4, 6, 7, 8, 9}
ε - closure (8) = {8, 3, 4, 6, 9}

= {3, 4, 6, 8, 9}

ε - closure (9) = {9}

Now we will obtain δ' transitions for each state and for each input symbol.

δ' (0, a) = ε - closure (δ (δ` (0, ε), a))

= ε - closure (δ (ε - closure(0), a))

= ε - closure (δ (0, a))

= ε - closure (1)

{1}

δ ' (0, b) = ε - closure (δ (δ` (0,ε), b))

= ε - closure (δ (ε - closure (0), b))

= ε - closure (δ (0, b))

= ε - closure (ϕ)

δ' (1,a) = ε - closure (δ (δ` (1,ɛ), a))

= ε - closure (δ (ε - closure (1), a))

= ε - closure (δ (1, a))

= ε - closure (ϕ)

δ ' (1, b) = ε - closure (8 (8 (1,ε), b))

= ε - closure (δ (ε - closure (1), b))

= ε - closure (δ (1, b))

= ε - closure (2)

= {2, 3, 4, 6, 9}

δ ' (2, a) = ε - closure (δ (δ` (2,ε), a))


= ε - closure (δ (ε - closure (2), a))

= ε - closure (δ (2, 3, 4, 6, 9), a)

= ε - closure (δ (2, a) U δ (3, a) U δ (4, a) U δ (6, a) U δ (9, a))

= ε - closure (ϕ U ϕ U 5 U ϕ U ϕ )

= ε - closure (5)

= {3, 4, 5, 6, 8, 9}

δ' (2, b) = ε - closure: (δ (δ (2, ε), b))

= ε - closure (δ (ε - closure (2), b))

= ε - closure (δ (2, 3, 4, 6, 9), b)

= ε - closure (δ(2, b) U δ(3, b) U δ(4, b) U δ(6, b) U δ(9, b))

= ε - closure (ϕ U ϕ U ϕ U 7 U ϕ)

= ε - closure (7)

= {3, 4, 6, 7, 8, 9}

δ'(3, a) = ε - closure (δ (δ'(3,ε), a))

= ε - closure (δ (ε - closure (3), a))

= ε - closure (δ (3, 4, 6), a).

= ε - closure (δ (3, a) U δ (4, a) U δ (6, a))

= ε - closure (ϕ U 5 U ϕ)

= ε - closure (5)

= {3, 4, 5, 6, 8, 9}

δ`(3, b) = ε - closure (δ (δ`(3, ε), b))

= ε - closure (δ (ε - closure (3), b))

= ε - closure (δ (3, 4, 6), b)

= ε - closure (δ (3, b) U δ (4, b) U δ (6, b))

= ε - closure (ϕ U ϕ U 7)
= ε - closure (7)

= {3, 4, 6, 7, 8, 9}

δ` (4, a) = ε - closure (δ (δ` (4, ε), a))

= ε - closure (δ (ε - closure (4), a))

= ε - closure (δ (4, a))

= ε - closure (5)

= {3, 4, 5, 6, 8, 9}

δ`(4, b) = ε - closure (δ (δ` (4, ε), b))

= ε - closure (δ (ε - closure (4, b))

= ε - closure (δ (4, b))

= ε - closure (ϕ)

δ ' (5, a) = ε - closure (δ (δ`(5, ε), a))

= ε - closure (δ (ε - closure (5), a))

= ε - closure (δ (3, 4, 5, 6, 8, 9), a)

= e-closure (δ (3, a) U (4, a) U δ (5, a) U δ (6, a) U δ (8, a) U δ (9,a))

= ε - closure (ϕ U 5 U ϕ U ϕ U ϕ U ϕ U ϕ)

= ε - closure (5)

= {3, 4, 5, 6, 8, 9}

δ' (5, b) = ε - closure (δ (δ`(5, ε), b))

= ε - closure (δ (ε - closure (5), b))

= ε - closure (δ (3, 4, 5, 6, 8, 9), b)

= ε - closure (δ (3, b) U δ (4, b) U δ (5, b) U δ (6, b) U δ (8, b) U δ (9, b))

= ε - closure (ϕ U ϕ U ϕ U 7 U ϕ U ϕ)

= ε - closure (7)
= {3, 4, 6, 7, 8, 9}

δ' (6, a) = ε - closure (δ (δ` (6, ɛ), a))

= ε - closure (δ (ε - closure (6), a))

= ε - closure (δ (6, a))

= ε - closure (ϕ)

8' (6, b) = ε - closure (δ (δ (6, ɛ), b))

= ε - closure (δ (ε - closure (6), b))

= ε - closure (δ (6, b))

= ε - closure (7)

= {3, 4, 6, 7, 8, 9}

δ' (7, a) = ε - closure (δ (δ`(7, ε), a))

= ε - closure (δ (ε - closure (7), a))

= ε - closure (δ (3, 4, 6, 7, 8, 9), a)

= ε - closure (δ (3, a) U δ (4, a) U δ (6, a) U δ (7, a) U δ (8, a) U δ (9, a))

= ε - closure (ϕ U 5 U ϕ U ϕ U ϕ U ϕ)

= ε - closure (5)

= {3, 4, 5, 6, 8, 9}

δ ' (7, b) = ε - closure (δ (δ` (7, ε), b))

= ε - closure (δ (ε - closure (7), b))

= ε - closure (δ (3, 4, 6, 7, 8, 9), b)

= ε - closure (δ (3, b) U δ (4, b) U δ (6, b) U δ (7, b) U δ (8, b) U δ (9, b))

= ε - closure (ϕ U ϕ U 7 U ϕ U ϕ U ϕ)

= ε - closure (7)

= {3, 4, 6, 7, 8, 9}
δ' (8, a) = ε - closure (δ (δ`(8, ε), a))

= ε - closure (δ (ε - closure (8), a))

= ε - closure (δ (3, 4, 6, 8, 9), a)

= ε - closure (δ (3, a) U δ (4, a) U δ (6, a) U δ (8, a) U δ (9, a))

= ε - closure (ϕ U 5 U ϕ U ϕ U ϕ)

= ε - closure (5)

= {3, 4, 5, 6, 8, 9}

δ' (8, b) = ε - closure (δ (δ` (8, ε), b))

= ε - closure (δ (ε - closure (8), b))

= ε - closure (δ (3, 4, 6, 8, 9), b)

= ε - closure (δ (3, b) U δ (4, b) U δ (6, b) U δ (8, b) U δ (9, b))

= ε - closure (ϕ U ϕ U 7 U ϕ U ϕ)

= ε - closure (7)

= {3, 4, 6, 7, 8, 9}

δ' (9, a) = ε - closure (δ (δ` (9, ε), a))

= ε - closure (δ (ε - closure (9), a))

= ε - closure (δ (9, a))

= ε - closure (ϕ)

δ' (9, b) = ε - closure (δ (δ` (9, ε), b))

= ε - closure (δ (ε - closure (9), b))

= ε - closure (δ (9, b))

= ε - closure (ϕ)

Now we will build the transition table using above calculated δ' transitions.
State {2} is a final state since ε - closure (2) contains 9 which is actually a final state
in given NFA. Similarly state 5, 7, 8 and 9 are final states.

Example 3 : Convert the following NFA with & to NFA without ɛ.

Solution: We will first obtain & - closures of q0, q1 and q2 as follows.

ε - closure (q0) = {q0}

ε - closure (q1) = {q1, q2}

ε - closure (q2) = {q2}

Now the δ' transitions on each input symbol is obtained as,

8' (q0, a) = ε - closure (δ (δ` (q0, ε), a))

= ε - closure (δ (ε - closure (q0), a))

= ε - closure (δ (q0, a))

= ε - closure (q1)
= {q1, q2}

δ' (q0, b) = ε - closure (δ (δ` (q0, ε), b))

= ε - closure (δ (ε - closure (q0), b))

= ε - closure (δ (q0, b)).

δ' (q1, a) = ε - closure (δ (δ` (q1, ε), a))

= ε - closure (δ (ε - closure (q1), a))

= ε - closure (δ (q1, q2), a)

= ε - closure (δ (q1, a) U δ (q2, a))

= ε - closure (ϕ U ϕ)

δ' (q1, b) = ε - closure (δ (δ` (q1, ε), b))

= ε - closure (δ (ε - closure (q1), b))

= ε - closure (δ (q1, q2), b)

= ε - closure (δ (q1, b) U δ (q2, b))

= ε - closure (q2)

= ε - closure (q2)

= {q2}

δ' (q2, a) = ε - closure (δ (δ` (q2, ε), a))

= ε - closure (δ (ε - closure (q2), a))

= ε - closure (δ (q2, a))

= ε - closure (ϕ)

δ' (q2, b)

= ε - closure (δ (δ`(q2, ε), b))


= ε - closure (δ (ε - closure (q2), b))

= ε - closure (δ (q2, b))

= ε - closure (q2)

= {q2}

The transition table can be –

States q1 and q2 becomes the final as closures of q1 and q2 contains the final state q2.
The NFA can be shown by transition diagram as shown in Fig. 1.9.5.

Example 4 : Convert the given NFA with ɛ to ordinary NFA.

Solution: We will first obtain ε - closure of each state.

ε - closure (q0) = {q0, q1, q2}

ε - closure (q1) = {q1, q2)

ε - closure (q2) = {q2}


Now &' transitions for each state on each input.

8' (q0, a) = ε - closure (δ (δ` (q0, ε), a))

= ε - closure (δ (ε - closure (q0), a))

= ε closure (δ ((q0, q1, q2), a))

= ε closure (δ (q0, a) U δ (q1, a) U δ (q2, a))

= ε - closure (ϕ U q1 U q1).

= ε - closure (q1)

= (q1, q2)

δ' (q0, b) = ε - closure (δ (δ` (q0, ε), b))

= ε closure (δ (ε - closure (q0), b))

= ε - closure (δ ((q0, q1, q2), b))

= ε - closure (δ (q0, b) U δ (q1, b) U δ (q2, b))

= ε - closure (q0 U ϕ U q0)

= ε - closure (q0)

= (q0, q1, q2)

δ' (q1, a) = ε - closure (δ (δ` (q1, ε), a))

= ε - closure (δ (ε - closure (q1), a))

= ε - closure (δ ({q1, q2), a))

= ε - closure (δ (q1, a) U δ (q2, a))

= ε - closure (q1 U q1)

= ε - closure (q1)

= {q1, q2}

δ' (q1, b) = ε - closure (δ (δ` (q1, ε), b))

= ε - closure (δ (ε - closure (q1), b))

= ε - closure (δ (q1, q2), b))


= ε - closure (δ (q1, b) U δ (q2, b))

= ε closure (ϕ U q0)

= {q0, q1, q2}

δ' (q2, a) = ε - closure (δ (δ` (q2, ε), a))

= ε - closure (δ (ε - closure (q2), a))

= ε - closure (δ (q2, a))

= ε - closure (q1)

= (q1, q2)

δ' (q2, b) = ε - closure (δ (δ` (q2, ε), b))

= ε closure (δ (ε - closure (q2), b))

= ε - closure (δ (q2, b))

= ε - closure (q0)

= {q0, q1, q2}

The transition table can be –

Example 5: Construct an NFA without ε transitions for the NFA given in Fig.

Solution: We will first obtain ε - closures of q0 and q1 as follows -

ε - Closure (q0) = {q0, q1}

ε - Closure (q1) = {q1}


Now δ' transitions on each input symbol is obtained as -

δ'(q0, 0) = ε - Closure (δ (δ` (q0, ε), 0))

= ε - Closure (δ (ε - Closure (q0), 0))

= ε - Closure (δ ((q0, q1), 0))

= ε - Closure (q0)

δ' (q0, 0) = {q0, q1}

δ' (q0, 1) = ε - Closure (δ (δ` (q0, ε), 1))

= ε - Closure (δ (ε - Closure (q0), 1))

= ε - Closure (8 ((q0, q1), 1))

= ε - Closure (q1)

δ' (q0, 1) = {q1}

δ' (q1, 0) = ε - Closure (δ (δ` (q1, ε), 0))

= ε - Closure (δ (ε - Closure (q1), 0))

= ε - Closure (δ (q1, 0))

= ε - Closure (ϕ)

δ' (q1, 0) = ϕ

δ' (q1, 1) = ε - Closure (δ (δ` (q1, ε), 1))

= ε - Closure (δ (ε - Closure (q1), 1))

= ε - Closure (δ (q1, 1))

= ε - Closure (q1)

δ' (q1, 1) = {q1}

The transation table for NFA without & will be,


The transition diagram will be -

EQUIVALENCE OF NFA WITH Ε TO DFA

Prove that there exists a DFA for every ε - NFA.

Step 1: Consider M = (Q, Σ, δ, q0, F) is a NFA with ε. We have to convert this NFA
with ε to equivalent DFA denoted by

MD = (QD, Σ, δD, q0, FD)

Then obtain,

ε - closure (q0) = {P1, P2, P3... Pn} then [P1, P2, P3 ,... Pn] becomes a start state of
DFA.

Now [P1, P2, P3... Pn] ϵ QD

Step 2: We will obtain δ transitions on [P1, P2, P3, ... Pn ] for each input.

δD ([P1, P2, Pn], a) = ε - closure (δ (P1, a) U δ (P2, a) U... δ (Pn, a))

= Uni=1 ε - closure d (Pi, a)

where a is input ϵ Σ.

Step 3: The states obtained [P1, P2, P3, ... Pn] ϵ QD. The states containing final state
Pi is a final state in DFA.

Now let us see some examples of conversion based on this procedure.

Example 1 : Convert the following NFA with ε to equivalent DFA.

Solution:

Step 1: To convert this NFA we will first find ɛ-closures.


ε - closures {q0} = {q0, q1, q2}

ε - closures {q1} = {q1, q2}

ε - closures {q2} = {q2}

Step 2: Let us start from ε - closure of start state

ε - closure {q0} = {q0, q1, q2} we will call this state as A.

Now let us find transitions on A with every input symbol.

δ (A, a) = ε-closure (δ (A, a))

= ε - closure (δ (q0, q1, q2), a)

= ε - closure {(q0, a) U δ (q1, a) U δ (q2, a)}

= ε - closure {q1}

= {q1, q2). Let us call it as state B.

δ (A, b) = ε-closure (δ (A, b))

= ε - closure (δ (q0, q1, q2), b)

= ε - closure {δ (q0, b) U δ (q1, b) U δ (q2, b)}

= ε - closure {q0}

= {q0, q1, q2} i.e. A.

Hence we can state that,

δ' (A, a) = B

δ` (A, b) = A

Step 3: Now let us find transitions for state B = {q1, q2}

δ' (B, a) = ε - closure (δ (q1, q2), a)

= ε - closure {q1}

= {q1, q2} i.e. B

δ` (B, b) = ε - closure (δ ( q1, q2), b)

= ε - closure {δ (q1, b) U δ (q2, b)}


= ε - closure {q0}

= (q0, q1, q2) i.e. A.

Step 4: Hence the generated DFA is

Example 2: Convert the given NFA into its equivalent DFA -

Solution: Let us obtain ε - closure of each state.

ε - closure (q0) = {q0, q1, q2}

ε - closure (q1)= {q1, q2}

ε - closure (q2) = {q2}

Now we will obtain d' transition. Let e-closure (q0) = {q0, q1, q2} call it as state A.

δ' (A, 0) = ε - closure { δ ((q0, q1, q2), 0)}

= ε - closure {δ (q0, 0) U δ (q1, 0) U δ (q2, 0)}

= ε - closure {q0}

= {q0, q1, q2} i.e. state A

δ' (A, 1) = ε - closure { δ ((q0, q1, q2), 1)}

= ε - closure {(q0,1) U δ (q1,1) U δ (q2,1)}

= ε - closure {q1, q2}

= {q1, q2} Call it as state B

δ' (A, 2) = ε - closure {δ ((q0, q1, q2), 2)}


= ε - closure {δ (q0, 2) U δ (q1, 2) U δ (q2, 2)}

= ε - closure {q2}

= {q2} Call it as state C.

Thus we have obtained,

δ` (A, 0) = A

δ` (A, 1) = B

δ` (A,2) = C

i.e.

Now we will find transitions on states B and C for each input.

Hence,

δ' (B, 0) = ε - closure {δ (q1, q2), 0}

= ε - closure {δ (q1, 0) U δ (q2, 0)}

= ε - closure {ϕ}

δ' (B, 1) = ε - closure {δ (q1, q2), 1}

= ε - closure {δ (q1, 1) U δ (q2, 1)}

= ε - closure {q1}

= {q1, q2) i.e state B itself.

δ` (B, 2) = ε - closure {δ (q1, q2), 2}

= ε - closure {δ (q1, 2) U δ (q2, 2)}


= ε - closure {q2}

= {q2} i.e state C.

Hence,

δ` (B, 0) = ϕ

δ` (B, 1) = B

δ` (B, 2) = C

The partial transition diagram will be,

Now we will obtain transitions for C:

δ` (C, 0) = ε - closure {δ (q2, 0)}

= ε - closure {ϕ}

δ` (C, 1) = ε - closure {δ (q2, 1)}

= ε - closure {ϕ}

δ` (C,2) = ε - closure {δ (q2, 2)}

= q2
Hence the DFA is,

As A = {q0, q1, q2} in which final state q2 lies hence A is final state in B = {q1, q2}
the state q2 lies hence B is also final state in C = {q2}, the state q2 lies hence C is also
a final state.

Example 3: Consider following NFA with ε.

Convert it to its equivalent DFA.

Solution: We will first compute ε - closure for start state p.

ε closure (p) = {p} call it as state A.

Now we will obtain 8 transitions on state A.


State A

δ' (A, a) = ε - closure (δ (A, a))

= ε - closure (δ (p, a))

= ε - closure (p)

= {p} i.e. state A only.

δ' (A, b) = ε - closure (δ (A, b))

= ε - closure (δ (p, b))

= ε - closure (q)

= {q, p} i.e. {p, q} Let us call it state B.

δ' (A, b) = B

δ' (A, c) = ε - closure (δ (A, c))

= ε - closure (δ (p, c))

= ε - closure (r) = {q, r} Call it as state C.

State B = {p, q}

δ' (B, a)

= ε - closure (δ (B, a))

= ε - closure (δ (p, q), a)

= ε - closure (δ (p, a) U δ (q, a))


= ε - closure (p U q)

= ε - closure (p, q)

= ε - closure(p) Ụ ɛ - closure(q)

= {P} U {q} = {p, q} i.e. state B only.

δ' (B, a) = B.

δ' (B, b) = ε - closure (δ (B, b))

= ε - closure (δ (p, q), b)

= ε - closure (δ (p, b) U δ (q, b))

= ε - closure (q U r)

= ε - closure (q, r)

δ' (B, b) = ε - closure(q) U ε - closure(r)

= {p, q} U {q, r} = {p, q, r} i.e. state D

δ`(B, b) = D.

δ' (B, c) = ε - closure (δ (B, C))

= ε - closure (δ (p, q), c)

= ε - closure (δ (p, c) U δ (q, c))

= ε - closure (r U ϕ)

= ε - closure (r)

= {q, r}

δ' (B, c) = C

State C = {q, r}

δ' (C, a) = ε - closure (δ (C, a))

= ε - closure (δ (q, r), a)

= ε - closure (δ (q, a) U δ (r, a))

= ε - closure (q U r)
= ε - closure (q) U ε - closure(r)

= {p, q} U {q, r}

= (p, q, r) i.e. state D.

δ' (C, a) = D

8' (C, b) = ε - closure (δ (C, b))

= ε - closure (δ (q, r), b)

= ε - closure (δ (q, b) U δ (r, b)).

= ε - closure (r U ϕ)

= ε - closure (r)

= {q, r) i.e. state C.

δ' (C, b) = C

δ' (C, c) = ε - closure (δ (C, c))

= ε - closure (δ (q, r), c)

= ε - closure (δ (q, c) U δ (r, c))

= ε - closure (ϕ U p)

= ε - closure (p)

= {p} i.e. state A.

δ' (C, c) = A

State D = {p, q, r}

δ' (D, a) = ε - closure (δ (D, a))

= ε - closure (δ (p, q, r), a)

= ε - closure (δ (p, a) U δ (q, a) U δ (r, a))

= ε - closure (p U q U r)

= ε - closure (p) U ɛ - closure(q) U ε - closure (r)

= (p, q, r) i.e. state D.


δ ' (D, a) = D

8' (D, b) = ε - closure (δ (D, b))

= ε - closure (δ (p, q, r), b)

= ε - closure (δ (p, b) U δ (q, b) U δ (r, b))

= ε - closure (q U r U ϕ)

= ε - closure (q, r)

= ε - closure (q) U ε - closure (r)

= (p, q, r) i.e. state D.

δ' (D, b) = D

δ' (D, c) = ε - closure (δ (D, c))

= ε - closure (δ (p, q, r), c)

= ε - closure (δ (p, c) U δ (q, c) U δ (r, c))

= ε - closure (r U ϕ U p)

= ε - closure (r) U ε - closure (p)

= {q, r} U {P}

= {p, q, r} i.e. state D.

δ' (D, c) = D

The transition table from above calculations can be obtained as,


As state A = {p} it is a start state and states C and D contain final state r, hence these
are final states. The transition diagram for the DFA is,

Example 4 : Consider the following ε - NFA for an identifier. Consider the ε -


closure of each state and find it's equivalent DFA.

Solution:

ε - closure (1) = {1} Call it as state A

δ' (A, letter) = ε - closure(δ (1, letter)

= ε - closure(2)

= {2, 3, 4, 5, 8, 10} Call it as state B

δ' (A, letter) = B

δ' (A, digit) = ε - closure(δ (1, digit))

δ' (A digit) = ϕ

δ' (B, letter) = ε - closure(δ (2, 3, 4, 5, 8, 10), letter)

= ε – closure (6)

= {6, 7, 4, 5, 8, 10) i.e.

= {4, 5, 6, 7, 8, 10} Call it as state C

δ' (B, letter) = C

δ' (B, digit) = ε - closure(&(2, 3, 4, 5, 8, 10), digit)

= ε – closure (9)
= {9, 7, 4, 5, 8, 10} i.e.

= {4, 5, 7, 8, 9, 10} Call it as state D

δ' (B, digit) = D

δ' (C, letter) = ε - closure(δ (4, 5, 6, 7, 8, 10), letter)

= ε – closure (6)

=C

δ' (C, letter) = C

δ' (C, digit) = ε - closure(δ (4, 5, 6, 7, 8, 10), digit)

= ε – closure (9)

=D

δ' (C, digit) = D

δ' (D, letter) = ε - closure(δ (4, 5, 7, 8, 9, 10), letter)

= ε - closure (6)

=C

δ' (D, letter) = C

δ' (D, digit) = ε - closure(δ (4, 5, 7, 8, 9, 10), digit)

= ε - closure (9)

=D

δ' (D, digit) = D

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy