CS372 Formal Languages & The Theory of Computation
CS372 Formal Languages & The Theory of Computation
Finite Automata,
Nondeterminism
a,c,d b b,c,d
Start C O
a
State diagrams of finite automata
• State diagrams are directed graphs whose
nodes are states and whose arcs are
labeled by one or more symbols from
some alphabet Σ.
• One state is initial (denoted by a short
incoming arrow)
• Several states are final/accepting (denoted
by a double circle).
• DFA: For every symbol a Σ there is an arc
labeled a emanating from every state
Example
• State diagram of a DFA accepts all strings
over {a,b} that have 3 consecutive a’s.
D1 = (Q, , δ,q0, F) q2 q3 q0
q3 q3 q3
Q = {q0, q1, q2, q3}, = {a,b},
F ={q3}
Configuration
• Used in formal description of DFA’s computation.
• Definition: Let M = (Q, , δ,q0, F) be a DFA. We say
that a word qx, qQ, x Σ*, is a configuration of M.
It represents the current state of M and the
remaining unread input of M.
• A configuration of a DFA,M, contains all the
information necessary to continue M’s computation.
• In programming parlance it is equivalent to a dump
of the current value of all variables of a program
and the current position in the program.
Language accepted by a DFA
a b
q0 {q0,q1} {q0}
q1 {q2}
q2 {q3}
q3 {q3} {q3}
Formal Notation of NFA N2
N1 = (Q, , δ,q0, F)
Q = {q0, q1, q2, q3}, = {a,b}, F = {q3}
a b
1 {2} {3}
2 {2, 3} {3}
3 {1}
Language accepted by an NFA
• Same idea as the DFA
• Let N = (Q, , δ,q0, F) be an NFA and let w =
w1w2…wn be a string where each wi is a member
of alphabet ∑.
• N accepts w if a sequence of states r0r1…rn in Q
exists with three conditions:
1. r0 = q0
2. ri+1 δ(ri, wi+1) for i=0, … , n-1
3. rn F
Observe that there is no path from state {1} to state {1,2} so {1,2} is remove from D4
Subset Construction (continued)
a b
Many states may be {1} {1} {2}
unreachable from our
start state. A good way to {2} {2,3} {3}
construct the equivalent {3} {1,3} Ø
DFA from an NFA is to
start with the start state {2,3} {1,2,3} {3}
and construct new states Ø Ø Ø
on the fly as we reach
them. {1,3} {1,3} {2}
{1,2,3} {1,2,3} {2,3}
Graphically:
Regular Languages