Professional Documents
Culture Documents
tcs1 Slides 40
tcs1 Slides 40
Version 2024.1
Chapter 4. Nondeterministic FA
Motivating example for nondeterminism tab, abau˚
Backbone: aba.
a, b
q1
b a b
q0 a q2 b q3
a
b
a q4
Motivating example for nondeterminism tab, abau˚
q3
b a
q0 a q1 b q2
a
Motivating example for nondeterminism tab, abau˚
q3
b a
q0 a q1 b q2
a
But this automaton has two a edges from state q0 , which is not
allowed.
Motivating example for nondeterminism tab, abau˚
ε
q0 q1 q2 q3
a b a
ε
Motivating example for nondeterminism tab, abau˚
ε
q0 q1 q2 q3
a b a
ε
q2
a b
b
q0 q1
a
Nondeterministic Finite Automata
Further,
‚ A string is accepted if at least one path labeled with that
string leads to a final state.
RECALL
Definition
A deterministic finite automaton is a 5-tuple pQ, Σ, δ, q0 , F q, where
Notation:
‚ Σε denotes Σ Y tεu, so a transition can be labeled with a
symbol a P Σ or the empty string ε.
‚ PpQq contains all sets of states, so a transition labeled a P Σε
can go to more than one state.
Example of formal definition of an NFA
0, 1 0, 1
1 0, ε 1
q1 q2 q3 q4
Example of formal definition of an NFA
0, 1 0, 1
1 0, ε 1
q1 q2 q3 q4
1 Q “ tq1 , q2 , q3 , q4 u
2 Σ “ t0, 1u
δ 0 1 ε
q1 tq1 u tq1 , q2 u H
3 δ is given by q2 tq3 u H tq3 u
q3 H tq4 u H
q4 tq4 u tq4 u H
4 q1 is the start state
5 F “ tq4 u
RECALL
Definition
Let M be a deterministic finite automaton pQ, Σ, δ, q0 , F q.
String w “ w1 w2 . . . wn P Σ˚ is accepted by M if there exists a
sequence of states r “ r0 r1 r2 . . . rn P Q ˚ such that
1 r0 “ q0 ,
2 δpri , wi`1 q “ ri`1 , (for i “ 0, . . . , n ´ 1)
3 rn P F .
1w 2 w 3 w n w
q0 “ r0 ÝÑ r1 ÝÑ r2 ÝÑ r3 . . . rn´1 ÝÑ rn P F
Formal definition of string accepted by an NFA
Definition
Let M be a nondeterministic finite automaton pQ, Σ, δ, q0 , F q.
String w P Σ˚ is accepted by M if we can write
w “ y1 y2 . . . ym , where yi P Σε
w “ y1 y2 . . . ym , where yi P Σε
1y 2y 3 y yn
q0 “ r0 ÝÑ r1 ÝÑ r2 ÝÑ r3 . . . rn´1 ÝÑ rn P F
(For yi possibly ε.)
Language recognized by an NFA
Definition
A language A is recognized by nondeterministic finite automaton
M “ pQ, Σ, δ, q0 , F q if A “ tw P Σ˚ | M accepts w u.
The language recognized by M is denoted by LpMq.
Notice that finding one path labeled with w ending in a final state
suffices, even if there are many more paths labeled with w that do
not end in a final state.
Example
0, 1 0, 1
1 0, ε 1
q1 q2 q3 q4
Is 11 P LpMq?
Example
0, 1 0, 1
1 0, ε 1
q1 q2 q3 q4
Is 11 P LpMq?
There are four paths labeled with the string 11:
1 1
‚ q1 Ý
Ñ q1 Ý
Ñ q1
1 1
‚ q1 Ý
Ñ q1 Ý
Ñ q2
1 1 ε
‚ q1 Ý
Ñ q1 Ý
Ñ q2 Ý
Ñ q3
1 ε 1
‚ q1 Ý
Ñ q2 Ý
Ñ q3 Ý
Ñ q4
Only the last one ends in a final state. Thus, 11 P LpMq.
Example
q1
b a
a ε
q2 q3
a, b
Observations:
‚ Every DFA can be considered an NFA.
‚ But not every NFA is a DFA.
Comparing DFAs and NFAs
Observations:
‚ Every DFA can be considered an NFA.
‚ But not every NFA is a DFA.
Questions:
‚ Are NFAs more expressive than DFAs?
‚ Can NFAs recognize exactly the same languages as DFAs?
Comparing DFAs and NFAs
Observations:
‚ Every DFA can be considered an NFA.
‚ But not every NFA is a DFA.
Questions:
‚ Are NFAs more expressive than DFAs?
‚ Can NFAs recognize exactly the same languages as DFAs?
Answer:
‚ NFAs and DFAs recognize the same languages, so NFAs are
NOT more expressive than DFAs.
DFAs and NFAs are equivalent
Definition
Two machines M and M 1 are equivalent if they recognize the same
language, i.e. LpMq “ LpM 1 q.
DFAs and NFAs are equivalent
Definition
Two machines M and M 1 are equivalent if they recognize the same
language, i.e. LpMq “ LpM 1 q.
Theorem
For every nondeterministic finite automaton there exists an
equivalent deterministic finite automaton.
‚ Then make for the DFA a new state tq, r u and a transition
a
tpu Ý
Ñ tq, r u
‚ So states in the DFA are labeled with sets of states from the
NFA.
‚ A set of states is a final state of the DFA if at least one of its
contained states is final in the original NFA.
Example: Consider the following fragment of an NFA
q1 ε q2
a
a q3
q0 a
ε q4
q5 a q6
Example: Consider the following fragment of an NFA
q1 ε q2
a
a q3
q0 a
ε q4
q5 a q6
tq0 , q5 u a tq1 , q2 , q3 , q4 , q6 u
Example: Consider the following fragment of an NFA
q1 ε q2
a
a q3
q0 a
ε q4
q5 a q6
tq2 u a H
Proof (First without ε-arrows)
Let M “ pQ, Σ, δ, q0 , F q be an NFA. We construct DFA
M 1 “ pQ 1 , Σ1 , δ 1 , q01 , F 1 q such that LpMq “ LpM 1 q, as follows.
Proof (First without ε-arrows)
Let M “ pQ, Σ, δ, q0 , F q be an NFA. We construct DFA
M 1 “ pQ 1 , Σ1 , δ 1 , q01 , F 1 q such that LpMq “ LpM 1 q, as follows.
1 Q 1 “ PpQq;
The new states are sets of old states.
Proof (First without ε-arrows)
Let M “ pQ, Σ, δ, q0 , F q be an NFA. We construct DFA
M 1 “ pQ 1 , Σ1 , δ 1 , q01 , F 1 q such that LpMq “ LpM 1 q, as follows.
1 Q 1 “ PpQq;
The new states are sets of old states.
2 Σ1 “ Σ;
The new alphabet is the same as the old alphabet.
Proof (First without ε-arrows)
Let M “ pQ, Σ, δ, q0 , F q be an NFA. We construct DFA
M 1 “ pQ 1 , Σ1 , δ 1 , q01 , F 1 q such that LpMq “ LpM 1 q, as follows.
1 Q 1 “ PpQq;
The new states are sets of old states.
2 Σ1 “ Σ;
The new alphabet is the same as the old alphabet.
3 For every R P Q 1 and a P Σ let
δ 1 pR, aq “ tq P Q | Dr PR q P δpr , aqu;
There is a new transition with label a from a set to another
set if the second set consists of all old states reachable with
label a from the first set.
Proof (First without ε-arrows)
Let M “ pQ, Σ, δ, q0 , F q be an NFA. We construct DFA
M 1 “ pQ 1 , Σ1 , δ 1 , q01 , F 1 q such that LpMq “ LpM 1 q, as follows.
1 Q 1 “ PpQq;
The new states are sets of old states.
2 Σ1 “ Σ;
The new alphabet is the same as the old alphabet.
3 For every R P Q 1 and a P Σ let
δ 1 pR, aq “ tq P Q | Dr PR q P δpr , aqu;
There is a new transition with label a from a set to another
set if the second set consists of all old states reachable with
label a from the first set.
4 q01 “ tq0 u;
The new initial state is the singleton set containing the old
initial state only.
Proof (First without ε-arrows)
Let M “ pQ, Σ, δ, q0 , F q be an NFA. We construct DFA
M 1 “ pQ 1 , Σ1 , δ 1 , q01 , F 1 q such that LpMq “ LpM 1 q, as follows.
1 Q 1 “ PpQq;
The new states are sets of old states.
2 Σ1 “ Σ;
The new alphabet is the same as the old alphabet.
3 For every R P Q 1 and a P Σ let
δ 1 pR, aq “ tq P Q | Dr PR q P δpr , aqu;
There is a new transition with label a from a set to another
set if the second set consists of all old states reachable with
label a from the first set.
4 q01 “ tq0 u;
The new initial state is the singleton set containing the old
initial state only.
5 F 1 “ tR P Q 1 | R X F ‰ Hu.
A set is a final state if any of its elements is an old final state.
Proof (with ε-arrows)
Extend δ 1 with all states reachable through a sequence of ε-arrows.
For any state R P Q 1 (i.e. R Ď Q) we define E pRq
1 Q 1 “ PpQq;
2 Σ1 “ Σ;
3 For every R P Q 1 and a P Σ let
δ 1 pR, aq “ tq P Q | Dr PR q P E pδpr , aqqu;
Extend target set with all states reachable by one or more ε
transitions.
4 q01 “ E ptq0 uq;
The new initial state contains the old initial state plus all
states reachable with ε’s from the old initial state.
5 F 1 “ tR P Q 1 | R X F ‰ Hu.
Example NFA Ñ DFA
1
b a
a ε
2 3
a, b
b a a, b
b b
a a
a
t3u a t1, 3u t2, 3u t1, 2, 3u
b b
Simplification
a, b
H t2u
b a
b b
a a
a
t3u a t1, 3u t2, 3u t1, 2, 3u
b b
Regularity
RECALL:
Definition
A language is called a regular language if some finite automaton
recognizes it.
RECALL:
Definition
A language is called a regular language if some finite automaton
recognizes it.
Corollary
A language is regular if and only if some nondeterministic finite
automaton recognizes it.
Reg
DFA NFA