Automata Theory Tutorial
Automata Theory Tutorial
This is a brief and concise tutorial that introduces the fundamental concepts of
Finite Automata, Regular Languages, and Pushdown Automata before moving
onto Turing machines and Decidability.
Audience
This tutorial has been prepared for students pursuing a degree in any
information technology or computer science related field. It attempts to help
students grasp the essential concepts involved in automata theory.
Prerequisites
This tutorial has a good balance between theory and mathematical rigor. The
readers are expected to have a basic understanding of discrete mathematical
structures.
All the content and graphics published in this e-book are the property of
Tutorials Point (I) Pvt. Ltd. The user of this e-book is prohibited to reuse, retain,
copy, distribute or republish any contents or a part of contents of this e-book in
any manner without written consent of the publisher.
We strive to update the contents of our website and tutorials as timely and as
precisely as possible, however, the contents may contain inaccuracies or errors.
Tutorials Point (I) Pvt. Ltd. provides no guarantee regarding the accuracy,
timeliness or completeness of our website or its contents including this tutorial.
If you discover any errors on our website or in this tutorial, please notify us at
[email protected]
i
Automata Theory
Table of Contents
About this Tutorial ..................................................................................................................................... i
Audience .................................................................................................................................................... i
Prerequisites .............................................................................................................................................. i
1. INTRODUCTION..................................................................................................................... 1
ii
Automata Theory
Grammar ................................................................................................................................................ 18
Definition ................................................................................................................................................ 67
iv
Automata Theory
7. DECIDABILITY ...................................................................................................................... 76
v
1. INTRODUCTION Automata Theory
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
Automata Theory
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 λ.
Representation: Σ+ = Σ1 U Σ2 U Σ3 U…….
Σ+ = Σ* − { λ }
Language
Definition : A language is a subset of Σ* for some alphabet Σ. It can be
finite or infinite.
2
Automata Theory
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:
3
Automata Theory
1 0
a b c
1 0
1
0
q0 is the initial state from where any input is processed (q0 ∈ Q).
4
Automata Theory
Example
Let a non-deterministic finite automaton be
Q = {a, b, c}
Σ = {0, 1}
q0 = {a}
F={c}
The transition function as shown below:
1 0
a b c
0, 1 0, 1
0 0, 1
DFA vs NDFA
The following table lists the differences between DFA and NDFA.
DFA NDFA
5
Automata Theory
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.
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.
δ*(q0, S) ∈ F
6
Automata Theory
{S | S ∈ Σ* and δ*(q0, S) ∈ F}
δ*(q0, S′) ∉ F
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, ........}
Algorithm 1
Input: An 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 Algorithm 1, we find its equivalent DFA. The state table of the DFA is
shown in below.
q δ(q,0) δ(q,1)
[a] [a,b,c,d,e] [d,e]
[a,b,c,d,e] [a,b,c,d,e] [b,d,e]
[d,e] [ e] ∅
[b,d,e] [c,e] [ e]
[ e] ∅ ∅
[c,e] ∅ [b]
[b] [ c] [ e]
[ 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]
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]
9
Automata Theory
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 d f
0
0 0 1
1
a c e
1 0
0
a b c d e f
a
b
c
d
e
f
Step 2 : We mark the state pairs:
a b c d e f
a
b
c ✓ ✓
d ✓ ✓
e ✓ ✓
f ✓ ✓ ✓
10
Automata Theory
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.
So the final minimized DFA will contain three states {f}, {a, b} and {c, d, e}
0, 1
0
1
(a, b) (c, d, e)
(f)
0, 1
==========
11