0% found this document useful (0 votes)
45 views18 pages

Unit 01 - Part 3

1. The document discusses finite automata and regular expressions. 2. It explains how to construct a nondeterministic finite automata (NFA) from a regular expression using a recursive algorithm. 3. It also describes how to convert an NFA to a deterministic finite automata (DFA) using the subset construction algorithm and how to minimize the resulting DFA.

Uploaded by

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

Unit 01 - Part 3

1. The document discusses finite automata and regular expressions. 2. It explains how to construct a nondeterministic finite automata (NFA) from a regular expression using a recursive algorithm. 3. It also describes how to convert an NFA to a deterministic finite automata (DFA) using the subset construction algorithm and how to minimize the resulting DFA.

Uploaded by

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

Topic

Finite Automata
Finite Automata
 Finite automata are recognizers; they simply say "yes" or "no" about each possible input string.
 Finite automata come in two flavors:
(a)Nondeterministic finite automata (NFA) have no restrictions on the labels of their edges. A symbol
can label several edges out of the same state, and ε, the empty string, is a possible label.
(b) Deterministic finite automata (DFA) have, for each state, and for each symbol of its input alphabet
exactly one edge with that symbol leaving that state.
A FA can be represented by a 5-tuple (Q, ∑, δ, q0, F)
Nondeterministic Finite Automata
A nondeterministic finite automaton (NFA) consists
of:
1. A finite set of states Q.
2.A set of input symbols ∑ , the input alphabet. We assume that E, which stands for the
empty string, is never a member of ∑ .
3.A transition function δ that gives, for each state, and for each symbol in a set of
next states.
4. A state q0 from Q that is distinguished as the start state (or initial state).
5.A set of states F, a subset of Q that is distinguished as the accepting states (or final
states).
This NFA graph is very much like a transition diagram, except:
a) The same symbol can label edges from one state to several different states, and
b) An edge may be labeled by c, the empty string, instead of, or in addition to, symbols from the input
alphabet.

Deterministic Finite Automata


A deterministic finite automaton (DFA) is a special case of an NFA where:
1. There are no moves on input ε, and
2. For each state s and input symbol a, there is exactly one edge out of s labeled a.
Topic
Regular Expressions
to Automata
From Regular Expressions to Automata
Implementation of that software requires the simulation of a DFA. Because an NFA
often has a choice of move on an input symbol or on ε its simulation is less
straightforward than for a DFA. Thus often it is important to convert an NFA to a DFA
that accepts the same language.
The steps are
1. Construction of NFA from regular expression.
2. Conversion of NFA from DFA
Construction of NFA from a regular expression
 McNaughton-Yamada-Thompson algorithm to convert a regular expression to an
 NFA.
 The algorithm is syntax-directed, in the sense that it works recursively up the
parse tree for the regular expression.
 There are 2 rules for construction of NFA for sub expressions.

Department of CSE, NSCET, Theni Page-47


i) Basic rules for handling sub expressions with no operators
For expression ε constructs the NFA

For any sub expression a in Σ, construct the NFA as

Where, i is a new state start state of this NFA,


f is another new state accepting state for the NFA
ii) Induction Rules
 Used to construct larger NFA’s from the NFA’s for immediate sub expressions of given
expressions.
a) UNION
Suppose r = s|t. Then N (r), the NFA for r, is constructed from N(s) &N(t). N(r) accepts L(S)UL(t),
which is same as L(r).

b) CONCATENATION
Suppose r = st. The start state of N (s) becomes the start state of N (r), and the accepting state of N(t)
is the only accepting state of N(r). Thus, N(r) accepts exactly L(s)L(t), and is a correct NFA for r = st.
c) CLOSURE
Suppose r = s*. Here, i and f are new states, the start state and lone accepting state of N (r) .
N(r) accepts ε, which takes care of the one string in L(s)0, & accepts all strings in L(s)1,
L(s)2 and so on

Finally, suppose r = (s). Then L(r) = L(s), and we can use the NFA N(s) as N(r).
The properties of N(r) are as follows:
1. N(r) has at most twice as many states as there are operators and operands
in r.
2. N(r) has one start state and one accepting state.
3.Each state of N (r) other than the accepting state has either one outgoing transition on a
symbol in C or two outgoing transitions, both on ε.
Problem
Construct an NFA for r = (a | b) * a b
The following figure shows parse tree for r
i) NFA for a ii) NFA for a

iii) NFA for a | b iv) NFA for (a|b)*


v) NFA for (a|b)*a

vi) NFA for (a|b)*abb


Topic Minimizing DFA
Conversion of NFA into DFA
The general idea behind the subset construction algorithm is that each state of the
constructed DFA corresponds to a set of NFA states.
The Subset Construction Algorithm
1. Create the start state of the DFA by taking the ε-closure of the start state of the NFA.
2. Perform the following for the new DFA state: For each possible input symbol:
a) Apply move to the newly-created state and the input symbol; this will return a set of
states.
b)Apply the ε-closure to this set of states, possibly resulting in a new set.
This set of NFA states will be a single state in the DFA.
3. Each time we generate a new DFA state, we must apply step 2 to it.
The process is
complete when applying step 2 does not yield any new states.
4. The finish states of the DFA are those which contain any of the finish
states of the NFA.
DFA Minimization
 The process of converting a given DFA into an equivalent DFA with a minimum number of
states is considered to be a minimization of DFA.
 It contains the minimum number of states.
 The DFA in its minimal form is called as a Minimal DFA
Minimization of DFA Using Equivalence Theorem
Step 1:
Eliminate all the dead states and inaccessible states from the given DFA (if any).
Dead State
All those non-final states which transit to itself for all input symbols in ∑ are called as dead
states.
Inaccessible State
All those states which can never be reached from the initial state are called as inaccessible
states.
Step 2:
 Draw a state transition table for the given DFA.
 Transition table shows the transition of all states on all input symbols in Σ.
Step 3:
 Now, start applying equivalence theorem.
 Take a counter variable k and initialize it with value 0.

 Divide Q (set of states) into two sets such that one set contains all the non-final states and other set
contains all the final states.
 This partition is called P0.
Step 4:
 Increment k by 1.
 Find Pk by partitioning the different sets of Pk-1 .
 In each set of Pk-1 , consider all the possible pair of states within each set and if the two states are
distinguishable, partition the set into different sets in Pk.
 Two states q1 and q2 are distinguishable in partition Pk for any input symbol ‘a’,
Step 5
 Repeat step-04 until no change in partition occurs.
 In other words, when you find Pk = Pk-1, stop.
Step 6:
 All those states which belong to the same set are equivalent.
 The equivalent states are merged to form a single state in the minimal DFA.
Number of states in Minimal DFA = Number of sets in Pk
Example:
Construct NFA for the RE (a|b)*abb and also convert it into Minimized DFA
Step 1: NFA Construction using Thompson Method
(a|b)*abb

Step 2: Convert NFA into DFA using Subset construction Algorithm


ε – closure (0) = {0, 1, 2, 4, 7 } = A
Dtran[A, a] = ε – closure (move(A, a))
= ε – closure (3, 8)
= {1, 2, 3, 4, 6, 7, 8 }
=B
Dtran[A, b] = ε – closure (move(A, b))
= ε – closure (5)
= {1, 2, 4, 5, 6, 7 }
=C
Dtran[B, a] = ε – closure (move(B, a))
= ε – closure (3, 8)
= {1, 2, 3, 4, 6, 7, 8 }
=B
Dtran[B, b] = ε – closure (move(B, b))
= ε – closure (5, 9)
= {1, 2, 4, 5, 6, 7, 9 }
=D
Dtran[C, a] = ε – closure (move(C, a))
= ε – closure (3, 8)
= {1, 2, 3, 4, 6, 7, 8 }
=B
Dtran[C, b] = ε – closure (move(C, b))
= ε – closure (5)
= {1, 2, 4, 5, 6, 7 }

=C
Dtran[D, a] = ε – closure (move(D, a))
= ε – closure (3, 8)
= {1, 2, 3, 4, 6, 7, 8 }
=B
Dtran[D, b] = ε – closure (move(D, b))
= ε – closure (5, 10)
= {1, 2, 4, 6, 7, 10 }
=E
Dtran[E, a] = ε – closure (move(E, a))
= ε – closure (3, 8)
= {1, 2, 3, 4, 6, 7, 8 }
=B
Dtran[E, b] = ε – closure (move(E, b))
= ε – closure (5)
= {1, 2, 4, 5, 6, 7 }
=C
Step 3: DFA Transition Table

NFA State DFA State a b


{0,1,2,4,7} ->A B C
{1,2,3,4,6,7,8} B B D
{1,2,4,5,6,7} C B C
{1,2,4,5,6,7,9} D B E
{1,2,4,6,7,10} *E B C
Step 4: DFA Transition Diagram

You might also like