Automata Theory 2
Automata Theory 2
Related Terminologies
Alphabet
Definition − An alphabet is any finite set of symbols.
String
Page 1 of 17
Definition − A string is a finite sequence of symbols taken from
∑.
Length of a String
Definition − It is the number of symbols present in a string.
(Denoted by |S|).
Examples −
If S = ‘cabcad’, |S|= 6
Kleene Star
Definition
The Kleene star, ∑*, is a unary operator on a set of symbols or
strings, ∑, that gives the infinite set of all possible strings
of all possible lengths over ∑ including λ.
Representation − ∑+ = ∑1 ∪ ∑2 ∪ ∑3 ∪…….
∑+ = ∑* − { λ }
Page 2 of 17
Language
Definition − A language is a subset of ∑* for some alphabet ∑.
It can be finite or infinite.
Page 3 of 17
The vertices represent the states.
The arcs labeled with an input alphabet show the transitions.
The initial state is denoted by an empty single incoming arc.
The final state is indicated by double circles.
Example
Let a deterministic finite automaton be →
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
Page 4 of 17
Formal Definition of an NDFA
An NDFA can be represented by a 5-tuple (Q, ∑, δ, q0, F) where −
Q is a finite set of states.
∑ is a finite set of symbols called the alphabet.
δ is the transition function where δ: Q × ∑ → 2Q
(Here the power set of Q (2 Q) has been taken because in case
of NDFA, from a state, transition can occur to any
combination of Q states)
(q0 ∈ Q).
q0 is the initial state from where any input is processed
a a, b b
b c a, c
c b, c c
Its graphical representation would be as follows −
Page 5 of 17
DFA vs NDFA
The following table lists the differences between DFA and NDFA.
DFA NDFA
In NDFA, backtracking is
Backtracking is allowed in DFA
not always possible.
A string is accepted by a
A string is accepted by a DFA,
NDFA, if at least one of
if it transits to a final
all possible transitions
state.
ends in a final state.
Page 6 of 17
Acceptability by DFA and NDFA
A string is accepted by a DFA/NDFA iff the DFA/NDFA starting at
the initial state ends in an accepting state (any of the final
states) after reading the string wholly.
δ*(q0, S) ∈ F
A string S is accepted by a DFA/NDFA (Q, ∑, δ, q0, F), iff
{S | S ∈ ∑* and δ*(q0, S) ∈ F}
The language L accepted by DFA/NDFA is
δ*(q0, S′) ∉ F
A string S′ is not accepted by a DFA/NDFA (Q, ∑, δ, q0, F), iff
{S | S ∈ ∑* and δ*(q0, S) ∉ F}
language L) is
Example
Let us consider the DFA shown in Figure 1.3. From the DFA, the
acceptable strings can be derived.
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.
Page 7 of 17
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)
Page 8 of 17
[d,e] [e] ∅
[e] ∅ ∅
[c, e] ∅ [b]
[c] ∅ [b]
The state diagram of the DFA is as follows −
DFA Minimization
Page 9 of 17
Step 1 − Draw a table for all pairs of states (Q i, Qj) not
Step 2 − Consider every state pair (Qi, Qj) in the DFA where Qi ∈
necessarily connected directly [All are unmarked initially]
f
Step 2 − We mark the state pairs.
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
Page 10 of 17
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}
Page 11 of 17
Example
Let us consider the following DFA −
q δ(q,0) δ(q,1)
a b c
b a d
c e f
d e f
e e f
f f f
Let us apply the above algorithm to the above DFA −
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)
(q0 ∈ Q).
q0 is the initial state from where any input is processed
→ a b x1 c x1
b b x2 d x3
c d x3 c x1
d d x3 d x2
The state diagram of the above Mealy Machine is −
Moore Machine
Moore machine is an FSM whose outputs depend on only the present
state.
A Moore machine can be described by a 6 tuple (Q, ∑, O, δ, X, q 0)
where −
Q is a finite set of states.
∑ is a finite set of symbols called the input alphabet.
O is a finite set of symbols called the output alphabet.
δ is the input transition function where δ: Q × ∑ → Q
Page 13 of 17
X is the output transition function where X: Q → O
(q0 ∈ Q).
q0 is the initial state from where any input is processed
→ a b c x2
b b d x1
c c d x2
d d d x3
The state diagram of the above Moore Machine is −
Page 14 of 17
the transitions and the the current state and the
changes, when the input changes at the clock edges,
logic on the present state whenever state changes
is done. occur.
→ a d b 1
b a d 0
c c c 0
d b a 1
Now we apply Algorithm 4 to convert it to Mealy Machine.
Step 1 & 2 −
Present State Next State
a = 0 a = 1
Page 15 of 17
State Output State Output
→ a d b
b a d
c c c
d b a
Step 3 −
Next State
Present State a = 0 a = 1
=> a d 1 b 0
b a 1 d 1
c c 0 c 0
d b 0 a 1
Mealy Machine to Moore Machine
Algorithm 5
Input − Mealy Machine
Output − Moore Machine
Step 1 − Calculate the number of different outputs for each
state (Qi) that are available in the state table of the Mealy
machine.
Step 2 − If all the outputs of Qi are same, copy state Q i. If it
has n distinct outputs, break Qi into n states as Qin where n = 0,
1, 2.......
Step 3 − If the output of the initial state is 1, insert a new
initial state at the beginning which gives 0 output.
Example
Let us consider the following Mealy Machine −
Next State
Present State a = 0 a = 1
Page 16 of 17
→ a d 0 b 1
b a 1 d 0
c c 1 c 0
d b 0 a 1
Here, states ‘a’ and ‘d’ give only 1 and 0 outputs respectively,
so we retain states ‘a’ and ‘d’. But states ‘b’ and ‘c’ produce
different outputs (1 and 0). So, we divide b into b0,
b1 and c into c0, c1.
Next State
Present State Output
a = 0 a = 1
→ a d b1 1
b0 a d 0
b1 a d 1
c0 c1 C0 0
c1 c1 C0 1
d b0 a 0
Page 17 of 17