CS-501 TOC Notes
CS-501 TOC Notes
TOC NOTES
Theory of Computation (CS-501)
The term "Automata" is derived from the Greek word "αὐτόματα" which means "selfacting".
An automaton (Automata in plural) is an abstract self-propelled computing device which
follows a predetermined sequence of operations automatically.
An automaton with a finite number of states is called a Finite Automaton (FA) or Finite
State Machine (FSM).
• q0 is the initial state from where any input is processed (q0 ∈ Q).
• F is a set of final state/states of Q (F ⊆ Q).
Related Terminologies
Alphabet
• Definition: An alphabet is any finite set of symbols.
• Example: Σ = {a, b, c, d} is an alphabet set where ‘a’, ‘b’, ‘c’, and ‘d’ are
symbols.
String
• 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|).
1
Theory of Computation (CS-501)
• Examples:
o 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 λ.
• Example: If Σ = {a, b}, Σ*= {λ, a, b, aa, ab, ba, bb, ........... }
• Representation: Σ+ = Σ1 U Σ2 U Σ3 U…….
Σ+ = Σ* − { λ }
Language
• Definition : A language is a subset of Σ* for some alphabet Σ. It can be finite or
infinite.
• Example : If the language takes all possible strings of length 2 over Σ = {a, b},
then L = { ab, bb, ba, bb}
2
Theory of Computation (CS-501)
• q0 is the initial state from where any input is processed (q0 ∈ Q).
• F is a set of final state/states of Q (F ⊆ Q).
Example
Let a deterministic finite automaton be
• Q = {a, b, c},
• Σ = {0, 1},
• q0={a},
• F={c}, and
3
Theory of Computation (CS-501)
1 0
a b
1 0
1
0
4
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
Nondeterministic Finite Automaton.
• q0 is the initial state from where any input is processed (q0 ∈ Q).
Example
Let a non-deterministic finite automaton be
• Q = {a, b, c}
• Σ = {0, 1}
5
Theory of Computation (CS-501)
• q0 = {a}
• F={c}
b c a, c
c b, c c
1 0
a b
0, 1 0, 1
0 0, 1
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 multiple next states for each input symbol.
symbol. Hence it is called deterministic. Hence it is called non-deterministic.
6
Theory of Computation (CS-501)
Acceptor (Recognizer)
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.
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.
S) ∈ F
{S | S ∈ Σ* and δ*(q0, S) ∈ F}
S′) F
7
Theory of Computation (CS-501)
Example
Let us consider the DFA shown in Figure 1.3. From the DFA, the acceptable strings can be
derived.
0
1
a c
0 1
1
d
0
Strings accepted by the above DFA: {0, 00, 11, 010, 101, .. ........ }
Strings not accepted by the above DFA: {1, 011, 111, ........ }
8
Theory of Comp
Auuttaotm
ioa
nta
(CTSh-eo
50ry
1)
4. NDFA to DFAConversion
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 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}
Using the above algorithm, we find its equivalent DFA. The state table of the DFA is shown
in below.
q δ(q,0) δ(q,1)
9
Theory of Computation (CS-501)
[d,e] [e]
[e]
[c,e] [b]
[c] [b]
1 0
[a,b,c,d,e] [b,d,e] [c,e]
0 1
1 [b]
[a]
1 1 1
0
0
[d,e] [e] [c]
Algorithm
Input DFA
10
Theory of Comp
Auuttaotm
ioa
nta
(CTSh-eo
50ry
1)
5. DFA Minimization
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
Let us use Algorithm 2 to minimize the DFA shown below.
0, 1
1 1
b f
0
0 0 1
1
a e
1 0
0
11
Theory of Computation (CS-501)
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
a
b
c ✓ ✓
d ✓ ✓
e ✓ ✓
f ✓ ✓ ✓ ✓ ✓
After step 3, we have got state combinations {a, b} {c, d} {c, e} {d, e} that are unmarked.
Automata Theory
12
Theory of Computation (CS-501)
So the final minimized DFA will contain three states {f}, {a, b} and {c, d, e}
0 0, 1
1
(a, (c, d, e)
(f
0, 1
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.
13
Theory of Computation (CS-501)
Example
Let us consider the following 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) 0
0, 1 1
(a, b) (a, b) (c,d,e) (a, (c, d, e)
Finite automata may have outputs corresponding to each transition. There are two types
of finite state machines that generate output:
Mealy Machine
A Mealy Machine is an FSM whose output depends on the present state as well as the
present input.
14
Theory of Comp
Auuttaotm
ioa
nta
(CTSh-eo
50ry
1)
6. Moore and Mealy Machines
a b 𝑥1 c 𝑥1
b b 𝑥2 d 𝑥3
c d 𝑥3 c 𝑥1
d d 𝑥3 d 𝑥2
0
0 /x 3, 1
b
0 1
Moore Machine
Moore machine is an FSM whose outputs depend on only the present state.
15
Theory of Computation (CS-501)
• q0 is the initial state from where any input is processed (q0 ∈ Q).
a b c 𝑥2
b b d 𝑥1
c c d 𝑥2
d d d 𝑥3
16
Theory of Computation (CS-501)
0, 1
b/x1
0 1
d
a/x2 /x3
1 c/x2 0
Output depends both upon present Output depends only upon the present
state and present input. state.
Generally, it has fewer states than Generally, it has more states than Mealy
Moore Machine. Machine.
Algorithm 4
Input: Moore Machine
Output: Mealy Machine
Step 2 Copy all the Moore Machine transition states into this table format.
Step 3 Check the present states and their corresponding outputs in the Moore
Machine state table; if for a state Qi output is m, copy it into the output
columns of the Mealy Machine state table wherever Qi appears in the next
state.
17
Theory of Computation (CS-501)
Example
Let us consider the following Moore machine:
Next State
Present
a=0 a=1 Output
State
a d b 1
b a d 0
c c c 0
d b a 1
State table of a Moore Machine
Step 1 & 2:
Next State
a=0 a=1
Present State State Output State Output
a d b
b a d
c c c
d b a
18
Theory of Computation (CS-501)
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 Qi. 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
a=0 a=1
State
Next Next
Output Output
State State
a d 0 b 1
b a 1 d 0
c c 1 c 0
d b 0 a 1
State table of a Mealy Machine
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.
19
20