0% found this document useful (0 votes)
121 views23 pages

CS310: Automata Theory 2019: Lecture 4: Subset Construction

This document discusses the subset construction algorithm for converting a non-deterministic finite automaton (NFA) to a deterministic finite automaton (DFA). It begins with an example of applying the subset construction to an NFA. It then provides a proof that the languages recognized by the original NFA and the constructed DFA are equal. The document notes that the subset construction can result in an exponential increase in the number of states, but in practice many states may not be reachable. It presents an incremental algorithm to avoid constructing all potential states. Finally, it discusses how to show a family of NFAs requires a DFA with an exponential number of states.

Uploaded by

Utkarsh Chheda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
121 views23 pages

CS310: Automata Theory 2019: Lecture 4: Subset Construction

This document discusses the subset construction algorithm for converting a non-deterministic finite automaton (NFA) to a deterministic finite automaton (DFA). It begins with an example of applying the subset construction to an NFA. It then provides a proof that the languages recognized by the original NFA and the constructed DFA are equal. The document notes that the subset construction can result in an exponential increase in the number of states, but in practice many states may not be reachable. It presents an incremental algorithm to avoid constructing all potential states. Finally, it discusses how to show a family of NFAs requires a DFA with an exponential number of states.

Uploaded by

Utkarsh Chheda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

CS310 : Automata Theory 2019

Lecture 4: Subset construction

Instructor: Ashutosh Gupta

IITB, India

Compile date: 2019-01-10

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)

I First quiz timing? 7PM 23(W),24(T),25(F),26(S) Jan30

cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 2
What we have seen?

We have seen two fundamental definitions of automata theory

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

Most of the theorems in automata theory are about

constructing an automaton

that satisfies certain property and recognizes a given language.

cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 5
Subset construction
We had NFA A = (Q, Σ, δ, q0 , F ).

Let us construct the following DFA

A0 = (p(Q), Σ, δ 0, {q0}, F 0),


where
I for each S ⊆ Q, δ 0 (S, a) , ∪q∈S δ(q, a),and
I F 0 , {S ⊆ Q|S ∩ F 6= ∅}, i.e., all subsets of Q that have states from F .

We will prove that L(A0 ) = L(A).

First let us see the construction on an example.

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

The following is a DFA obtained by subset construction.

q0 q2 1 q1
start 1
1 0,1
0 1 0
1
0 q0 q1 q0 q2 q1 q2 ∅ 0,1
0 0

{.., ..} is dropped from the sets in 0 1 q0 q1 q2


the states to keep notation minimal
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 7
Example: continued

The names of states have no meaning.

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 )

where for each S ⊆ Q, δ 0 (S, a) , ∪q∈S δ(q, a) and F 0 , {S ⊆ Q|S ∩ F 6= ∅}.

We will first prove


δ̂(q0 , w ) = δˆ0 ({q0 }, w )
by induction on the length of w .

...

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.)

Proof of theorem 4.1(contd.).


base case:
Let w = .

δ̂(q0 , ) = {q0 } due to the def of NFA extended transitions

δˆ0 ({q0 }, ) = {q0 } due to the def of DFA extended transitions

Therefore,
δ̂(q0 , ) = δˆ0 ({q0 }, )
...

cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 10
Proof of correctness of subset construction (contd.)

Proof of theorem 4.1(contd.).


induction step:
Let w = xa, where x is a word in Σ∗ and a is a letter in Σ.

Due to induction hypothesis, we assume δ̂(q0 , x) = δˆ0 ({q0 }, x) = S.

Due to the definition of δ̂, δ̂(q0 , xa) = ∪q∈S δ(q, a).

Due to the definition of δˆ0 , δˆ0 ({q0 }, xa) = δ 0 (S, a) = q∈S δ(q, a).
S

Since δ 0 is defined in the terms


of δ, we apply the definition.
Therefore, δ̂(q0 , xa) = δˆ0 ({q0 }, xa). ...

cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 11
Proof of correctness of subset construction (contd.)

Proof of theorem 4.1(contd.).

claim: L(A) = L(A0 )


If w is accepted by A, δ̂(q0 , w ) has a state q such that q ∈ F .
I iff, q ∈ δˆ0 ({q0 }, w ), which is δˆ0 ({q0 }, w ) ∩ F 6= ∅.
I iff, δˆ0 ({q0 }, w ) ∈ F 0 .
I iff, w is accepted by A0 .

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

I However, not all states are reachable most of the times.

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

Let us construct an equivalent DFA:


0 0
1
q0 1 q0 q1 0 q0 q2 0 q0 q3
start

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

Theoretically, there is a potential exponential explosion.

How do we know there is necessary explosion for some NFA’s?

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

I The evidence of blow up is a family of examples.


I For each number n, there is a larger example

I For each example in family, we show that there is a contradiction if a


small DFA exists.

cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 18
Exponential blow up family I

For some n, Ln = {w |nth symbol from the end is 1}.

The following NFA recognizes Ln .

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

Let us suppose ai and bi are different. ...


cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 20
Exponential blow up family II
Proof(contd.)
Without loss of generality(why?), we can assume ai = 0 and bi = 1.

Now consider words


I w = a1 , ..., ai , ..., an , 0i−1 , which is not in Ln .
I w 0 = b1 , ..., bi , ..., bn , 0i−1 , which is in Ln .
Since A is DFA, w amd w 0 will finish in the same state of A, say q 0 .(why?)
a1 , . . . , an

start q0 q q0
0i−1
b1 , . . . , bn

A will either accept or reject both w or w 0 simultaneously. Contradiction.


cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 21
Beyond regular languages

NFAs and DFAs can recognize same regular languages.

If we add more features in the automaton, would we cover more languages?

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

You might also like