Professional Documents
Culture Documents
Module 1
Session 1
1
Module 1 Syllabus
FINITE AUTOMATA:
Central concepts of automata theory,
deterministic finite automata, non-deterministic
finite automata, finite automata with epsilon
transitions, Moore and Mealy machines.
2
Contents
Introduction
What is AT
Basic Concepts of AT
Applications of FLAT
Components of Automata
Classification of Automata
3
What is Automata Theory?
Study of abstract computing devices, or
“machines”
Automaton = an abstract computing device
Note: A “device” need not even be a physical
hardware!
A fundamental question in computer science:
Find out what different models of machines can do
and cannot do
The theory of computation
Computability vs. Complexity
4
Basic Concepts of
Automata Theory
Automaton: a formal construct that accepts input,
produces output, may have some temporary storage,
and can make decisions
Formal Language: a set of sentences formed from a set
formal language
In addition, the theory of computation is concerned with
questions of computability (the types of problems
computers can solve in principle) and complexity (the types
of problems that can solved in practice).
5
(A pioneer of automata theory)
6
Theory of Computation: A
Historical Perspective
1930s • Alan Turing studies Turing machines
• Decidability
• Halting problem
1940-1950s • “Finite automata” machines studied
• Noam Chomsky proposes the
“Chomsky Hierarchy” for formal
languages
1969 Cook introduces “intractable” problems
or “NP-Hard” problems
1970-1980s Modern computer science: compilers,
computational & complexity theory evolve
7
Languages & Grammars
Languages: “A language is a
Or “words” collection of sentences of
finite length all constructed
from a finite alphabet of
symbols”
Grammars: “A grammar can
be regarded as a device that
enumerates the sentences
of a language” - nothing
more, nothing less
Regular Context-
(DFA) Context- Recursively-
free
sensitive enumerable
(PDA)
(LBA) (TM)
9
The Central Concepts of
Automata Theory
10
Alphabet
An alphabet is a finite, non-empty set of
symbols
We use the symbol ∑ (sigma) to denote an
alphabet
Examples:
Binary: ∑ = {0,1}
All lower case letters: ∑ = {a,b,c,..z}
Alphanumeric: ∑ = {a-z, A-Z, 0-9}
DNA molecule letters: ∑ = {a,c,g,t}
…
11
Strings
A string or word is a finite sequence of symbols
chosen from ∑
Empty string is (or “epsilon”)
13
Powers of an alphabet
Let ∑ be an alphabet.
∑* = ∑0 U ∑1 U ∑2 U …
∑ + = ∑ 1 U ∑ 2 U ∑3 U …
Example:
Let w = 100011
Q) Is w the language of strings with
equal number of 0s and 1s?
18
Finite Automata
Some Applications
Software for designing and checking the behavior
of digital circuits
Lexical analyzer of a typical compiler
Software for scanning large bodies of text (e.g.,
web pages) for pattern finding
Software for verifying systems of all types that
have a finite number of states (e.g., stock market
transaction, communication/network protocol)
19
Finite Automata : Examples
action
On/Off switch state
22
Automata Components
23
Automata Components
Storage: consists of an unlimited number of cells.
24
Automata Components
Control unit: has a finite number of internal states.
25
Automata Components
Transition function:
current state input symbol storage info next state
26
Classification of Automata
General types of automata:
27
Finite Automata
Module 1
Session 2
28
Contents
Examples of DFA
29
Finite State Automata (FSA)
30
Finite State Automaton (FSA)
Informally, a state diagram that comprehensively
captures all possible states and transitions that a
machine can take while responding to a stream or
sequence of input symbols
Recognizer for “Regular Languages”
31
Deterministic Finite Automata
- Definition
A Deterministic Finite Automaton (DFA)
defined by the 5-tuple: {Q, ∑ , q0,F, δ }
Where,
Q ==> a finite set of states
between Q x ∑ ==> Q
32
Representation of FSA
Two ways:
Graph Representation
Transition Table Representation
33
Graph Representation of
DFA’s
Self Loop
34
Graph Representation of
DFA’s
Nodes = states.
Arcs represent transition function.
Arc from state p to state q labelled by all
those input symbols that have
transitions from p to q.
Arrow labelled “Start” to the start state.
Final states indicated by double circles.
35
Transition Diagram
Representation
FSA which accepts a binary string with
odd number of 1’s.
36
Transition Table Representation
Tabular Representation of δ function.
Takes two inputs and produce one output.
Rows represent states and columns
represent the input symbols of ∑.
Corresponding value of row & column
gives the new output state.
37
Transition Table Representation
Example
FSA which accepts a binary string with odd
number of 1’s.
38
What does a DFA do on
reading an input string?
Input: a word w in ∑*
Question: Is w acceptable by the DFA?
Steps:
Start at the “start state” q0
For every input symbol in the sequence w do
Compute the next state from the current state, given the
current input symbol in w and the transition function
If after all symbols in w are consumed, the current
state is one of the accepting states (F) then accept
w;
Otherwise, reject w.
39
Regular Languages
Let L(A) be a language recognized by a
DFA A.
Then L(A) is called a “Regular Language”.
40
The Chomsky Hierarchy
• A containment hierarchy of classes of formal languages
Regular Context-
(DFA) Context- Recursively-
free
sensitive enumerable
(PDA)
(LBA) (TM)
41
Pattern recognition problems
The following are the steps to be followed:
1. Identify the alphabet.
string)
4. Identify other transitions not defined in
step 3.
5. Construct a DFA using transitions in step
3 and step 4. 42
Example #1
Build a DFA for the following language:
L = {w | w is a binary string that contains 01 as a substring}
Steps for building a DFA to recognize L:
∑ = {0,1}
Identify minimum string “01”
Construct skeleton DFA
Decide on the states: Q
Designate start state and final state(s)
δ: Decide on the transitions:
“Final” states == same as “accepting states”
Other states == same as “non-accepting states”
43
DFA for strings containing 01
Solution:
• What makes this DFA deterministic? • Q = {q0,q1,q2}
q1 q1 q2
• What if the language allows
*q2 q2 q2
empty strings?
44
Example #2
Obtain a DFA which accepts strings of a’s and b’s
starting with the string ‘ab’
Step1: Identify the ∑, i.e., ∑={ a, b }
Step2: Write the language (L) for the given problem
i.e., L={ ab, aba, abb, abba, abab, abaaa, abbaba,
ababbb….}
Step3: Now, Construct the DFA for the minimal string,
i.e, ‘ab’.
45
Transition Diagram
46
Transition Table
47
Example #3
Build a DFA for the following language:
L = { w | w is a binary string that has
even number of 1s and even number of
0s}
?
48
Solution
L={,0011,0101,1100,00001111,…….}
Even number of zero’s and one’s
49
Transition Table
50
Example #4
Build a DFA that accepts the language
over alphabet, ∑={0,1} of all that contain
neither the substring 00 nor 11.
not contain 00 or 11
?
51
Solution
Step1: Construct a DFA which contains
the sub-string either ’00’ or ‘11’.
Step2: Complement the DFA to the
actual DFA.
Make final states as non-final and non-final
states as final states.
52
53
54
Divisible by K problems
For these types of problems, the transitions can be obtained using the
following relation:
55
Example #1
Obtain a DFA that accepts the decimal string which are divisible by 3.
Solution:
Now all the numbers with remainder value zero can be considered as
one number i.e., 0 (zero).
All the numbers with remainder value one can be taken as one number
i.e., 1 (one).
All the numbers with remainder value two can be taken as a single
number i.e., 2 (two).
56
57
58
Transition table
59
Transition diagram
Start state
as well as
final state
60
61
Example #2
Build a DFA that accepts the language
over alphabet, ∑={0,1} where the
language is divisible by 3.
62
63
Modulo k counter problems
Construct a DFA for the given language
L={w: |w| mod 3 >= |w| mod 2 where
wϵ∑*and ∑={a}}
Solution:
|w| mod 3 means the length of the string must be completely divisible by 3.
|w| mod 2 means the length of the string must be completely divisible by 2.
Now, draw the automata separately to satisfy both the conditions. 64
65
The set of states of Q1 = {0,1,2} and Q2 = {0,1}. Now, find out
the cross product: Q = Q1xQ2
Q = {(0,0), (0,1), (1,0), (1,1), (2,0), (2,1) }
Now find out the transitions starting from first cross product (0,0)
66
Now draw the automata by using the
obtained transitions:
67
Now check the condition: |w| mod 3 >= |w| mod 2
For example: w = aaaa, |w| = 4
|w| mod 3 >= |w| mod 2
1 >= 0 (1>=0 is true --> so this state will become one of the final
state.)
Likewise, check all the pair of cross product, where ever
remainder value of M1 is greater than or equal to the remainder
value of M2. All those states will become final states of DFA as
shown in below transition diagram.
68
Extended transitions (δ) to (δ)
It is used whenever the input w is given
δ (q,w) = destination state from state q on
input string w
If w=‘abb’
δ (q0,abb) = δ (δ(q0,a), bb)
= δ (q1, bb)
= δ (δ (q1, b),b) Final State
= δ (q1,b)= δ (q1,b)= q2
69
Language of a DFA
A DFA A accepts string w if there is a path
from q0 to an accepting (or final) state
that is labeled by w
71
Non-deterministic Finite
Automata (NFA)
A Non-deterministic Finite Automaton (NFA)
consists of:
Q ==> a finite set of states
∑ ==> a finite set of input symbols (alphabet)
q0 ==> a start state
F ==> set of accepting states
δ ==> a transition function, which is a mapping
between Q x ∑ ==> 2Q
An NFA is also defined by the 5-tuple:
{Q, ∑ , q0,F, δ }
72
How to use an NFA?
Input: a word w in ∑*
Question: Is w acceptable by the NFA?
Steps:
Start at the “start state” q0
For every input symbol in the sequence w do
Determine all possible next states from all current states, given
the current input symbol in w and the transition function
If after all symbols in w are consumed and if at least one of
the current states is a final state then accept w;
Otherwise, reject w.
73
NFA for strings containing 01
74
Note: Omitting to explicitly show error states is just a matter of design convenience
(one that is generally followed for NFAs), and
i.e., this feature should not be confused with the notion of non-determinism.
76
Transition Diagram
77
Transition Table
78
Example #3 (Oct-2018)
Construct an NFA that will accept those
strings of decimal digits that are
divisible by 3 Solution:
Step1: Identify the ∑={0,1,2,…9,}
Step2: Identify the language L.
Step3: Draw the Transition Diagram and
Transition Table.
79
Solution
80
Example #4 (Oct-2019 &
2017)
Draw the Finite state diagram which
accepts all floating point numbers.
Solution:
Transition Table.
81
Solution
82
Example #5
Build an NFA for the following language:
L = { w | w ends in 01}
?
Other examples
Keyword recognizer (e.g., if, then, else,
while, for, include, etc.)
Strings where the first symbol is present
somewhere later on at least once
83
Transition diagram
84
Extension of δ to NFA Paths
Basis: δ (q,) = {q}
Induction:
Let δ (q0,w) = {p1,p2…,pk}
δ (pi,a) = Si for i=1,2...,k
Then, δ (q0,wa) = S1 U S2 U … U Sk
85
Language of an NFA
An NFA accepts w if there exists at least
one path from the start state to an
accepting (or final) state that is labeled
by w
L(N) = { w | δ(q0,w) ∩ F ≠ Φ }
86
Advantages & Caveats for
NFA
Great for modeling regular expressions
String processing - e.g., grep, lexical analyzer
87
Technologies for NFAs
Micron’s Automata Processor (introduced in 2013)
2D array of MISD (multiple instruction single data) fabric
w/ thousands to millions of processing elements.
1 input symbol = fed to all states (i.e., cores)
Non-determinism using circuits
http://www.micronautomata.com/
88
But, DFAs and NFAs are equivalent in their power to capture langauges !!
Subset construction 91
NFA to DFA by subset construction
Let N = {QN,∑,δN,q0,FN}
Goal: Build D={QD,∑,δD,{q0},FD} s.t.
L(D)=L(N)
Construction:
1. QD= all subsets of QN (i.e., power set)
2. FD=set of subsets S of QN s.t. S∩FN≠Φ
3. δD: for each subset S of QN and for each input symbol
a in ∑:
δD(S,a) = Up δinNs(p,a)
92
Idea: To avoid enumerating all of
power set, do
“lazy creation of states”
δD 0 1 δD 0 1
δN 0 1
Ø Ø Ø [q0] [q0,q1] [q0]
q0 {q0,q1} {q0}
[q0] {q0,q1} {q0} [q0,q1] [q0,q1] [q0,q2]
q1 Ø {q2}
[q1] Ø {q2} *[q0,q2] [q0,q1] [q0]
*q2 Ø Ø *[q2] Ø Ø
[q0,q1] {q0,q1} {q0,q2}
*[q0,q2] {q0,q1} {q0} 0. Enumerate all possible subsets
*[q1,q2] Ø {q2} 1. Determine transitions
*[q0,q1,q2] {q0,q1} {q0,q2}
2. Retain only those states
reachable from {q0}
93
NFA to DFA: Repeating the example
using LAZY CREATION
L = {w | w ends in 01} 1 0
NFA: DFA:
0,1 0 1
[q0] [q0,q1] [q0,q2]
0
0 1 1
q0 q1 q2
δN 0 1 δD 0 1
q0 {q0,q1} {q0} [q0] [q0,q1] [q0]
q1 Ø {q2} [q0,q1] [q0,q1] [q0,q2]
*q2 Ø Ø *[q0,q2] [q0,q1] [q0]
Main Idea:
Introduce states as you go
(on a need basis) 94
Correctness of subset construction
Theorem: If D is the DFA constructed from
NFA N by subset construction, then
L(D)=L(N)
Proof:
95
Applications
Text indexing
inverted indexing
For each unique word in the database, store all
locations that contain it using an NFA or a DFA
Find pattern P in text T
Example: Google querying
Extensions of this idea:
PATRICIA tree, suffix tree
96
A few subtle properties of
DFAs and NFAs
The machine never really terminates.
It is always waiting for the next input symbol or making
transitions.
The machine decides when to consume the next symbol from
the input and when to ignore it.
(but the machine can never skip a symbol)
97
FA with -Transitions
We can allow explicit -transitions in finite
automata
i.e., a transition from one state to another state
without consuming any additional input symbol
Explicit -transitions between different states
introduce non-determinism.
Makes it easier sometimes to construct NFAs
Definition: -NFAs are those NFAs with at
least one explicit -transition defined.
-NFAs have one more column in their
transition table
98
Example of an -NFA
L = {w | w is empty, or if non-empty will end in 01}
0,1
0 1
-closure of a state q,
q0 q1 q2 ECLOSE(q), is the set
of all states (including
start q’0 itself) that can be
reached from q by
δE 0 1
repeatedly making an
*q’0 Ø Ø {q’0,q0}
ECLOSE(q’0) arbitrary number of -
q0 {q0,q1} {q0} {q0} ECLOSE(q0) transitions.
ECLOSE(q1)
q1 Ø {q2} {q1}
*q2 Ø Ø {q2} ECLOSE(q2) 99
To simulate any transition:
Step 1) Go to all immediate destination states.
Step 2) From there go to all their -closure states as well.
Example of an -NFA
L = {w | w is empty, or if non-empty will end in 01}
0,1
Simulate for w=101:
0 1
q0 q1 q2
q0’
start
q’0
q0’ q0
1 1
q0
δE 0 1 Ø
x 0
ECLOSE(q’0)
*q’0 Ø Ø {q’0,q0} q1
1
q0 {q0,q1} {q0} {q0} ECLOSE(q0)
q2
q1 Ø {q2} {q1}
*q2 Ø Ø {q2} 100
100
To simulate any transition:
Step 1) Go to all immediate destination states.
Step 2) From there go to all their -closure states as well.
start q’0 q3
δE 0 1
*q’0 Ø Ø {q’0,q0,q3}
q0 {q0,q1} {q0} {q0,q3}
q1 Ø {q2} {q1}
*q2 Ø Ø {q2}
q3 Ø {q2} {q3}
101
101
Equivalency of DFA, NFA, -
NFA
Theorem: A language L is accepted by
some -NFA if and only if L is accepted by
some DFA
Implication:
DFA ≡ NFA ≡ -NFA
(all accept Regular Languages)
102
Eliminating -transitions
Let E = {QE,∑,δE,q0,FE} be an -NFA
Goal: To build DFA D={QD,∑,δD,{qD},FD} s.t. L(D)=L(E)
Construction:
1. QD= all reachable subsets of QE factoring in -closures
2. qD = ECLOSE(q0)
3. FD=subsets S in QD s.t. S∩FE≠Φ
4. δD: for each subset S of QE and for each input symbol a∑:
Let R= U δE(p,a) // go to destination states
p in s
δD(S,a) = U ECLOSE(r) // from there, take a union
r in R
of all their -closures
103
Example: -NFA DFA
0 1
q0 q1 q2
start q’0
δE 0 1 δD 0 1
q1 Ø {q2} {q1}
*q2 Ø Ø {q2}
104
Example: -NFA DFA
δE 0 1 δD 0 1
106
Solution
Steps:
1. Draw the diagram
2. find the -close for all the states
3. Remove the -transitions
Find -close(state) -> transition w.r.t. input -> -
close(state)
4. Draw the diagram for the derived new
transitions.
107
Solution
Draw the diagram and -close for all the states
108
Find -close(state)->transition w.r.t. input->-close(state)
109
-free NFA Transition diagram
110
Summary
DFA
Definition
Regular language
NFA
Definition
112
Finite Automata
Finite Automata
113
Mealy Machine
114
115
Example
117
Example
Note that the length of the output string is one longer than the length
of the input string.
118
Example (Oct-2017)
119
Solution (Moore Machine)
120
Mealy machine
121
Mealy to Moore
Conversion
Mealy machine for the 1’s Complement
0/0 1/0
1/1
A B
0/1
1/0
0/0
Mealy Machine
1/1
A B
0/1
0 0
1
A/0 B/1
0 1
Moore Machine
B/0
1