Lecture 4 - NFA To DFA
Lecture 4 - NFA To DFA
Theory Of Automata
By
Dr. Ahmed Hesham Mostafa
Next
NFA
Regular
expressions DFA
2
Speeding Up The Scanner
ε-closure(0) = {0,1,2,4,7} = A
D B E a b b
E B A A B D E
b a
Subset Construction Method
NFA without ε-transitions
Subset Construction Method
NFA without ε-transitions
Fig1. NFA without ε-transitions
3
b a
a Step1
a
a 2 b
Construct a transition table showing all
a,b reachable states for every state for
1 5
every input signal.
a,b a
4
b
Subset Construction Method
NFA without ε-transitions
Transition table
Fig1. NFA without ε-transitions
3 State a b
b a 1 {1,2,3,4,5} {4,5}
a
a ??? ???
a 2 b 2 {3}
??? {5}
???
a,b
1 5 3 {2}
∅
??? ???
a,b
4
a 4 {5}
??? {4}
???
5 ∅
??? ∅
???
b
Subset Construction Method
NFA without ε-transitions
Transition from state q with Transition from state q
Transition table
input a with input b
Fig1. NFA without ε-transitions
3 State a b
b a Starts here 1 {1,2,3,4,5} {4,5}
a
a ??? ???
a 2 b 2 {3}
??? {5}
???
a,b
1 5 3 {2}
∅
??? ???
a,b
4
a 4 {5}
??? {4}
???
5 ∅
??? ∅
???
b
Subset Construction Method
NFA without ε-transitions
Step2
State a b
1 {1,2,3,4,5} {4,5} The set of states resulting from every
transition function constitutes a new
2 {3} {5} state.
Calculate all reachable states for every
3 ∅ {2} such state for every input signal using
union operation.
4 {5} {4} Note 1 is the start state
Note 5 is accept state , so every new
5 ∅ ∅ state will contain 5 will be considered
accept state
Subset Construction table
2 {3} {5}
3 ∅ {2}
4 {5} {4}
5 ∅ ∅
Transition table Subset Construction table
4 {5} {4}
5 ∅ ∅
Transition table Subset Construction table
4 {5} {4}
5 ∅ ∅
Step3
Repeat this process(step2) until no
more new states are reachable.
Transition table Subset Construction table
State a b State a b
{1,2,3,4,5} 1 {1,2,3,4,5} {4,5}
1 {4,5}
{1,2,3,4,5} {1,2,3,4,5}
??? {2,4,5}
???
2 {3} {5}
{4,5}
3 ∅ {2} {2,4,5}
4 {5} {4}
5 ∅ ∅
Transition table Subset Construction table
State a b State a b
1 {1,2,3,4,5} {4,5} 1 {1,2,3,4,5} {4,5}
{1,2,3,4,5} {1,2,3,4,5} {2,4,5}
2 {3} {5}
{4,5} 5
??? 4
???
3 ∅ {2}
{2,4,5}
4 {5} {4}
5
5 ∅ ∅ 4
Transition table Subset Construction table
State a b State a b
1 {1,2,3,4,5} {4,5} 1 {1,2,3,4,5} {4,5}
{1,2,3,4,5} {1,2,3,4,5} {2,4,5}
2 {3} {5}
{4,5} 5 4
3 ∅ {2}
{2,4,5} {3,5}
??? {4,5}
???
4 {5} {4}
5
5 ∅ ∅ 4
{3,5}
Transition table Subset Construction table
State a b State a b
{1,2,3,4,5} 1 {1,2,3,4,5} {4,5}
1 {4,5}
{1,2,3,4,5} {1,2,3,4,5} {2,4,5}
2 {3} {5}
{4,5} 5 4
3 ∅ {2} {3,5} {4,5}
{2,4,5}
4 {5} {4} 5 ∅
??? ∅
???
5 ∅ ∅ 4
{3,5}
∅
Transition table Subset Construction table
State a b State a b
1 {1,2,3,4,5} {4,5} 1 {1,2,3,4,5} {4,5}
{1,2,3,4,5} {1,2,3,4,5} {2,4,5}
2 {3} {5}
{4,5} 5 4
3 ∅ {2}
{2,4,5} {3,5} {4,5}
4 {5} {4}
5 ∅ ∅
5 ∅ ∅ 4 5
??? 4
???
{3,5}
We already got 4 and 5.
So we don’t add them again.
∅
Note ∅ is Dead State
Transition table Subset Construction table
State a b State a b
1 {1,2,3,4,5} {4,5} 1 {1,2,3,4,5} {4,5}
{1,2,3,4,5} {1,2,3,4,5} {2,4,5}
2 {3} {5}
{4,5} 5 4
3 ∅ {2}
{2,4,5} {3,5} {4,5}
4 {5} {4}
5 ∅ ∅
5 ∅ ∅ 4 5 4
{3,5} ∅
??? 2
???
∅
2
Transition table Subset Construction table
State a b State a b
1 {1,2,3,4,5} {4,5} 1 {1,2,3,4,5} {4,5}
{1,2,3,4,5} {1,2,3,4,5} {2,4,5}
2 {3} {5}
{4,5} 5 4
3 ∅ {2}
{2,4,5} {3,5} {4,5}
4 {5} {4}
5 ∅ ∅
5 ∅ ∅ 4 5 4
{3,5} ∅ 2
∅ ∅
??? ∅
???
2
Transition table Subset Construction table
State a b State a b
1 {1,2,3,4,5} {4,5} 1 {1,2,3,4,5} {4,5}
{1,2,3,4,5} {1,2,3,4,5} {2,4,5}
2 {3} {5}
{4,5} 5 4
3 ∅ {2}
{2,4,5} {3,5} {4,5}
4 {5} {4}
5 ∅ ∅
5 ∅ ∅ 4 5 4
{3,5} ∅ 2
∅ ∅ ∅
2 3
??? 5
???
3
Transition table Subset Construction table
State a b State a b
1 {1,2,3,4,5} {4,5} 1 {1,2,3,4,5} {4,5}
{1,2,3,4,5} {1,2,3,4,5} {2,4,5}
2 {3} {5}
{4,5} 5 4
3 ∅ {2}
{2,4,5} {3,5} {4,5}
4 {5} {4}
5 ∅ ∅
5 ∅ ∅ 4 5 4
{3,5} ∅ 2
∅ ∅ ∅
Stops here as there are no 2 3 5
more reachable states
3 ∅
??? 2
???
Resulting FA after applying Subset
Subset Construction table Construction.
a
State a b
1 {1,2,3,4,5} {4,5} b a
12345 245
{1,2,3,4,5} {1,2,3,4,5} {2,4,5}
35
{4,5} 5 4 a
a,b a
{2,4,5} {3,5} {4,5}
b
b
5 ∅ ∅ 1
∅ a
3
4 5 4 b a,b b
a
{3,5} ∅ 2
2
a
∅ ∅ ∅ 45 5 b
2 3 5 b 4 a
3 ∅ 2
b
References
37
THANKS
SEE U NEXT LECTURE