Professional Documents
Culture Documents
Lecture#03-08
1 9/8/2019 Unit-I
Computer ???
What is a computer?
A computer is a machine that manipulates
data according to a list of instructions.
What does the computer do?
Any thing that can be expressed with that list
of instructions.
9/8/2019 Unit-I 2
Computer ??? (Cont.)
Is there anything that a computer cannot
do?
The efforts to answer to this question are
started even before the creation of the
computer !!
The question leads us to the concept of
Automata theory.
9/8/2019 Unit-I 3
Automata theory
The word “Automata“ is the plural of “automaton"
which simply means any machine.
automata theory is the study of abstract
machines and problems they are able to solve.
Automata theory is closely related to formal
language theory as the automata are often
classified by the class of formal languages they
are able to recognize.
9/8/2019 Unit-I 4
Abstract Machine
An abstract machine, also called an abstract
computer, is a theoretical model of a computer
hardware or software system used in Automata
theory.
Abstraction of computing processes is used in
both the computer science and computer
engineering disciplines and usually assumes
discrete time paradigm.
abstract machines are often used in thought
experiments regarding computability or to
analyze the complexity of algorithms
9/8/2019 Unit-I 5
Finite Automata
( or Finite State Machines)
6 9/8/2019
Deterministic Finite Automata
(DFA)
We have seen a simple example before:
start off on
7 9/8/2019
Definition of DFA
8 9/8/2019
Definition of DFA
For example:
1
start off on
9 9/8/2019
Definition of DFA
Another Example:
1 0 0
q1 q2
start q0
1 0
10 9/8/2019
Transition Table
We can also use a table to specify the
transitions.
For the previous example, the DFA is (Q,,,q0,F)
where Q = {q0,q1,q2}, = {0,1}, F = {q2} and is
such that Inputs
States 0 1
q0 q1 q0
q1 q2 q0
q2 q1 q0
12 9/8/2019
Language of a DFA
Given a DFA M, the language accepted
(or recognized) by M is the set of all
strings that, starting from the initial
state, will reach one of the final states
after the whole string is read.
For example, the language accepted by
the previous example is the set of all 0
and 1 strings with even number of 0’s
and 1’s.
13 9/8/2019
Class Discussion
0 0
1
Start q0 q1
1
0 1
1
Start q0 q1
0
0 1 0,1
q0 1 q1 0 q2
Start
14 9/8/2019
Class Discussion
9/8/2019 Unit-I 17
Extended transition function
Given:
a b c
q q1 q2 q3
0
9/8/2019 Unit-I 18
Extended transition function
Let M = (Q, , q0, , A) be an FA. We can
define the function * : Q * Q as
follows:
For any q Q, * (q, ) = q
For any y * , a , and q Q,
* (q, ya) = (* (q, y) , a)
9/8/2019 Unit-I 19
Computation
Since a DFA is an abstract model of
computation, we can now define mathematically
what we mean by “computation”
A computation is a sequence of transitions from
one configuration to another
A computation proceeds according to a finite set
of rules or instructions -- the transition function
(or program) of the DFA
9/8/2019 Unit-I 20
Finite State Machines with output
Moore Machine: Output depends on only
current state.
9/8/2019 Unit-I 21
Accepting
Let M = (Q, , q0, , F) be an FA.
A string w * is accepted by M if
*(q0, w) F
The language accepted (or recognized) by
M is the set of all strings on that are
accepted by M
Formally:
L(M) = {w * : δ* (q0, w) F}
9/8/2019 Unit-I 22
L = {awa : w {a,b}*}
a a
q0 q1 q2
b
a,b
q3
This finite accepter accepts all and only the strings of the
language given above. But note that there are two arcs
out of q1 labeled a. How does the FA know which path to
take on an a? It doesn’t; it has to magically guess right.
Also, there are no arcs out of q2. So this FA is
nondeterministic.
9/8/2019 Unit-I 23
L = {awa : w {a,b}*}
b a
a a
q0 q1 q2
b
b
q3
This finite accepter accepts all and only the strings of the
language given above. This FA is Deterministic.
9/8/2019 Unit-I 24
The finite control can be described by a transition diagram:
Example #1:
0
q0 q1 1
0
1 0 0 1 1
q0 q0 q1 q0 q0 q0
9/8/2019 Unit-I 25
Example #2:
a a a/b/c
c c
q0 q1 q2
b b
a c c c b accepted
q0 q0 q1 q2 q2 q2
a a c rejected
q0 q0 q0 q1
9/8/2019 Unit-I 26
For example #1:
1
Q = {q0, q1}
0
Σ = {0, 1}
q0 q1 1
Start state is q0
F = {q0} 0
δ:
0 1
q0 q1 q0
q1 q0 q1
9/8/2019 Unit-I 27
For example #2:
a a a/b/c
Q = {q0, q1, q2}
Σ = {a, b, c} c c
q0 q1 q2
Start state is q0
F = {q2} b b
δ: a b c
q0 q0 q0 q1
q1 q1 q1 q2
q2 q2 q2 q2
δ^ : (Q x Σ*) –> Q
Formally:
1) δ^(q, ε) = q, and
2) For all w in Σ* and a in Σ
δ^(q,wa) = δ (δ^(q,w), a)
9/8/2019 Unit-I 29
Recall Example #1: 1
0
q0 q1 1
0
What is δ^(q0, 011)? Informally, it is the state entered by M after
processing 011 having started in state q0.
Formally:
δ^(q0, 011) = δ (δ^(q0,01), 1)
= δ (δ ( δ(q0,0), 1), 1)
= δ (δ (q1, 1), 1)
= δ (q1, 1)
= q1
9/8/2019 Unit-I 30
Definitions for DFAs
Let M = (Q, Σ, δ,q0,F) be a DFA and let w be in Σ*. Then w is
accepted by M iff δ^(q0,w) = p for some state p in F.
Let M1 = (Q1, Σ1, δ1, q0, F1) and M2 = (Q2, Σ2, δ2, p0, F2) be
DFAs. Then M1 and M2 are equivalent iff L(M1) = L(M2).
9/8/2019 Unit-I 31
Notes:
A DFA M = (Q, Σ, δ,q0,F) partitions the set Σ* into two sets: L(M) and
Σ* - L(M).
Questions:
How do we determine whether or not a given language is regular?
How could a program “simulate” a DFA?
9/8/2019 Unit-I 32
Give a DFA M such that:
0/1
0/1 0/1
q0 q1 q2
9/8/2019 Unit-I 33
Give a DFA M such that:
b/c a/b/c
a
a
q0 q1 q2
b/c
9/8/2019 Unit-I 34
Give a DFA M such that:
b/c a a/b/c
a a
b
q0 q1 q2 q3
c
b/c
9/8/2019 Unit-I 35
Give a DFA M such that:
a
b
a
q1 q2 q3 b
a a/b
a
q0 a b q7
b
b a
b a
q4 q5 q6
b
9/8/2019 Unit-I 36
Let Σ = {0, 1}. Give DFAs for {}, {ε}, Σ*, and Σ+.
0/1
q0 q0 q1
9/8/2019 Unit-I 37
Non-deterministic FA (NFA)
For each state, zero, one or more
transitions are allowed on the same input
symbol.
An input is accepted if there is a path
leading to a final state.
Nondeterministic Finite State
Automata (NFA)
An NFA is a five-tuple:
M = (Q, Σ, δ, q0, F)
9/8/2019 Unit-I 39
Example #1: some 0’s followed by some 1’s
0 1 0/1
Q = {q0, q1, q2}
Σ = {0, 1} 0 1
q0 q1 q2
Start state is q0
F = {q2}
δ: 0 1
q0 {q0, q1} {}
q1 {} {q1, q2}
q2 {q2} {q2}
9/8/2019 Unit-I 40
Example #2: pair of 0’s or pair of 1’s
0/1 0/1
Q = {q0, q1, q2 , q3 , q4}
Σ = {0, 1} 0 0
q0 q3 q4
Start state is q0
F = {q2, q4} 1 0/1
1
δ: 0 1 q1 q2
q0 {q0, q3} {q0, q1}
q1 {} {q2}
{q2} {q2}
q2
q3 {q4} {}
q4 {q4} {q4}
9/8/2019 Unit-I 41
Determining if a given NFA (example #2) accepts a given string
(001) can be done algorithmically:
0 0 1
q0 q0 q0 q0
q3 q3 q1
q4 q4 accepted
9/8/2019 Unit-I 42
Another example (010):
q0 0 q0 1 q0 0 q0
q3 q1 q3
not accepted
9/8/2019 Unit-I 43
An Example of NFA
In this NFA (Q,,,q0,F), Q = {q0,q1,q2}, = {0,1},
F = {q2} and is:
Start 0
1
q1 Inputs
States 0 1
q0 1 OR q0 {q1,q2}
0 q1 {q1 } {q2 }
1 q2 {q0 }
q2
Note that each transition can lead to a set of states,
which can be empty.
Language of an NFA
Given an NFA M, the language recognized by M is
the set of all strings that, starting from the initial
state, has at least one path reaching a final state
after the whole string is read.
q1 0-9 q4 q6
0-9 . E
0-9
0-9
Start q0 q3 q5 0-9
0-9
+,-
+,-
q2 q7
0-9 0-9
Class Discussion
Consider the language L that consists of
all the strings over = {0, 1} such that the
third last symbol is a “1”.
(a) Construct a DFA for L.
(b) Construct an NFA for L.
a/b/c a/b/c
a b
q0 q1 q2
Is L a subset of L(M)?
Is L(M) a subset of L?
9/8/2019 Unit-I 48
Nondeterminism
9/8/2019 Unit-I 49
L = {ambn : m, n 0}
a
b a
q0 q1 q2
b a,b
9/8/2019 Unit-I 50
Some exercises
a b a,b
q0 b q1 a q2
9/8/2019 Unit-I 51
Some exercises
a b a,b
q0 b q1 a q2
9/8/2019 Unit-I 52
Some exercises
b a a,b
q3
a,b
9/8/2019 Unit-I 53
Some exercises
Use set notation to describe the language
accepted by the following DFA.
b
a b c
c a
b,c a a,b,c
9/8/2019 Unit-I 54
NDFA
Differences between a DFA and an NDFA:
(1) in an NDFA, the range of is in the powerset of
Q (instead of just Q), so that from the current
state, upon reading a symbol:
(a) more than one state might be the next state
of the NDFA, or
(b) no state may be defined as the next state of
the NDFA, and
(2) -moves are possible; that is, a transition from
one state to another may occur without reading
a symbol from the input string.
9/8/2019 Unit-I 55
NDFA = DFA
One kind of automaton is more powerful
than another if it can accept and reject
some kinds of languages that the other
cannot.
Two finite accepters are equivalent if both
accept the same language, that is,
L(M1) = L(M2)
As mentioned previously, we can always find
an equivalent DFA for any given NDFA.
Therefore, NDFA’s are no more powerful
than DFA’s.
9/8/2019 Unit-I 56
DFA and NFA
Is NFA more powerful than DFA?
NO! NFA is equivalent to DFA.
Trivial
DFA NFA
Constructive
Proof
Constructing DFA from NFA
Given any NFA M=(Q,,,q0,F) recognizing a
language L over , we can construct a DFA
N=(Q’, ,’,q0’,F’) which also recognizes L:
• Q’ = set of all subsets of Q
e.g., if Q = {q0, q1}, Q’ = {{}, {q0}, {q1}, {q0, q1}}
• q0’ = {q0}
• F’ = set of all states in Q’ containing a final state
of M
• ’({q1a,q 2, …
state
q }, a) = (q1,a) a(q
in N i
,a) ... (qi,a)
state2 in M
NDFA DFA
9/8/2019 Unit-I 59
NDFA DFA
{q0}
9/8/2019 Unit-I 60
NDFA DFA
c. Then form the union of all these δ*, yielding the set
{ql, qm, …, qn}.
So our new DFA will have a state labeled {q1, q2}.
d. Create a vertex for GD labeled {ql, qm, …, qn} if it
does not already exist.
So create a vertex for our new DFA and label it {q1,
q2}.
e. Add to GD an edge from {qi, qj, …, qk} to {ql, qm, …,
qn} and label it with a.
So add a transition labeled a to {q1, q2} from q0.
9/8/2019 Unit-I 62
NDFA DFA
So now we have:
9/8/2019 Unit-I 63
NDFA DFA
c. Then form the union of all these δ*, yielding the set
{ql, qm, …, qn}.
So our new DFA will have a state labeled .
d. Create a vertex for GD labeled {ql, qm, …, qn} if it
does not already exist.
So create a vertex for our new DFA and label it .
e. Add to GD an edge from {qi, qj, …, qk} to {ql, qm, …,
qn} and label it with a.
So add a transition labeled b to from q0.
9/8/2019 Unit-I 65
NDFA DFA
So now we have:
b a
9/8/2019 Unit-I 66
NDFA DFA
c. Then form the union of all these δ*, yielding the set
{ql, qm, …, qn}.
The union is {q1, q2} .
d. Create a vertex for GD labeled {ql, qm, …, qn} if it
does not already exist.
It does.
e. Add to GD an edge from {qi, qj, …, qk} to {ql, qm, …,
qn} and label it with a.
So add a transition labeled a to {q1, q2} from {q1, q2}
.
9/8/2019 Unit-I 68
NDFA DFA
So now we have:
a
b a
a, b
9/8/2019 Unit-I 69
NDFA DFA
c. Then form the union of all these δ*, yielding the set
{ql, qm, …, qn}.
The union is {q1, q2} .
d. Create a vertex for GD labeled {ql, qm, …, qn} if it
does not already exist.
It does.
e. Add to GD an edge from {qi, qj, …, qk} to {ql, qm, …,
qn} and label it with a.
So add a transition labeled b to q0 from {q1, q2} .
9/8/2019 Unit-I 71
NDFA DFA
9/8/2019 Unit-I 72
NDFA DFA
Here is the finished DFA (Figure 2.13 in Linz):
9/8/2019 Unit-I 73
An Example of NFA DFA
Consider a simple NFA:
0 1
0
Start q0 1 q1
1
{q0, q1} {}
1,0 1,0
NDFA DFA
Example: Convert this NDFA to a DFA.
9/8/2019 Unit-I 75
NDFA DFA
Example:
9/8/2019 Unit-I 76
NDFA DFA
Example:
9/8/2019 Unit-I 77
Minimal DFA’s
Two states p and q of a DFA are called
indistinguishable if
* (p, w) F implies * (q, w) F ,
and
* (p, w) F implies * (q, w) F ,
for all w *.
If there exists some string w * such that
* (p, w) F
and
* (q, w) F
or vice versa, then the states p and q are said to be
distinguishable by string w.
9/8/2019 Unit-I 78
The “Mark” procedure
This procedure marks all pairs of distinguishable
states.
1. Remove all inaccessible states.
2. Consider all pairs of states (p, q). If p F and q
F or vice versa, mark the pair (p, q) as
distinguishable.
3. Repeat the following step until no previously
unmarked pairs are marked:
For all pairs (p, q) and all a , compute (p,
a) = pa and (q, a) = qa. If the pair (pa, qa) is marked
as distinguishable, mark (p,
9/8/2019 Unit-I
q) as distinguishable. 79
The “Reduce” procedure
Given a DFA M = (Q, , , q0, F), we construct a
reduced DFA M’ = (Q’, , ’, q0’, F’) as follows:
1. Use procedure Mark to find all pairs of
distinguishable states. Then from this find the sets
of indistinguishable states by partitioning the state
set Q of the DFA into disjoint subsets {qi, qj, …, qk},
{ql, qm, …, qn}, …, such that any q Q occurs in
exactly one of these subsets, that elements in each
subset are indistinguishable, and that any two
elements from different subsets are distinguishable.
9/8/2019 Unit-I 80
The “Reduce” procedure, cont.
2. For each set {qi, qj, …, qk} of such
indistinguishable states, create a state labeled ij…k
for M.
3. For each transition rule of the form (qr, a) = qp,
find the sets to which qr and qp belong. If qr {qi, qj,
…, qk} and qp {ql, qm, …, qn}, add to ’ a rule ’
(ij…k, a) = lm…n.
4. The initial state q0’ is that state of M’ whose label
includes the 0.
5. F’ is the set of all the states whose label contains
i such that qi F.
9/8/2019 Unit-I 81
Theorem 2.4
9/8/2019 Unit-I 82
Minimal DFA’s
Example: This DFA can be reduced to the DFA on the next
slide.
9/8/2019 Unit-I 83
Minimal DFA’s
9/8/2019 Unit-I 85
Minimum number of states in an
FA
If there are n distinguishable strings in a
language, then there must be at least n
states in the finite automata that accepts it.
The FA has no memory, other than the current
state.
This puts a lower bound on the number of
states in a FA recognizing a language.
9/8/2019 Unit-I 86
For
Equivalence of DFA and NFA, refer page
no 33
FA’s with ε-transitions, refer page no. 43
Equivalence and minimization of DFA,
refer page no. 118
All from Lecture Notes#01
9/8/2019 Unit-I 87
THANK YOU
88 9/8/2019 Unit-I