Theory of Computation
BCS503
Prerequisites
Module 1
Introduction to Finite Automata
• Automata theory is the core of computer science.
• It deals with the design and analysis of automata.
• An automaton (plural: automata) is a mathematical model of
computation that performs operations on an input to produce an
output, following a set of predefined rules.
• Abstract Machines in Automata Theory: Finite Automaton (FA),
Pushdown Automaton (PDA), Turing Machine (TM)
Why Study Automata?
• Automata theory presents many useful models for software and
hardware.
• In compilers we use finite automatons for lexical analyzers, and
push down automatons for parsers.
• In spell checker.
• In search engines, we use finite automatons in order to determine
tokens in web pages.
• Finite automata model protocols, electronic circuits.
• Automata theory offers many useful models for natural language
processing.
A Simple Finite Automaton – On/Off Switch
• States are represented by circles.
• Accepting (final) states are represented by double circles.
• One of the states is a starting state.
• Arcs represent external influences (inputs).
Central Concepts of Automata theory
1. Alphabet
• A finite, nonempty set of symbols.
• Symbol: Σ
Examples:
o The binary alphabet: Σ = {0, 1}
o The set of all lower-case letters: Σ = {a, b, . . . , z}
o The set of all ASCII characters
2. Strings
• A string (or sometimes a word) is a finite sequence of symbols chosen from some alphabet.
Example: 01101 and 111 are strings from the binary alphabet Σ = {0, 1}
• Empty string: The string with zero occurrences of symbols. This string is denoted by ε and may
be chosen from any alphabet whatsoever.
• Length of a string: The number of positions for symbols in the string.
Example: 01101 has length 5
- There are only two symbols (0 and 1) in the string 01101, but 5 positions for symbols.
The standard notation for the length of a string w is |w|.
Example: |011| = 3 and | ε | = 0
• Powers of an Alphabet: If Σ is an alphabet, we can express the set of all strings of a certain length
from that alphabet by using an exponential notation. Σk is the set of strings of length k, each of
whose is in Σ.
Examples:
o Σ 0 : {ε}, regardless of what alphabet Σ is. That is ε is the only string of length 0.
o If Σ = {0, 1}, then:
1. Σ1 = {0, 1}
2. Σ2 = {00, 01, 10, 11}
3. Σ3 = {000, 001, 010, 011, 100, 101, 110, 111}
o Note: confusion between Σ and Σ1 :
1. Σ is an alphabet; its members 0 and 1 are symbols.
2. Σ1 is a set of strings with members as the strings 0 and 1 of length 1.
Example:
o If Σ = {a,b,c}, then:
1.Σ1={a,b,c}
2.Σ2={aa,ab,ac,ba,bb,bc,ca,cb,cc}
3.Σ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}
o Σ*: The set of all strings over an alphabet
{0, 1}* = {ε, 0, 1, 00, 01, 10, 11, 000, . . .}
Σ* = Σ0 ∪ Σ1 ∪ Σ2 ∪ . . .
The symbol ∗ is called Kleene star.
o Σ+ = Σ1 ∪ Σ2 ∪ Σ3 ∪ . . .
o Thus Σ* = Σ+ ∪ {ε}
• Concatenation of strings
o Let x and y be strings then xy denotes the concatenation of x and y, that is, the string formed by
making a copy of x and following it by a copy of y.
o More precisely, if x is the string composed of I symbols x = a1 a2 . . . ai and y is the string composed of j
symbols y = b1 b2. . . bj , then xy is the string of length i+j: xy = a1 a2 . . . ai b1 b2. . . Bj.
o Examples:
Let x = 1101 and y = 0011
Then xy = 11010011and yx = 00111101
For any string w, the equations εw = wε = w hold.
That is, ε is the identity for concatenation (when concatenated with any string it yields the other
string as a result).
3. Languages
• A (possibly infinite) set of strings all of which are chosen from some
Σ*, where Σ is a particular alphabet, is called a language.
• If Σ is an alphabet, and L ⊆ Σ* , then L is a (formal) language over Σ.
• A language over Σ need not include strings with all symbols of Σ.
• Thus, a language over Σ is also a language over any alphabet that is a
superset of Σ .
Other language examples
1. The language of all strings consisting of n 0s followed by n 1s (n ≥ 0):
{ε, 01, 0011, 000111, . . .}
2. The set of strings of 0s and 1s with an equal number of each:
{ε, 01, 10, 0011, 0101, 1001, . . .}
3. Σ* is a language for any alphabet Σ.
4. ∅, the empty language, is a language over any alphabet.
5. {ε}, the language consisting of only the empty string, is also a language over any alphabet.
NOTE: ∅ ≠ {ε} since ∅ has no strings and {ε} has one
6. {w | w consists of an equal number of 0 and 1}
7. {0n1n | n ≥ 1}
8. {0i1j | 0 ≤ i ≤ j}
(This language consists of strings with some 0’s (possibly none) followed by at least as many 1’s.)
• Example: Let us formally specify a DFA that accepts all and only the strings of 0’s
and 1’s that have the sequence 01 somewhere in the string. We can write this
language L as:
{w | w is of the form x01y for some strings x and y consisting of 0’s and 1’s only}
• Another equivalent description, using parameters x and y to the left of the vertical
bar, is:
{x01y | x and y are any strings of 0’s and 1’s}
Finite Automata
• Finite automata or finite state machine is the simplest machine that is used for
recognizing patterns.
• It is an abstract machine that has five elements or tuples.
• It possesses a set of states and rules that are used for moving from one state to
another, but it is dependent on the applied input symbol.
• Types of Finite Automata:
o Deterministic Finite Automata
o Nondeterministic Finite Automata
Deterministic Finite Automata(DFA)
Definition:
• A deterministic finite automaton consists of:
1. A finite set of state, often denoted Q.
2. A finite set of input symbols, often denoted Σ.
3. A transition function that takes as arguments a state and an input symbol and returns a
state. The transition function will commonly be denoted δ. In our informal graph
representation of automata, δ was represented by arcs between states and the labels on
the arcs. If q is a state, and a is an input symbol, then δ (q, a) is that state p such that
there is an arc labeled a from q to p.
4. A start state, one of the states in Q.
5. A set of final or accepting states F. The set F is a subset of Q.
• A DFA is defined by the 5-tuple:
• A={Q, ∑ , δ , q0, F }
How a DFA Processes Strings
• How the DFA decides whether or not to “accept” a sequence of input symbols?
• The “language” of the DFA is the set of all strings that the DFA accepts.
• Suppose a1a2 . . . an is a sequence of input symbols.
• Start state is q0, then transition function δ, say δ(q0, a1) = q1to find the state that the DFA A
enters after processing the first input symbol a 1.
• Process the next input symbol a2, by evaluating δ(q1, a2) = q2.
δ(qi-1, ai) = qi for each i.
• If qn is a member of F, then the input a1a2 . . . an is accepted, and if not then it is “rejected”.
Simpler Notations for DFA’s
• There are two preferred notations for describing automata:
1. A transition diagram, which is a graph.
2. A transition table, which is a tabular listing of the δ function,
which by implication tells us the set of states and the input
alphabet.
1. Transition Diagrams
• A transition diagram for a DFA A = {Q, ∑ , δ , q0, F } is a graph defined as
follows:
a) For each state in Q there is a node.
b) For each state q in Q and each input symbol a in ∑, let δ (q, a) = p. Then the
transition diagram has an arc from node q to node p, labeled a. If there are several
input symbols that cause transitions from q to p, then the transition diagram can
have one arc, labeled by the list of these symbols.
c) There is an arrow into the start state q0 labeled Start. This arrow does not originate
at any node.
d) Nodes corresponding to accepting states (those in F) are marked by a double circle.
States not in F have a single circle.
• Example:
2. Transition Tables
• A transition table is a conventional, tabular representation of a
function like δ that takes two arguments and returns a value.
• The rows of the table correspond to the states, and the columns
correspond to the inputs.
• The entry for the row corresponding to state q and the column
corresponding to input a is the state δ (q, a).
• Example: Two other features of a transition table. The start state is
marked with an arrow, and the accepting states are marked with a star.
DFA Examples:
• DFA to accept empty language.
• DFA to accept exactly one ‘a’ on {a}.
• DFA to accept one ‘a’ or one ‘b’ on {a, b}.
• DFA to accept zero or more a’s on {a}.
• Draw a DFA to accept strings of a’s having at least one ‘a’.
• Draw a DFA to accept strings of a’s having even number of a’s.
• Draw a DFA to accept strings of a’s having odd number of a’s.
Contd…
• Construct DFA that accepts set of all strings over {a,b} of strings
starting with ‘a’.
• Construct DFA that accepts set of all strings over {a,b} of strings
starting with ‘ab’.
• Draw a DFA to accepts set of all strings over {0,1} of strings starting
with ‘101’.
Contd…
• Construct DFA that accepts set of all strings over {a,b} of strings ends with
“ab”.
• Construct DFA that accepts set of all strings over {0,1} of strings ends with
“00”.
• Construct DFA to accept strings of 0’s and 1’s ends with 111.
• Construct DFA to accept strings of a’s and b’s ending with abb.
• Construct DFA to accept strings of a’s and b’s which do not end with abb.
Contd…
• Construct DFA that accepts set of all strings over {a,b} of strings containing
“abb”.
• Construct DFA that accepts set of all strings over {0,1} of strings containing
“1100” as a substring.
• Construct DFA that accepts set of all string 0,1 which contain even number of 1’s.
• Construct DFA that accepts strings of a’s and b’s having substring “aab”.
• Construct DFA that accepts strings of a’s and b’s which is not having substring
“aab”.
Extending the Transition Function to Strings
• An extended transition function that describes what happens when we start
in any state and follow any sequence of inputs.
• 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 that the automaton reaches when
starting in state q and processing the sequence of inputs w.
Contd…
• We define 𝛿መ by induction on the length of the input string, as follows:
መ ε) = q, if we are in state q and read no inputs, then we are still in state q.
• BASIS: 𝛿(q,
• INDUCTION: Suppose w is a string of the form xa; that is, a is the last symbol of w, and x is the string
consisting of all but the last symbol. For example, w = 1101 is broken into x = 110 and a = 1. Then
መ w) = δ(𝛿(q,
𝛿(q, መ x),a)
መ w), first compute 𝛿(q,
• To compute 𝛿(q, መ x), the state that the automaton is in after processing all but the last
symbol of w.
መ x) = p.
• Suppose this state is p; that is 𝛿(q,
መ w) is what we get by making a transition from state p on input a, the last symbol of w. That is 𝛿(q,
• Then 𝛿(q, መ
w) = δ (p, a)
The Language of a DFA
• Now, we can define the language of a DFA A = {Q, ∑ , δ , q0, F }. This
language is denoted L(A), and is defined by
መ 0, w) is in F}
L(A) = {w| 𝛿(q
• That is, the language of A is the set of strings w that take the start state
q0 to one of the accepting states. If L is L(A) for some DFA A, then we
say L is a regular language.
Problems:
• Design a DFA that contains 01 as a substring over ∑={0,1}. Write the extended
transition function for 10001.
• Design a DFA to accept the language, L={w|w is even and begins with 01}. Write
the extended transition function for
i. 0101
ii. 1010
iii. 110
• Design a DFA to accept the language, L={w|w is odd and begins with 01}.
• L={w|w ε (a+b)n where n≥0}
Divisible by k problems
• The transitions can be obtained by using the formula
δ (qi, a)=qj
• where j=(r*i+d)mod k
• Where r → radix of input, for binary r=2
for decimal r=10
i → remainder obtained after dividing by k
d → represents digits, for binary d=0,1
k → divisor
E.g. k=3 then i={0,1,2}
Contd…
Steps to construct DFA using divisible by k method:
• Step 1: Identify the radix (r), input alphabets (d) and divisor (k).
• Step 2: Compute the possible remainders. These remainders
represents the state (i).
• Step 3: Find the transition using δ (qi, a)=qj where j=(r*i+d)mod k.
• Step 4: Construct the DFA using the transitions obtained in step 3.
Problems:
1) Construct a DFA which accepts strings of 0’s and 1’s where the value of
each string is represented as binary number. Only the strings representing
0mod5 should be accepted. Check whether the string 1111 will be
accepted or not.
• r=2, d={0,1}, k=5
• i={0,1,2,3,4} i.e. states = {q0,q1,q2,q3,q4}
• δ (qi, a)=qj , where j=(r*i+d)mod k
Remainder d (r*i+d)mod k = j δ (qi, d)=qj
i=0 d=0 (2*0+0)mod 5 = 0 δ (q0, 0)=q0
d=1 (2*0+1)mod 5 = 1 δ (q0, 1)=q1
i=1 d=0 (2*1+0)mod 5 = 2 δ (q1, 0)=q2
d=1 (2*1+1)mod 5 = 3 δ (q1, 1)=q3
i=2 d=0 (2*2+0)mod 5 = 4 δ (q2, 0)=q4
d=1 (2*2+1)mod 5 = 0 δ (q2, 1)=q0
i=3 d=0 (2*3+0)mod 5 = 1 δ (q3, 0)=q1
d=1 (2*3+1)mod 5 = 2 δ (q3, 1)=q2
i=4 d=0 (2*4+0)mod 5 = 3 δ (q4, 0)=q3
d=1 (2*4+1)mod 5 = 4 δ (q4, 1)=q4
2) Construct a DFA which accepts set of decimal strings divisible by 3.
• r=10 , d={0,1,2,3,4,5,6,7,8,9}, k=3
• i={0,1,2} i.e state = {q0,q1,q2}
Group the digits from 0-9 based on the remainders. We get after
dividing by 3 i.e.
0,3,6,9 = δ(0)
1,4,7 = δ(1)
2,5,8 = δ(2)
Remainder d (r*i+d)mod k = j δ (qi, d)=qj
i=0 0 (10*0+0)mod 3 = 0 δ (q0, 0)=q0
1 (10*0+1)mod 3 = 1 δ (q0, 1)=q1
2 (10*0+2)mod 3 = 2 δ (q0, 2)=q2
i=1 0 (10*1+0)mod 3 = 1 δ (q1, 0)=q1
1 (10*1+1)mod 3 = 2 δ (q1, 1)=q2
2 (10*1+2)mod 3 = 0 δ (q1, 2)=q0
i=2 0 (10*2+0)mod 3 = 2 δ (q2, 0)=q2
1 (10*2+1)mod 3 = 0 δ (q2, 1)=q0
2 (10*2+2)mod 3 = 1 δ (q2, 2)=q1
Modulo – k counter problem
Steps to solve:
• Step 1: Identify number of states based on the remainders.
• Step 2: Identify start and final state using problem statement.
• Step 3: Obtain transition and write DFA.
Problems:
1) Obtain a DFA to accept the language L={w:|w| mod 3 = 0 } where ∑={a}.
• No. of states :
Remainder = {0,1,2}
States = {q0,q1,q2}
• Start state = q0 , Final state = q0 (Remainder = 0)
2) Obtain a DFA to accept the language L={w:|w| mod 3 = 1 } where ∑={a,b}.
• No. of states :
Remainder = {0,1,2}
States = {q0,q1,q2}
• Start state = q0 , Final state = q1
3) Obtain a DFA to accept the language L={w:|w| mod 5 ≠ 0 } where ∑={a}.
• No. of states :
Remainder = {0,1,2,3,4}
States = {q0,q1,q2, q3, q4}
• Start state = q0 , Final state = {q1, q2, q3, q4}
4) Obtain a DFA to accept the language L= w such that
a) |w| mod 3 ≥ |w| mod 2 ∑={a}
• The remainders for mod 3 = A = {0,1,2}
• Remainders for mod 2 = B = {0,1}
• The transitions of DFA which has strings of ‘w’ with wmod3 and wmod2
can be obtained by taking cross product of ‘A’ and ‘B’.
• Therefore, the number of states are
{(A0B0), (A0B1), (A1B0), (A1B1), (A2B0), (A2B1)}
• 4) b) |w| mod 3 ≠ |w| mod 2 ∑={a}
5) Obtain a DFA to accept strings of a’s and b’s
• Having even number of a’s and even number of b’s
• Having even number of a’s and odd number of b’s
• Having odd number of a’s and even number of b’s
• Having odd number of a’s and odd number of b’s
6) Obtain a DFA to accept strings of a’s and b’s having even no. of a’s and even no. of b’s.
• The possibilities of states are
o Even no. of a’s : Ea
o Even no. of b’s : Eb
o Odd no. of a’s : Oa
o Odd no. of b’s : Ob
• Different cases of states are
o Even a’s & Even b’s: EaEb
o Even a’s & Odd b’s: EaOb
o Odd a’s & Even b’s: OaEb
o Odd a’s & Odd b’s: OaOb
a
5) Obtain a DFA to accept strings of a’s and b’s such that
L={w: Na(w)mod 3 = 0 & Nb(w) mod 2 = 0 } where ∑={a,b}
• The possibilities of states are
• {(A0B0), (A0B1), (A1B0), (A1B1), (A2B0), (A2B1)}
Assignment Questions
• Design a DFA to accept strings of a’s and b’s ending with ab or ba.
• Obtain a DFA to accept the language L={wbab|w ε {a,b}*}.
• Obtain a DFA that accepts strings of a’s and b’s with atmost 2
consecutive b’s.
• Obtain a DFA to accept strings of 0’s and 1’s starting with atleast two
0’s and ending with atleast 2 1’s.
Non- Deterministic Finite Automata(NFA)
• A “nondeterministic” finite automaton (NFA) has the power to be in
several states at once.
• This ability is often expressed as an ability to “guess” something about
its input.
• NFA stands for non-deterministic finite automata. It is easy to
construct an NFA than DFA for a given regular language.
Contd…
• The finite automata are called NFA when there exist many paths for
specific input from the current state to the next state.
• There are two or more transitions from one state to another on single
input.
• Every NFA is not DFA, but each NFA can be translated into DFA.
• NFA is defined in the same way as DFA but with the following two
exceptions, it contains multiple next states, and it contains ε transition.
An Informal View of Nondeterministic Finite Automata
• Like the DFA, an NFA has a finite set of states, a finite set of input
symbols, one start state and a set of accepting states.
• It also has a transition function, which we shall commonly call δ. The
difference between the DFA and the NFA is in the type of δ. For the
NFA, δ is a function that takes a state and input symbol as arguments,
but returns a set of zero, one, or more states.
Definition of Nondeterministic Finite Automata
• An NFA is represented essentially like a DFA:
A = {Q, ∑, δ, q0, F }
• Where:
1. Q is a finite set of states.
2. ∑ is a finite set of input symbols.
3. q0, a member of Q, is the start state.
4. F, a subset of Q, is the set of final (or accepting) states.
5. δ, the transition function is a function that takes a state in Q and an input symbol in ∑ as
arguments and returns a subset of Q.
• Notice that the only difference between an NFA and a DFA is in the type of value that δ returns: a set
of states in the case of an NFA and a single state in the case of a DFA.
The Extended Transition Function
መ
• Recursive definition of 𝛿(with string as input)
መ 0, ε) = {q}
• Basis: 𝛿(𝑞
• Induction: Suppose w is of the form w = xa, where a is the final symbol of w and x is the rest
of w. Also suppose that 𝛿መ (q, x) = {p1, p2, …, pk}. Let
ራ δ(pi,a) = {r1, r2, …, rm}
𝑖=1
• Then 𝛿መ (q, w) = {r1, r2, …, rm}.
• Compute 𝛿መ (q, w) by first computing 𝛿መ (q, x), and by then following any transition from any of
these states that is labeled a.
The Language of an NFA
• If A = {Q, ∑ , δ , q0, F } is an NFA, then
L(A) = {𝜔 | 𝛿መ 𝑞0 , 𝜔 ∩ 𝐹 ≠ ∅}
• That is, L(A) is the set of strings 𝜔 in ∑* such that 𝛿መ 𝑞0 , 𝜔 contains
at least one accepting state.
NFA Problems:
• Construct NFA which accepts all strings over an alphabet {0,1} where
strings starts with 01.
• Strings ending with 01.
• Substring 01.
• Third symbol from right end is ‘a’.
• Double ‘1’ is followed by double ‘0’.
• String containing either ’01’ or ‘10’.
• Starting with ‘1’ and ends with ‘0’.
• L = {0m1n|m≥0 and n ≥ 1}
• (ab)n with n ≥ 1
• (ab)n with n ≥ 0
• NFA to recognize the following set of strings abc, abd and aacd.
Equivalence of Deterministic and Nondeterministic Finite
Automata
• Every NFA can be turned into an equivalent DFA. The basic idea is that when a
transition results in a set of states, we treat the set as one state in the equivalent
DFA.
• Conversion from NFA to DFA
1. Subset construction method
2. Lazy evaluation method
Conversion from NFA to DFA using subset construction method:
• Consider an NFA N = (QN, ∑, δN, q0, FN) we construct an equivalent DFA, D = (QD, ∑,
δD, q0, FD) such that L(D) = L(N).
• The input alphabets of the two automata are the same.
• The start state of D is the set containing only the start state of N.
• The other components of D are constructed as follows.
• QD is the set of subsets of QN i.e., QD is the power set of QN.
• FD is the set of subsets S of QN such that S ∩FN ≠ 𝜙. That is, FD is all sets of N’s
states that include at least one accepting state of N.
• For each set S ⊆ QN and for each input symbol a in ∑,
δD(S,a) = ሪ𝑃 ⅈ𝑛 𝑆 δN(P,a)
THEOREM 1: If D = {QD, ∑, δD, {q0}, FD} is the DFA constructed from NFA N =
{QN, ∑, δN, q0, FN} by the subset construction, then L(D) = L(N).
• Proof: What we actually prove first, by induction on |w|, is that
𝛿መ𝐷 ({q0},w) = 𝛿መ𝑁 (q0,w)
• Basis: Let |w| = 0; that is, w = ε. By the basis definitions of 𝛿መ for DFA’s and NFA’s,
both 𝛿መ D ({q0}, ε) and 𝛿መ N ({q0}, ε) are {q0}.
• Induction: Let w = xa, where ‘a’ is the final symbol of w. By the inductive
hypothesis, 𝛿መ𝐷 ({q0},x) = 𝛿መ𝑁 (q0,x). Let both these sets of N’s states be {p1,p2,…..,pk}.
Contd…
• The inductive part of the definition of 𝛿መ for NFA’s tells us
𝑵 (q0,w) = ሪ𝒌 δN(pi,a) ……….. (1)
𝜹 𝒊=𝟏
• The subset construction, on the other hand, tells us that
𝒌
δD({p1,p2,…..,pk},a) = ሪ𝒊=𝟏 δN(pi,a) ……….. (2)
• The definition of 𝛿መ for DFA tells us
D({q0},x) = {p1,p2,…..,pk} ……….. (3)
𝜹
𝛿መ D({q0},w) = δD (𝛿መ D({q0},x),a)
= δD({p1,p2,…..,pk},a) by (3)
𝑘
= ሪ𝑖=1 δN(pi,a) by (2)
𝛿መ D({q0},w) = 𝛿መ N({q0},w) by (1)
Therefore, DFA and NFA both accept w if and only if 𝛿መ D({q0},w) and 𝛿መ N(q0,w) contain a state in FN.
Therefore, L(D) = L(N)
Lazy Evaluation Method for converting NFA to DFA
• Problems: Convert the following NFA to DFA
1.
2.
Epsilon- NFA
• A transition with an empty input string is called as ε – transition.
• Definition of ε-NFA: (Finite Automata with ε – transition)
It is defined by a 5 tuple A = {Q, ∑, δ, q0, F},
Where:
Q → set of states.
∑ → set of non-empty finite input symbols.
q0 → member of Q, is the start state.
F, a subset of Q, is the set of final (or accepting) states.
δ → δ: Q × (∑ ∪ ε) → 2Q
Based on the current state there can be a transition to other states with or
without any input symbol.
• Eg:
Epsilon-Closure
• The ε-closure of any state Q, or ECLOSE of Q, is the set of all states
which are reachable from Q on ε transitions.
• It is defined recursively as
State q is in ECLOSE(q), i.e., ECLOSE(q) = q.
If ECLOSE(q) contains ‘p’ and if there is a transition from state ‘p’ to state ‘r’
labelled ε then state ‘r’ is also in ECLOSE(q).
Extended Transition Function to ε-NFA
• It is defined as δ: Q × (∑ ∪ ε) → 2Q
Basis: 𝛿መ (q, ε) = ECLOSE(q)
Induction: Let w = xa and states of machine be {p1,p2,…..,pk} i.e.,
𝛿መ (q, x) = {p1,p2,…..,pk}
Let the transition from p1,p2,…..,pk on ‘a’ is
δ({p1,p2,…..,pk} ,a} = δ(p1,a) ∪δ(p2,a) ∪….. δ(pk,a)
={r1,r2,…..,rm}
Now, 𝛿መ (q, w) = ECLOSE(r1,r2,…..,rm)
= ECLOSE(r1) ∪ECLOSE(r2) ∪ECLOSE(r3)….. ∪ECLOSE(rk)
• Example: Obtain an ε-NFA which accepts strings consisting of zero or
more a’s followed by zero or more b’s followed by zero or more c’s.
Thus, an ε-NFA is given by A = (Q, ∑, δ, q0, F) where
• Q = {q0, q1, q2}
• ∑ = {a,b,c}
• q0 is start state
• F = {q2}
• δ is shown below using the transition table:
δ a b c ε
→ q0 q0 𝜑 𝜑 q1
q1 𝜑 q1 𝜑 q2
* q2 𝜑 𝜑 q2 𝜑
Conversion from ε-NFA to DFA
• Compute ECLOSE() of all states.
• If q0 is the start state of NFA then ECLOSE(q0) is start state of DFA.
• Compute the transitions table for given NFA.
• Compute the transitions table for DFA using step 1 and step 3.
• Construct transition diagram of DFA.
Problems:
1) Convert the following NFA to its equivalent DFA.
2) Convert the following NFA to its equivalent DFA.
3) Convert the following NFA to its equivalent DFA.
4) Convert the following NFA to its equivalent DFA.
5) Convert the following NFA to its equivalent DFA.
Equivalence and Minimization of Automata
• An important consequence is that there is a way to minimize a DFA.
• That is, we can take any DFA and find an equivalent DFA that has the
minimum number of states.
• In fact, this DFA is essentially unique: given any two minimum state
DFA’s that are equivalent, we can always find a way to rename the
states so that the two DFA’s become the same.
• The decision properties of regular languages give us algorithms for
deciding whether two automata define the same language.
• If the two automata accept the same language, we can minimize the
automata that have as few states as possible.
• The minimization of FA is very important in the design of switching
circuits.
• This is because, as the number of states of the automaton implemented
by the circuit decreases, the cost of the circuit tends to decrease.
Equivalence of two states
• The language generated by DFA is unique. But, there can exist many DFA’s that
accept the same language.
• In such cases, the DFA’s are said to be equivalent. During computations, it is
desirable to represent the DFA with fewer states since the space is proportional to
the number of states of DFA.
• For storage efficiency, it is required to reduce the number of states and hence it is
required to minimize the DFA. This can be achieved first by finding the
distinguishable and indistinguishable states.
Contd.
Definition: Two states p and q of DFA are equivalent (indistinguishable) if and only if δ(p,w)
and δ(q,w) are final states or both δ(p,w) and δ(q,w) are non-final states for all w ∈ ∑* i.e. if
δ(p,w) ∈ F and δ(q,w) ∈ F
then the states p and q are indistinguishable. If
δ(p,w) ∉ F and δ(q,w) ∉ F
then also the states p and q are indistinguishable.
If there is at least one string w such that one of δ(p,w) and δ(q,w) is final state and the other
is non-final state, then the states p and q are not equivalent and are called distinguishable
states.
• Note: the distinguishable and indistinguishable states can be obtained using table-filling algorithm
(also called mark procedure).
Table Filling Algorithm
• It is used to find the set of states that are distinguishable and indistinguishable states.
The algorithm is recursively defined as shown below:
• Step 1: Identify the initial markings: For each pair (p,q) where p ∈ Q and q ∈ Q, if p ∈
F and q ∉ F or vice versa then, the pair (p,q) is distinguishable and mark the pair (p,q).
• Step 2: Identify the subsequent markings: For each pair (p,q) and for each a ∈ ∑, find
δ(p,a) = r and δ(q,a) = s. if the pair (r,s) is already marked as distinguishable then the
pair (p,q) is also distinguishable and mark it as say ‘×’. Repeat step 2 until no
previously unmarked pairs are marked.
Note: if the pair (p,q) obtained using the above table filling algorithm are indistinguishable then the two states
p and q are equivalent and they can be merged into one state thus minimizing the states of DFA.
Minimization of DFA (Algorithm or Procedure)
• Once we have found the distinguishable and indistinguishable pairs we can easily minimize the
number of states of a DFA and accepting the same language as accepted by original DFA.
• The algorithm to minimize the DFA is shown below:
• Step1: Find the distinguishable and indistinguishable pairs: using the table-filling algorithm.
• Step2: Obtain the states of minimized DFA: These groups consist of indistinguishable pairs
obtained in previous step and individual distinguishable states. The groups obtained are the
states of minimized DFA.
Contd.
• Step3: Compute the transition table: If [p1,p2,…..,pk] is a group and if
δ([p1,p2,…..,pk],a) = [r1,r2,…..,rm] then place an edge from the group
[p1,p2,…..,pk] to the group [r1,r2,…..,rm] and label the edge with the symbol a.
follow this procedure for each group obtained in step 2 and for each a ∈ ∑.
• Step4: Identify the start state: If one of the component in the group [p1,p2,…..,pk]
consists of a start state of given DFA then [p1,p2,…..,pk] is the start state of
minimized DFA.
• Step5: Identify the final state: If the group [p1,p2,…..,pk] contains a final state of
given DFA then the group [p1,p2,…..,pk] is final state of minimized DFA.
Problem 1:
δ a b
B
→ A B F
C X X
B G C
D X
* C A C
D C G
E X
E H F F X
F C G G X
G G E H X
H G C A B C D E F G
δ a b δ a b
AB BG FC DE CH GF
AD BC FG DF CC GG B X
AE BH FF DG CG GE C X X
AF BC FG DH CG GC
D X X X
AG BG FE EF HC FG
AH BG FC EG HG FE E X X X
BD GC CG EH HG FC F X X X X
BE GH CF FG CG GE G X X X X X X
BF GC CG FH CG GC
H X X X X X X
BG GG CE GH GG EC
BH GG CC A B C D E F G
.
.
.
δ a b
AE BH FF
AG BG FE
BH GG CC
DF CC GG
• Indistinguishable pairs: (A,E), (B,H) and (D,F)
• Distinguishable pairs: C and G
Minimizing DFA: the DFA can be minimized as shown below
Step 1: Find the distinguishable and indistinguishable pairs
(A,E), (B,H) and (D,F) are indistinguishable
C, G are distinguishable
Step 2: Obtain the states of minimized DFA: The states of the minimized DFA
(A,E), (B,H), C, (D,F), G
Step 3: Compute the transition table: Use the transition table of given DFA and obtain the transitions for the
minimized DFA as shown below δ a b
→ (A,E) (B,H) (D,F)
(B,H) G C
* C (A,E) C
(D,F) C G
G G (A,E)
Step 4: Identify the start state: Since the group (A,E) has the start state of DFA,
the group (A,E) is the start state of minimized DFA.
Step 5: Identify the final state. The group C is the final state of given DFA. So,
C will be the final state of minimized DFA. The transition diagram of the
minimized DFA is shown below
• Problem 2:
δ a b
→ q0 q1 q3
q1 q2 q4
q2 q1 q4
q3 q2 q4
* q4 q4 q4
δ a b
q1 (q0,q1) (q1,q2) (q3,q4)
q2 (q0,q2) (q1,q1) (q3,q4)
q3 (q0,q3) (q1,q2) (q3,q4)
q4 X X X X (q1,q2) (q2,q1) (q4,q4)
q0 q1 q2 q3 (q1,q3) (q2,q2) (q4,q4)
(q2,q3) (q1,q2) (q4,q4)
q1 X
δ a b
q2 X (q1,q2) (q2,q1) (q4,q4)
q3 X (q1,q3) (q2,q2) (q4,q4)
q4 X X X X (q2,q3) (q1,q2) (q4,q4)
q0 q1 q2 q3
• (q1,q2), (q1,q3), (q2,q3) => (q1,q2,q3) are indistinguishable groups.
• q0 and q4 are distinguishable states.
• So, various groups that represent the states of minimized DFA are:
q0, (q1,q2,q3), q4
• The minimized transition table shown below. Note that the start state of original DFA is the
start state of minimized DFA and the group which consists of a final state of original SFA
is the final state of minimized DFA.
δ a b
q0 (q1,q2,q3) (q1,q2,q3)
(q1, q2,q3) (q1,q2,q3) q4
q4 q4 q4
Problem 3:
B
C X X
D X
E X
F X X X X
G X X
H X X
I X X X X X X
A B C D E F G H
δ a b δ a b
(A,B) (B,C) (E,F) (D,E) (E,F) (H,I)
(A,D) (B,E) (E,H) (D,G) (E,H) (H,B) B X
(A,E) (B,F) (E,I) (D,H) (E,I) (H,C)
(A,G) (B,H) (E,B) (E,G) (F,H) (I,B) C X X
(A,H) (B,I) (E,C) (E,H) (F,I) (I,C) D X X
(B,D) (C,E) (F,H) (F,I) (G,A) (B,E)
(B,E) (C,F) (F,I) (G,H) (H,I) (B,C)
E X X X
(B,G) (C,H) (F,B) F X X X X
(B,H) (C,I) (F,C)
(C,F) (D,G) (H,B)
G X X X X
(C,I) (D,A) (H,E) H X X X X X
I X X X X X X
.
.
A B C D E F G H
.
• Indistinguishable pairs: (A,D)(A,G)(D,G) = (A,D,G)
• (B,E)(B,H)(E,H) = (B,E,H)
• (C,F)(C,I)(F,I) = (C,F,I)
• Distinguishable states: does not exist
δ a b
→ (A,D,G) (B,E,H) (B,E,H)
(B,E,H) (C,F,I) (C,F,I)
* (C,F,I) (A,D,G) (B,E,H)