CS310: Automata Theory 2019: Lecture 4: Subset Construction
CS310: Automata Theory 2019: Lecture 4: Subset Construction
IITB, India
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 1
Announcements
I Join piazza (some students have not joined yet; all communications via
piazza)
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 2
What we have seen?
I DFA
I NFA
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 3
Reverse question
Theorem 4.1
For each NFA A = (Q, Σ, δ, q0 , F ), there is a DFA A0 such that L(A) = L(A0 ).
Wait! First non-trivial theorem. Can you see why this may be true?
NFAs have more transitions, but still do not recognize more languages.
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 4
Meta comment on automata theory
constructing an automaton
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 5
Subset construction
We had NFA A = (Q, Σ, δ, q0 , F ).
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 6
Example: subset construction
Example 4.1 0,1
q0 0 q1 1 q2
start
q0 q2 1 q1
start 1
1 0,1
0 1 0
1
0 q0 q1 q0 q2 q1 q2 ∅ 0,1
0 0
By giving them ordinary names, it is clear that the following is just a DFA.
q0 q1 1 q2
start 1
1 0,1
0 1 0
1
0 q3 q4 q5 q6 0,1
0 0
0 1 q7
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 8
Proof of correctness of subset construction
Proof of theorem 4.1.
Let us recall! We had NFA A = (Q, Σ, δ, q0 , F ) and we constructed DFA
A0 = (p(Q), Σ, δ 0 , {q0 }, F 0 )
...
Exercise 4.1
How does the above equality type-check?
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 9
Proof of correctness of subset construction (contd.)
Therefore,
δ̂(q0 , ) = δˆ0 ({q0 }, )
...
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 10
Proof of correctness of subset construction (contd.)
Due to the definition of δˆ0 , δˆ0 ({q0 }, xa) = δ 0 (S, a) = q∈S δ(q, a).
S
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 11
Proof of correctness of subset construction (contd.)
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 12
Complexity of the subset construction
I If NFA has n states DFA potentially has 2n states. exponential blowup
Example 4.2
Consider our example.
q0 q1 1 q2
start 1
1 0,1
0 1 0
1
0 q3 q4 q5 q6 0,1
0 0
0 1 q7
Out of 8 states, only 3 states are reachable from the initial state.
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 13
Idea alert! : exponential blowup
Exponential Bad!
Polynomial Good!
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 14
Incremental generation of DFA
Algorithm 4.1: NFA2DFA( NFA A = (Q, Σ, δ, q0 , F ) )
Output: DFA A0 = (Q 0 , Σ, δ 0 , {q0 }, F 0 )
Q 0 := ∅;
δ 0 := ∅;
F 0 := ∅;
worklist := {{q0 }};
while worklist 6= ∅ do
choose S ∈ worklist;
worklist := worklist \ {S};
if S ∈ Q 0 then continue;
Q 0 := Q 0 ∪ {S};
if S ∩ F 6= ∅ then F 0 := F 0 ∪ {S};
foreach a ∈ Σ do
2 S 0 := ∪q∈S δ(q, a);
3 δ 0 := δ 0 [(S, a) 7→ S 0 ];
4 worklist := worklist ∪ {S 0 }
return (Q 0 , Σ, δ 0 , {q0 }, F 0 )
The above algorithm avoids exponential blow up, if the output DFA does not
have exponentially many states.
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 15
Example: incremental DFA construction
Example 4.3 0, 1
Consider NFA
1 0, 1 0, 1
start q0 q1 q2 q3
1 1 0 0
1 q0 q1 q2 q3 1 q0 q1 q2 1 q0 q1 q3 1 q0 q2 q3
0
Exercise 4.2 1
What fraction of subset states are reached?
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 16
Worst case example
Exercise 4.3
a. Does one such example be enough?
b. How do we prove that there is no small equivalent DFA for an NFA?
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 17
Proving lower size bound
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 18
Exponential blow up family I
0, 1
1 0, 1 0, 1 0, 1
start q0 q1 q2 qn
Since we do not know when the word is going to end, DFA needs to keep the
record of last n symbols.
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 19
Exponential blow up family II
Theorem 4.2
No DFA states fewer than 2n states can recognize Ln .
Proof.
Let us suppose such a DFA A exists.
There must be two different words a1 , ...., an and b1 , ..., bn such that both of
them end up in the same state q of A.(why?)
a1 , . . . , an
start q0 q
b1 , . . . , bn
start q0 q q0
0i−1
b1 , . . . , bn
To be continued...
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 22
End of Lecture 4
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 23