TOC 1
TOC 1
Motivation
• Automata = abstract computing devices
• Turing studied Turing Machines (= computers) before there were any real computers
• We will also look at simpler devices than Turing machines (Finite State Automata, Pushdown
Automata, . . . ), and specification means, such as grammars and regular expressions.
• NP-hardness = what cannot be efficiently computed.
• Undecidability = what cannot be computed at all.
Finite Automata
Finite Automata are used as a model for
• Software for designing digital cicuits
• Lexical analyzer of a compiler
• Searching for keywords in a file or on the web.
• Software for verifying finite state systems, such as communication protocols.
Related Terminologies
Alphabet
String
Length of a String
Kleene Star
● Definition − The set ∑+ is the infinite set of all possible strings of all possible lengths
over ∑ excluding λ.
● Representation − ∑+ = ∑1 ∪ ∑2 ∪ ∑3 ∪…….
∑+ = ∑* − { λ }
● Example − If ∑ = { a, b } , ∑+ = { a, b, aa, ab, ba, bb,………..}
Language
Example
● Q = {a, b, c},
● ∑ = {0, 1},
● q0 = {a},
● F = {c}, and
Transition function δ as shown by the following table −
Present State Next State for Input 0 Next State for Input 1
a a b
b c a
c b c
In NDFA, for a particular input symbol, the machine can move to any combination of the
states in the machine. In other words, the exact state to which the machine moves cannot
be determined. Hence, it is called Non-deterministic Automaton. As it has finite number
of states, the machine is called Non-deterministic Finite Machine or Non-deterministic
Finite Automaton.
● Q = {a, b, c}
● ∑ = {0, 1}
● q0 = {a}
● F = {c}
The transition function δ as shown below −
Present State Next State for Input 0 Next State for Input 1
a a, b b
b c a, c
c b, c c
DFA vs NDFA
The following table lists the differences between DFA and NDFA.
DFA NDFA
The transition from a state is to a single The transition from a state can be to
particular next state for each input symbol. multiple next states for each input
Hence it is called deterministic.
symbol. Hence it is
called non-deterministic.
Empty string transitions are not seen in DFA. NDFA permits empty string transitions.
An automaton that computes a Boolean function is called an acceptor. All the states of an
acceptor is either accepting or rejecting the inputs given to it.
Classifier
A classifier has more than two final states and it gives a single output when it terminates.
Transducer
An automaton that produces outputs based on current input and/or previous state is called
a transducer. Transducers can be of two types −
● Mealy Machine − The output depends both on the current state and the current
input.
● Moore Machine − The output depends only on the current state.
Strings accepted by the above DFA: {0, 00, 11, 010, 101, ...........}
Strings not accepted by the above DFA: {1, 011, 111, ........}
Problem Statement
Let X = (Qx, ∑, δx, q0, Fx) be an NDFA which accepts the language L(X). We have to design
an equivalent DFA Y = (Qy, ∑, δy, q0, Fy) such that L(Y) = L(X). The following procedure
converts the NDFA to its equivalent DFA −
Algorithm
Input − An NDFA
Output − An equivalent DFA
Step 1 − Create state table from the given NDFA.
Step 2 − Create a blank state table under possible input alphabets for the equivalent DFA.
Step 3 − Mark the start state of the DFA by q0 (Same as the NDFA).
Step 4 − Find out the combination of States {Q0, Q1,... , Qn} for each possible input alphabet.
Step 5 − Each time we generate a new DFA state under the input alphabet columns, we
have to apply step 4 again, otherwise go to step 6.
Step 6 − The states which contain any of the final states of the NDFA are the final states of
the equivalent DFA.
Example
Let us consider the NDFA shown in the figure below.
q δ(q,0) δ(q,1)
a {a,b,c,d,e} {d,e}
b {c} {e}
c ∅ {b}
d {e} ∅
e ∅ ∅
Using the above algorithm, we find its equivalent DFA. The state table of the DFA is shown
in below.
q δ(q,0) δ(q,1)
[d,e] [e] ∅
[e] ∅ ∅
[c, e] ∅ [b]
[c] ∅ [b]
Input − DFA
Output − Minimized DFA
Step 1 − Draw a table for all pairs of states (Qi, Qj) not necessarily connected directly [All
are unmarked initially]
Step 2 − Consider every state pair (Qi, Qj) in the DFA where Qi ∈ F and Qj ∉ F or vice versa
and mark them. [Here F is the set of final states]
Step 3 − Repeat this step until we cannot mark anymore states −
If there is an unmarked pair (Qi, Qj), mark it if the pair {δ (Qi, A), δ (Qi, A)} is marked for
some input alphabet.
Step 4 − Combine all the unmarked pair (Qi, Qj) and make them a single state in the
reduced DFA.
Example
a b c d e f
a b c d e f
c ✔ ✔
d ✔ ✔
e ✔ ✔
f ✔ ✔ ✔
Step 3 − We will try to mark the state pairs, with green colored check mark, transitively. If
we input 1 to state ‘a’ and ‘f’, it will go to state ‘c’ and ‘f’ respectively. (c, f) is already
marked, hence we will mark pair (a, f). Now, we input 1 to state ‘b’ and ‘f’; it will go to state
‘d’ and ‘f’ respectively. (d, f) is already marked, hence we will mark pair (b, f).
a b c d e f
c ✔ ✔
d ✔ ✔
e ✔ ✔
f ✔ ✔ ✔ ✔ ✔
After step 3, we have got state combinations {a, b} {c, d} {c, e} {d, e} that are unmarked.
We can recombine {c, d} {c, e} {d, e} into {c, d, e}
Hence we got two combined states as − {a, b} and {c, d, e}
So the final minimized DFA will contain three states {f}, {a, b} and {c, d, e}
DFA Minimization using Equivalence Theorem
If X and Y are two states in a DFA, we can combine these two states into {X, Y} if they are
not distinguishable. Two states are distinguishable, if there is at least one string S, such that
one of δ (X, S) and δ (Y, S) is accepting and another is not accepting. Hence, a DFA is
minimal if and only if all the states are distinguishable.
Algorithm 3
Step 1 − All the states Q are divided in two partitions − final states and non-final
states and are denoted by P0. All the states in a partition are 0th equivalent. Take a
counter k and initialize it with 0.
Step 2 − Increment k by 1. For each partition in Pk, divide the states in Pk into two partitions
if they are k-distinguishable. Two states within this partition X and Y are k-distinguishable if
there is an input S such that δ(X, S) and δ(Y, S) are (k-1)-distinguishable.
Step 3 − If Pk ≠ Pk-1, repeat Step 2, otherwise go to Step 4.
Step 4 − Combine kth equivalent sets and make them the new states of the reduced DFA.
Example
a b c
b a d
c e f
d e f
e e f
f f f
● P0 = {(c,d,e), (a,b,f)}
● P1 = {(c,d,e), (a,b),(f)}
● P2 = {(c,d,e), (a,b),(f)}
Hence, P1 = P2.
There are three states in the reduced DFA. The reduced DFA is as follows −
Q δ(q,0) δ(q,1)
Some RE Examples
(a+b)* Set of strings of a’s and b’s of any length including the null
string. So L = { ε, a, b, aa , ab , bb , ba, aaa…….}
(a+b)*abb Set of strings of a’s and b’s ending with the string abb. So
L = {abb, aabb, babb, aaabb, ababb, …………..}
(aa + ab + ba + bb)* String of a’s and b’s of even length can be obtained by
concatenating any combination of the strings aa, ab, ba
and bb including null, so L = {aa, ab, ba, bb, aaab, aaba,
…………..}
Regular Sets
Any set that represents the value of the Regular Expression is called a Regular
Set.
● ∅* = ε
● ε* = ε
● RR* = R*R
● R*R* = R*
● (R*)* = R*
● RR* = R*R
● (PQ)*P =P(QP)*
● (a+b)* = (a*b*)* = (a*+b*)* = (a+b*)* = a*(ba*)*
● R + ∅ = ∅ + R = R (The identity for union)
● R ε = ε R = R (The identity for concatenation)
● ∅ L = L ∅ = ∅ (The annihilator for concatenation)
● R + R = R (Idempotent law)
● L (M + N) = LM + LN (Left distributive law)
● (M + N) L = ML + NL (Right distributive law)
● ε + RR* = ε + R*R = R*
Construction of an FA from an RE
We can use Thompson's Construction to find out a Finite Automaton from a Regular
Expression. We will reduce the regular expression into smallest regular expressions
and converting these to NFA and finally to DFA.
Some basic RA expressions are the following −
Case 1 − For a regular expression ‘a’, we can construct the following FA −
Method
Step 1 Construct an NFA with Null moves from the given regular expression.
Step 2 Remove Null transition from the NFA and convert it into its equivalent DFA.
Problem
Convert the following RA into its equivalent DFA − 1 (0 + 1)* 0
Solution
We will concatenate three expressions "1", "(0 + 1)*" and "0"
Now we will remove the ε transitions. After we remove the ε transitions from the
NDFA, we get the following −
It is an NDFA corresponding to the RE − 1 (0 + 1)* 0. If you want to convert it into a
DFA, simply apply the method of converting NDFA to DFA discussed in Chapter 1.
Solution
Step 1 −
Here the ε transition is between q1 and q2, so let q1 is X and qf is Y.
Here the outgoing edges from qf is to qf for inputs 0 and 1.
Step 2 −
Now we will Copy all these edges from q1 without changing the edges from qf and
get the following FA −
Step 3 −
Here q1 is an initial state, so we make qf also an initial state.
So the FA becomes −
Step 4 −
Here qf is a final state, so we make q1 also a final state.
So the FA becomes −
Let L be a regular language. Then there exists a constant ‘c’ such that for every
string w in L −
|w| ≥ c
We can break w into three strings, w = xyz, such that −
● |y| > 0
● |xy| ≤ c
● For all k ≥ 0, the string xykz is also in L.
●
● This DFA accepts the language
● L = {a, aa, aaa , ............. }
● over the alphabet
● ∑ = {a, b}
● So, RE = a+.
● Now we will swap its accepting states with its non-accepting states and vice
versa and will get the following −
●
● This DFA accepts the language
● Ľ = {ε, b, ab ,bb,ba, ............... }
● over the alphabet
● ∑ = {a, b}
● Note − If we want to complement an NFA, we have to first convert it to DFA
and then have to swap states as in the previous method.