You are on page 1of 96

21CS51 ATCD Module 1

Introduction to Automata Theory

VENKATESH
Senior Professor, Dept. of CSE
AIET, Moodbidri
MODULE 1 SYLLABUS
• Introduction to Automata Theory: Central Concepts of
Automata theory, Deterministic Finite Automata (DFA), Non-
Deterministic Finite Automata (NFA), Epsilon- NFA, NFA to DFA
Conversion, Minimization of DFA
• Introduction to Compiler Design: Language Processors,
Phases of Compilers.

• Textbook 1: Chapter1 – 1.5, Chapter2 – 2.2, 2.3, 2.5 Chapter4 – 4.4


• Textbook 2: Chapter1 – 1.1 and 1.2
Automata Theory
• Automata Theory is the study of Abstract Computing
Devices, or Machines.
• Finite Automata and Formal Grammers are used in the
design of machines and construction of important kind of
software.
Finite Automaton Model for On/Off Switch
• Here the device remembers whether the system is in
the on state or off state. It allows the user to press a
button whose effect is different, depending on the
state of the switch. Push
Start
off on
Push
Write a Finite Automaton for
Transmission of a car.
•Exercise for a student.
Central Concepts of Automata Theory
• Some terms frequently used in the theory of automata:
• Alphabet (It is a set of symbols)

• String (A list of symbols from the alphabet)


• Language (a set of strings from the same alphabet)
Alphabets
• In Binary system, the alphabets are: {0, 1}
• In Digits system, the alphabets are {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
• In letter, the alphabets are {a, b, c, …, z, A, B, C, …, Z}
• In arithmetic operations, the various alphabets are: {+, -, *, /}
ALPHABETS
• An alphabet is a finite, nonempty set of symbols.
• We use the symbol Ʃ for an alphabet.
• Some of the alphabets are:
• Ʃ = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
• Ʃ = {0, 1}
• Ʃ = {a, b, c, …, z, A, B, C, ,… Z}
ALPHABETS
• An alphabet is a finite, nonempty set of symbols.
• We use the symbol Ʃ for an alphabet.
• Some of the alphabets are:
• Ʃ = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
• Ʃ = {0, 1}
• Ʃ = {a, b, c, …, z, A, B, C, ,… Z}
STRINGS (or WORDS)
• A string is a finite sequence of symbols chosen from some
alphabet.
• Example: 1845 is a string from digit alphabet
Ʃ = {0, 1, 2, 3, 4, 5, 6, 7, 8}
• Any number of strings can be generated from the given
alphabet.
Some Terminologies on String
Some Terminologies on String
• of the alphabet (Ʃk)
Ʃ0 = . We have only one string with length zero. i.e.,
Some Terminologies on String
• of the alphabet (Ʃk)
Ʃ0 = . We have only one string with length zero. i.e.,
• of the alphabet (Ʃk)
Ʃ0 = . We have only one string with length zero. i.e.,
Some Terminologies on String
• Empty String: An Empty String is a string with zero occurrences of
symbols. Empty string is denoted by the symbol 
• Length of the string: It is the total number of symbols used in the string.
Standard notation for the length of the string w is |w|. That is || = 0.
• Powers of an alphabet: Number of occurrence of the symbols in the
string is represented by power of the alphabet (Ʃk)
Ʃ0 = . We have only one string with length zero. i.e., 
• Concatenation of a string: if x = 1101 and y = 101101,
then xy is xy = {1101101101}
yx = {1011011101}
More about Powers of an alphabet
• Number of occurrence of the symbols in the string is represented by
power of the alphabet (Ʃk)
Ʃ0 = . We have only one string with length zero. i.e., 
• If Ʃ = {a, b, c}; then
• Ʃ1 = {a, b, c}
• Ʃ2 = {aa, ab, ac, ba, bb, bc, ca, cb, cc}
• Ʃ3 = {aaa, aab, aac, aba, abb, abc, aca, acb, acc, baa, bab, bac, bba,
bbb, bbc, bca, bcb, bcc, caa, cab, cac, cba, cbb, cbc, cca, ccb, ccc }
• Ʃ* = Ʃ0 U Ʃ1 U Ʃ2 U Ʃ3 …
• Ʃ+ = Ʃ1 U Ʃ2 U Ʃ3 …
• Therefore, Ʃ* = Ʃ+ U {} = Ʃ+ U Ʃ0
Identity for Concatenation
• For any String, w, the equations εw = wε = w.
• Hence ε is the identity of for concatenation. That is,
when ε is concatenated with any other string, then it
produces the other string.
Languages
• A set of strings all of which are chosen from Ʃ* , where Ʃ
is a particular alphabet, is called as a language.
• If Ʃ is an alphabet, and L ⃀ Ʃ*, then L is a language over Ʃ.
Deterministic Finite Automata (DFA)
• A Deterministic Finite Automaton Consists of :
• A Finite set of States, denoted by Q.
• A Finite set of input symbols denoted by Ʃ.
• A Transition Function that takes the arguments a state
and an input symbol and returns a state. A Transition
function is denoted by Ꟙ was represented arcs
between states and labels on the arcs.
• A Start State
• A set of Final State (or accepting state)
Deterministic Finite Automata (DFA)
DFA in Five Tuple Notation
A = (Q, Ʃ, Ꟙ, q0, F)
Here A is the name pf the DFA
Q is the set of states
Ʃ is the its input symbols
Ꟙ is the transition function.
q0 is the start state.
F is the Accepting states.
How DFA Processes a string
• The “Language” of the DFA is the set of all strings that the DFA accepts.
• Suppose that a1a2a3a4…an is a sequence of input symbols.
• DFA begins with its start state q0.
• Let us assume that transition function at q0 is Ꟙ(q0, a1) = q1. This shows the
new state of the DFA after processing first input symbol a 1.
• We process next input symbol a2 by evaluating the transition function
Ꟙ(q1, a2) = q2.
• We continue in this manner, finding the states q3, q4, q5, … qn. Using the
transition function: Ꟙ(qi–1, ai) = qi for each i. if qn (Final state) is the member
of F, then the input string a1a2a3a4…an is accepted by DFA. Otherwise it is
rejected by DFA.
Example 1:
• Write a Language that accepts all binary strings containing 0’s
and 1’s that have the sequence 01 somewhere in the string.
• Ans:
{w | w is of the form x01y for some strings x and y consisting of 0’s and 1’s}

Alternate description:
{x01y | x and y are any strings of 0’s and 1’s}

• Examples of strings in the language include 01, 11010, 100011 etc…


• Example of the strings not in the language include ε, 0, 10, 110, 11,
111000 etc…
Write a State Transition Diagram to accept binary string
that contains 01 any where in the string
• Input Alphabet is Ʃ = {0, 1}
• It has some states, say the set Q, of which one, say q0, is the start
state.
• To decide whether “01” is a substring of the input, DFA needs to
remember the following:
• Has it already seen 01? If so, then DFA accepts every sequence of the string.
• Has it never seen 01, but its most recent input was 0, and if it now sees a 1, it
will have seen 01 and can accept everything it sees from here on?
• Has it never seen 01, but its last input either nonexistent (just started), or it
last saw a 1? In this case, DFA cannot accept until it first sees a 0 and then
sees a 1 immediately after.
How to Draw the DFA for example 1?
• These three conditions can each be represented by a state.
• Condition 3 can be represented by a start state, q0. If in the state q0 we next see a 1,
then we are no closure to seeing 01, and we must stay in start state q0 only, that is
Ꟙ(q0, 1) = q0.
• If we are in the state q0, we see a 0, then we are in condition 2. that is we are never
seen 01, but we have our 0. Let us use the state q2 to represent condition 2. The
transition function is: Ꟙ(q0, 0) = q2.
• Let us see the transition from state q2.
• If we see a 0 in q2, then, we have not seen 01, but 0 was the last symbol. So we
are still waiting in the state q2. Transition function is Ꟙ(q2, 0) = q2.
• In q2, if we receive a 1, then, we are in condition 1. We can go to accepting
state. We shall call it by q1. Transition function is Ꟙ(q2, 1) = q1.
Write a Transition Diagram for the previous Example

•Left as Exercise for the students


Simpler Notation for DFA
• Transition Diagram: Pictorial Representation of
Transition Function Ꟙ

• Transition Table: Tabular Representation of


Transition Function Ꟙ
Transition Diagram
• Transition Diagram for DFA A = (Q, Ʃ, Ꟙ, q0, F) is a graph defined as follows:
• For each state in Q, there is a node.
• For each state q in Q and each input symbol a in Ʃ, let Ꟙ(q, a) = p. Then
transition diagram has an arc from node q to node P labeled with a.
• If there are several input symbols that cause the transitions
from node q to node p, then the transition diagram can have
one arrow (or arc) from node q to node p, labeled by the list of
these symbols.
• There is an arrow into the start state q0, labeled by Start. This arrow
does not originate at any node.
• Nodes corresponds to accepting states (the states in F), are marked by
double circle. States not in F are single circle.
Write a transition diagram for DFA to accept a binary string
that contains 01 anywhere in the binary string.
Write a transition diagram for DFA to accept a binary string
that contains 01 anywhere in the binary string.

q0 q1 q2
Write a transition diagram for DFA to accept a binary string
that contains 01 anywhere in the binary string.

Start q0 q1 q2
Write a transition diagram for DFA to accept a binary string
that contains 01 anywhere in the binary string.

Start q0 0 q1 1 q2
Write a transition diagram for DFA to accept a binary string
that contains 01 anywhere in the binary string.

1 0 0, 1

Start q0 0 q1 1 q2
Exercise to the Students
• Draw the Transition diagram to recognize the
binary string that ended with 01
Exercise to the Students
• Draw the Transition diagram to recognize the
binary string that ended with 01

Start q0 0 q1 1 q2
Exercise to the Students
• Draw the Transition diagram to recognize the
binary string that ended with 01
1 0

Start q0 0 q1 1 q2
Exercise to the Students
• Draw the Transition diagram to recognize the
binary string that ended with 01
1 0
0
Start q0 0 q1 1 q2

1
You may reposition the states
• After repositioning, you may get the Transition diagram
as shown below
1

Start 1
q0 q2
0 q1 1
0 0
Transition Tables
• It is a conventional tabular representation of a
transition function Ꟙ that takes two arguments and
returns a value.
• Rows of the table represents the states in the
transition diagram.
• Columns represents the input symbols. The entry
corresponds to the state q and the column
corresponds to the input a, is a state Ꟙ(q, a).
Write a transition table for accepting the binary string
containing 01 anywhere in the binary string
1 0 0, 1
Start q0 0 q1 1 q2
0 1
q0
q1
*q2
Write a transition table for accepting the binary string
containing 01 anywhere in the binary string
1 0 0, 1
Start q0 0 q1 1 q2
0 1
q0 q1 q0
q1 q1 q2
*q2 q2 q2
Extending the Transition Function to Strings
• If Ꟙ is our transition function, then the extended transition
function constructed from Ꟙ will be called ^

• The extended transition function is a function that takes a
state q and a string w and returns a state p.
• The state p is the state that the automaton reaches when
starting in state q and processing the sequence of inputs w.
^
Defining Ꟙ by induction on the length of the input string
^
• Basis: Ꟙ(q, ε) = q. That is, if we are in state q and read no
inputs then we are still in state q.
• Induction: Suppose w is a string of the form xa; that is a is
last symbol of w, and x is the string consisting of all symbol in
w except last symbol. Then
^ ^
Ꟙ(q, w) = Ꟙ( Ꟙ (q, x), a)
Suppose that Ꟙ ^(q, w) is the transition from
^ (q, x) = p. Then Ꟙ
state p on input a, the last symbol of w. That is,
^ (q, w) = Ꟙ(p, a)

Example: Design a DFA to accept the language
L = {w | w is of even length and begins with 01}
• This automaton needs to remember whether the string seen so far started with
01. It also needs to keep track the length of the string. So, it consists of five states
could be interpreted as follows:
• q0: The initial State.
• q1: The state entered on reading 0 in the state q0.
• q2: The DFA enters this state whenever the substring seen so far starts with 01 and
is even length.
• q3: The DFA enters this state whenever the substring seen so far starts with 01 and
is odd length.
• q4: The DFA enters this state whenever the string begins with 1 or it reads a
symbol 1 in q1.
Write the Transition Diagram for the same
Write the Transition Diagram for the same

Start 0 1
q0 q1 q2 q3

q4
Write the Transition Diagram for the same

Start 0 1 0, 1
q0 q1 q2 q3

1 0 0, 1

q4
Write the Transition Diagram for the same
Start 0 1 0, 1
q0 q1 q2 q3

1 0 0, 1

q4
Write a Transition Table
for this DFA
^
Ꟙ transition
Construct Extended Transition Function from its
function Ꟙ for the string 011101
^Ꟙ(q , ε) = q
0 0
^
Ꟙ (q , 0) = Ꟙ( ^
Ꟙ (q , ε), 0) = q
0 0 1
^
Ꟙ(q0, 01) = Ꟙ( ^Ꟙ(q0, 0), 1) = Ꟙ(q1, 1) = q2
^ ^
Ꟙ(q0, 011) = Ꟙ( Ꟙ (q0, 01), 1) = Ꟙ(q2, 1) = q3
^ (q
Ꟙ 0 , 0111) = Ꟙ( ^
Ꟙ(q0, 011), 1) = Ꟙ(q3, 1) = q2
^ (q , 01110) = Ꟙ( ^Ꟙ (q , 0111), 0) = Ꟙ(q , 0) = q
Ꟙ 0 0 2 3
^ (q , 011101) = Ꟙ( ^Ꟙ(q , 01110), 1) = Ꟙ(q , 0) = q
Ꟙ 0 0 3 2
Another Example: Write a DFA to accept all
Binary strings with length three or more that
does not contain 110

•Left as Exercise to the students


Write DFA to accept all binary strings divisible by 5
For n = 5, five states in DFA corresponding to five reminder information
as follows:
1.State q0 reached if reminder is 0. State q0 is the final state (accepting
state). It is also an initial state.
2.State q1 reaches if reminder is 1, a non-final state.
3.State q2 if reminder is 2, a non-final state.
4.State q3 if reminder is 3, a non-final state.
5.State q4 if reminder is 4, a non-final state.
Writing DFA is exercise to the students
Write DFA that accepts all Binary strings
begins with 1 and divisible by 5

• Left as an Exercise for the students


Exercises
• Give DFA’s that accepting the following strings over the
binary alphabet set.
• The set of all strings beginning with 101.
• The set of all strings containing 1101 as a substring.
• The set of all strings with exactly three consecutive 0’s.
• The set of all strings such that the number of 1’s is
even and number of 0’s is odd.
• The set of all strings not containing 110
• Set of all strings that begins with 01 and ends with 11.
Non-deterministic Finite Automata (NFA)
• NFA is a Finite Automata that takes a transition
function (Ꟙ) takes two arguments (Current state and
an input symbol) and returns zero or more states
(rather than exactly one state like in DFA)
Example: Write a Finite Automata that accepts a Binary
string containing a 1 in second last position.
Example: Write a Finite Automata that accepts a Binary
string containing a 1 in second last position.
1, 0
Start
q0 1 q1 1, 0 q2
Example: Write a Finite Automata that accepts a Binary
string containing a 1 in second last position.
1, 0
Start
q0 1 q1 1, 0 q2
Consider the Input String: 01010
Example: Write a Finite Automata that accepts a Binary
string containing a 1 in second last position.
1, 0
Start
q0 1 q1 1, 0 q2
Consider the Input String: 01010
Start 0 1 0 1 0
q0 q0 q0 q0 q0 q0
Example: Write a Finite Automata that accepts a Binary
string containing a 1 in last second last position.
1, 0
Start
q0 1 q1 1, 0 q2
Consider the Input String: 01010
Start 0 1 0 1 0
q0 q0 q0 q0 q0 q0
1
q1
0
q2 Stuck Here
Example: Write a Finite Automata that accepts a Binary
string containing a 1 in second last position.
1, 0
Start
q0 1 q1 1, 0 q2
Consider the Input String: 01010
Start 0 1 0 1 0
q0 q0 q0 q0 q0 q0
1 1
q1 q1
0 0 Success
q2 Stuck Here q2 Here
Definition of Nondeterminstic Finite Automata (NFA)
• The Five Tuple Notation for NFA is:
A = (Q, Ʃ, Ꟙ, q0, F)
Where
• Q is a Finite Set of States
• Ʃ is a finite set of input symbols
• Q0 is a member of Q, is the start state.
• F is a subset of Q, is the set of final (or accepting) states.
• Ꟙ is the transition function. It is a function that takes a state in Q and an input
symbol in Ʃ as arguments and returns a subset of Q. The difference between
DFA and NFA is in the type of value that Ꟙ returns a set of states in the case of
NFA and a single state in case of DFA.
Example: Write a Finite Automata that accepts a Binary
string containing a 1 in second last position.
1, 0
Start
q0 1 q1 1, 0 q2
This is NFA to accepts a Binary string containing a 1 in second last
position. The Transition table for this NFA is:
Ꟙ 0 1
q0 q0 q0, q1
q1 q2 q2
NFA–to–DFA Conversion
• An NFA can have zero, one or more than one move from a
given state on a given input symbol. An NFA can also have
NULL moves (moves without input symbol).
• On the other hand, DFA has one and only one move from a
given state on a given input symbol.
Steps in NFA–to–DFA Conversion
• Step 1: Convert the given NFA to its equivalent transition table
• Step 2: Create the DFA’s start state
• Step 3: Create the DFA’s transition table
• Step 4: Create the DFA’s final states
• Step 5: Simplify the DFA
• Step 6: Repeat steps 3-5 until no further simplification is possible
Step 1: Convert the given NFA to its equivalent transition table

• To convert the NFA to its equivalent transition table, we need


to list all the states, input symbols, and the transition rules.
• The transition rules are represented in the form of a matrix,
where the rows represent the current state, the columns
represent the input symbol, and the cells represent the next
state.
Step 2: Create the DFA’s start state
• The DFA’s start state is the set of all possible starting states in
the NFA.
• This set is called the “epsilon closure” of the NFA’s start state.
• The epsilon closure is the set of all states that can be reached
from the start state by following epsilon (λ) transitions.
Step 3: Create the DFA’s transition table
• The DFA’s transition table is similar to the NFA’s transition
table, but instead of individual states, the rows and
columns represent sets of states.
• For each input symbol, the corresponding cell in the
transition table contains the epsilon closure of the set of
states obtained by following the transition rules in the
NFA’s transition table.
Step 4: Create the DFA’s final states

• The DFA’s final states are the sets of states that


contain at least one final state from the NFA.
Step 5: Simplify the DFA
• The DFA obtained in the previous steps may contain unnecessary
states and transitions. To simplify the DFA, we can use the following
techniques:
• Remove unreachable states: States that cannot be reached from the
start state can be removed from the DFA.
• Remove dead states: States that cannot lead to a final state can be
removed from the DFA.
• Merge equivalent states: States that have the same transition rules
for all input symbols can be merged into a single state.
Step 6: Repeat steps 3-5 until no further simplification is possible

• After simplifying the DFA, we repeat steps 3-5 until no


further simplification is possible.
• The final DFA obtained is the minimized DFA equivalent to
the given NFA.
Example: Consider the following NFA shown in Figure below:
a, b
Start
q0 a q1 b q2

• Following are the various parameters for NFA.


• Q = { q0, q1, q2 }
• ∑ = ( a, b )
• F = { q2 }
• δ (Transition Function of NFA)
Steps in NFA–to–DFA Conversion
• Step 1: Convert the given NFA to its equivalent transition table
• Step 2: Create the DFA’s start state
• Step 3: Create the DFA’s transition table
• Step 4: Create the DFA’s final states
• Step 5: Simplify the DFA
• Step 6: Repeat steps 3-5 until no further simplification is possible
These Steps can be applied to the given NFA
• Step 1: Q’ = ɸ
• Step 2: Q’ = {q0}
• Step 3: For each state in Q’, find the states for each input symbol. Currently,
state in Q’ is q0, find moves from q0 on input symbol a and b using transition
function of NFA and update the transition table of DFA. δ’ (Transition Function
of DFA)
Contd…
• Now { q0, q1 } will be considered as a single state.
• As its entry is not in Q’, add it to Q’.
• So Q’ = { q0, { q0, q1 } }
• Now, moves from state { q0, q1 } on different input symbols are not present in
transition table of DFA, we will calculate it like:
δ’ ( { q0, q1 }, a ) = δ ( q0, a ) ∪ δ ( q1, a )
= { q0, q1 }
δ’ ( { q0, q1 }, b ) = δ ( q0, b ) ∪ δ ( q1, b ) = { q0, q2 }
• Now we will update the transition table of DFA.
• δ’ (Transition Function of DFA)
Contd…
• Now { q0, q2 } will be considered as a single state.
• As its entry is not in Q’, add it to Q’.
• So Q’ = { q0, { q0, q1 }, { q0, q2 } }
• Now, moves from state {q0, q2} on different input symbols are not
present in transition table of DFA, we will calculate it like:
δ’ ( { q0, q2 }, a ) = δ ( q0, a ) ∪ δ ( q2, a ) = { q0, q1 }
δ’ ( { q0, q2 }, b ) = δ ( q0, b ) ∪ δ ( q2, b ) = { q0 }
• Now we will update the transition table of DFA.
• δ’ (Transition Function of DFA)
Contd…
• As there is no new state generated, we are done with the conversion.
• Final state of DFA will be state which has q2 as its component, i.e., { q0, q2 }
• Following are the various parameters for DFA.
• Q’ = { q0, { q0, q1 }, { q0, q2 } }
• ∑ = ( a, b ) F = { { q0, q2 } } and transition function δ’ as shown above.
• The final DFA for above NFA has been shown in Figure below.
Exercises to the Students
Convert the Following NFAs to DFAs
Ꟙ 0 1 Ꟙ 0 1
p {p, q} {p} p {p, r} {q}
q ɸ {r} q {r, s} {p}
*r {p, r} {q} r {p, s} {r}
*s {q, r} ɸ
Ꟙ 0 1
p {p, q} {p}
q {r, s} {t}
r {p, r} {t}
*s ɸ ɸ
*t ɸ ɸ
Give NFA to accept the following languages over
{0, 1}

• The set of all strings such that containing either 101, or 110 as substring.
• The set of all strings such that every 1 is followed immediately by 00
• The set of all strings containing exactly two occurrences of 10
Epsilon–NFA (ε–NFA)
• NFA with ε transaction is known as ε–NFA.
• Example: Write NFA to accept signed integer number
• Examples for Signed integer number are:
+12, -54, 23
Formal Definition of ε-NFA
Formally we represent a ε-NFA A by A = {Q, Ʃ, Ꟙ, q0, F}
Where
• Q is a Finite Set of States
• Ʃ is a finite set of input symbols
• Q0 is a member of Q, is the start state.
• F is a subset of Q, is the set of final (or accepting) states.
• Ꟙ is the transition function. It is a function that takes a state in Q and an input
symbol in Ʃ U {ε} as arguments and returns a subset of Q. The difference
between DFA and NFA is in the type of value that Ꟙ returns a set of states in the
case of NFA and a single state in case of DFA.
Formal Definition of ε-NFA
Formally we represent a ε-NFA A by A = {Q, Ʃ, Ꟙ, q0, F}
Where
• Q is a Finite Set of States
• Ʃ is a finite set of input symbols
• Q0 is a member of Q, is the start state.
• F is a subset of Q, is the set of final (or accepting) states.
• Ꟙ is the transition function. It is a function that takes a state in Q and an input
symbol in Ʃ U {ε} as arguments and returns a subset of Q. The difference
between DFA and NFA is in the type of value that Ꟙ returns a set of states in the
case of NFA and a single state in case of DFA.
Epsilon Closure (ε Closure)
• The ε closure(P) is a set of states which are reachable
from state P on ε-transitions.
• ε-closure (P) = P, where P ∈ Q
• If there exists ε-closure (P) = {q} and 𝛿(q, ε) =r then, ε-
closure (P) = {q, r}
Example: Find ε-closure for the following Non-
deterministic finite automata (NFA) with epsilon.

• Solution:
• ε-closure (q0)= {q0,q1,q2}
• self state+ ε-reachable states.
• ε-closure (q1)= { q1,q2}
• q1 is self-state and q2 is a state obtained from q1 with epsilon input.
• ε-closure (q2)= {q2}
Minimization of DFA
• DFA minimization stands for converting a given DFA to its
equivalent DFA with minimum number of states.
• DFA minimization is also called as Optimization of DFA and
uses partitioning algorithm.
• DFA minimization is the task of transforming a given
Deterministic Finite Automaton (DFA) into an equivalent DFA
that has a minimum number of states. Here, two DFAs are
called equivalent if they recognize the same regular language.
Equivalence of States
• If two distinct states say p and q are equivalent, then we can replace
these two states by one single state that behaves like both p and q.
• We say that State p and state q are equivalent if for all strings w,
^ ^
Ꟙ (p, w) is an accepting state if and only if Ꟙ (q, w)is an accepting state
If the two states p and q are not equivalent, then we say p and q are
distinguishable.
Consider this Example
1 q4 1 q5 0, 1
q3
0
0 0 1 1
Start q 1 q1 0 q2 0
0

• In State q1, it exhibits same behavior for every input string as in state q2 and q4.
So, q1, q2, and q4 are non distinguishable states. These states are called as
equivalent states. Similarly, q0 and q3 are non distinguishable states.
Identify the Non Distinguishable States in the following Automata
Identify the Non Distinguishable States in the following Automata
B X
C X X
D X X X
E X X X
F X X X X
G X X X X X X
A B C D E F
Here,
C and E are Equivalent (non-distinguishable states)
D and F are Equivalent (non-distinguishable states)
Testing Equivalence of Regular Languages
Here ,
F.S represents -> Final State.
I.S represents -> Intermediate State
(Non-Final State)

• For the first pair of states, the resultant


states lie in F.S as a combination
• But for the pair (q2,q5) when operated
over input alphabets they lie in different
states. (i.e. one in F.S and the other in I.S).
• Conclusion – The Given Automata are not
equivalent.
Minimization of DFA Algorithm
Suppose there is a DFA D (Q, Σ, q0, δ, F) which recognizes a language L. Then the
minimized DFA D (Q’, Σ, q0, δ’, F’) can be constructed for language L as:
Step 1: We will divide Q (set of states) into two sets. One set will contain all final
states and other set will contain non-final states. This partition is called P0.
Step 2: Initialize k = 1
Step 3: Find Pk by partitioning the different sets of Pk-1. In each set of Pk-1, we will
take all possible pair of states. If two states of a set are distinguishable, we will
split the sets into different sets in Pk.
Step 4: Stop when Pk = Pk-1 (No change in partition)
Step 5: All states of one set are merged into one. No. of states in minimized DFA
will be equal to no. of sets in Pk.
Consider the following DFA shown in figure.
1 q4 1 q5 0, 1
q3
0
0 0 1 1
Start q0 1 q1 0 q2 0
Consider the following DFA shown in figure.
1 q4 1 q5 0, 1
q3
0
0 0 1 1
Start q0 1 q1 0 q2 0
• Step 1. P0 will have two sets of states. One set will contain q1, q2, q4
which are final states of DFA and another set will contain remaining states.
So P0 = { { q1, q2, q4 }, { q0, q3, q5 } }.
The Resultant Automata is

0
0 0, 1

Start 1 q1, q2, q4 1


q0, q3 q5
Check whether these two automata are equivalent or not?
Minimization of DFA
• First, Eliminate all states that are not reachable, if any.
• Partition the remaining states into blocks so that all
states in the same states must be equivalent and not
pair of states from different blocks are equivalent.
END OF FIRST PART IN
MODULE 1

You might also like