You are on page 1of 39

ε-NFA to DFA Conversion

Prepared and presented by Asst. Prof. Dr.


Mohamed Kurdi
Constructing DFA From ε-NFA Using Transition Table
• Recall that the -Closure of a state q, denoted as -Closure(q), is all
states that are reachable from q by a sequence of … and can be
defined as follows:
1. q-CLOSURE(q);
2. p-CLOSURE(q) and r(p, ) → r-CLOSURE(q)

• Now let's define the -closure for a subset of states S.


Let M=(Q,Σ,δ,q0,F) be a nondeterministic finite automaton (ε-NFA)
and S⊆Q. The ε-closure of S, denoted as E(S), can be defined as
follows:
1. S⊆E(S)
2. For every q∈E(S), δ(q,ε)⊆E(S)

2
https://grrinchas.github.io/posts/enfa-to-dfa
Constructing DFA From ε-NFA Using Transition Table

3
https://grrinchas.github.io/posts/enfa-to-dfa
Constructing DFA From ε-NFA Using Transition Table

4
https://grrinchas.github.io/posts/enfa-to-dfa
Constructing DFA From ε-NFA Using Transition Table

1-The start state will be all the states which can


be reached from NFA start state q0 following
zero or more ε-transitions, including itself.

5
https://grrinchas.github.io/posts/enfa-to-dfa
Constructing DFA From ε-NFA Using Transition Table

1-The start state will be all the states which can


be reached from NFA start state q0 following
zero or more ε-transitions, including itself.

2-Now for each symbol in the alphabet, we will find


transition from {q0,q2} to the other states. We will
do this by combining ε-closed transitions from Table
1.0.3 for each state in {q0,q2}.

6
https://grrinchas.github.io/posts/enfa-to-dfa
Constructing DFA From ε-NFA Using Transition Table

1-The start state will be all the states which can


be reached from NFA start state q0 following
zero or more ε-transitions, including itself.

2-Now for each symbol in the alphabet, we will find


transition from {q0,q2} to the other states. We will
do this by combining ε-closed transitions from Table
1.0.3 for each state in {q0,q2}.

3-Next step is to repeat all the previous steps for each


newly created state, in our case {q1}. Once again by
inspecting Table 1.0.3 we find that state {q1} will transition
to state {q1,q2} on symbol a and to {2} on symbol b.
7
https://grrinchas.github.io/posts/enfa-to-dfa
Constructing DFA From ε-NFA Using Transition Table

4-Previous transitions introduced two new states


{q1,q2} and {q2}. Thus, we need to find transitions for
these two states as well. We already know that on
symbol a state {q1,q2} will transition to {q0,q1,q2} and
on symbol b to state {q2}.

8
https://grrinchas.github.io/posts/enfa-to-dfa
Constructing DFA From ε-NFA Using Transition Table

4-Previous transitions introduced two new states


{q1,q2} and {q2}. Thus, we need to find transitions for
these two states as well. We already know that on
symbol a state {q1,q2} will transition to {q0,q1,q2} and
on symbol b to state {q2}.
5-Let's do the same thing for state {q2}. On symbol
a it goes to start state {q0,q2} and on symbol b to ∅.
You may wonder how empty set can be valid state?
Remember that ∅ was included in the set of DFA
states Q′, hence it is perfectly valid state.

9
https://grrinchas.github.io/posts/enfa-to-dfa
Constructing DFA From ε-NFA Using Transition Table

4-Previous transitions introduced two new states


{q1,q2} and {q2}, thus we need to find transitions for
these to states as well. We already know that on
symbol a state {q1,q2} will transition to {q0,q1,q2} and
on symbol b to state {q2}.
5-Let's do the same thing for state {q2}. On symbol
a it goes to start state {q0,q2} and on symbol b to ∅.
You may wonder how empty set can be valid state?
Remember that ∅ was included in the set of DFA
states Q′, hence it is perfectly valid state

6-Once again, we have to find transitions for ∅ and


{q0,q1,q2}. State ∅ doesn't contain any state of ε-NFA, thus
no matter what symbol is given it will transition to ∅ in
other words to itself. State {q0,q1,q2} transitions to the
state {q1,q2} on symbol b and to itself on symbol a.
10
https://grrinchas.github.io/posts/enfa-to-dfa
Constructing DFA From ε-NFA Using Transition Table

4-Previous transitions introduced two new states


{q1,q2} and {q2}, thus we need to find transitions for
these to states as well. We already know that on
symbol a state {q1,q2} will transition to {q0,q1,q2} and
on symbol b to state {q2}.
5-Let's do the same thing for state {q2}. On symbol
a it goes to start state {q0,q2} and on symbol b to ∅.
You may wonder how empty set can be valid state?
Remember that ∅ was included in the set of DFA
states Q′, hence it is perfectly valid state

6-Once again, we have to find transitions for ∅ and


{q0,q1,q2}. State ∅ doesn't contain any state of ε-NFA, thus
no matter what symbol is given it will transition to ∅ in
other words to itself. State {q0,q1,q2} transitions to the
state {q1,q2} on symbol b and to itself on symbol a.
11
https://grrinchas.github.io/posts/enfa-to-dfa
Exercise 1
Convert the following epsilon-NFA to DFA.

12
Exercise 1
Convert the following epsilon-NFA to DFA.
q (q, 0) (q, 1) (q, ε) E((q,0)) E((q,1))

{q0}
{q1}
{q2}

13
Exercise 1
Convert the following epsilon-NFA to DFA.
q (q, 0) (q, 1) (q, ε) E((q,0)) E((q,1))

{q0} {q0} ∅ {q1} {q0,q1,q2} ∅


{q1}
{q2}

14
Exercise 1
Convert the following epsilon-NFA to DFA.
q (q, 0) (q, 1) (q, ε) E((q,0)) E((q,1))

{q0} {q0} ∅ {q1} {q0,q1,q2} ∅


{q1} ∅ {q1} {q2} ∅ {q1,q2}
{q2}

15
Exercise 1
Convert the following epsilon-NFA to DFA.
q (q, 0) (q, 1) (q, ε) E((q,0)) E((q,1))

{q0} {q0} ∅ {q1} {q0,q1,q2} ∅


{q1} ∅ {q1} {q2} ∅ {q1,q2}
{q2} ∅ {q2} ∅ ∅ {q2}

16
Exercise 1
Convert the following epsilon-NFA to DFA.
q (q, 0) (q, 1) (q, ε) E((q,0)) E((q,1))

{q0} {q0} ∅ {q1} {q0,q1,q2} ∅


{q1} ∅ {q1} {q2} ∅ {q1,q2}
{q2} ∅ {q2} ∅ ∅ {q2}
{q0,q1,q2}

17
Exercise 1
Convert the following epsilon-NFA to DFA.
q (q, 0) (q, 1) (q, ε) E((q,0)) E((q,1))

{q0} {q0} ∅ {q1} {q0,q1,q2} ∅ 0


{q1} ∅ {q1} {q2} ∅ {q1,q2}
{q2} ∅ {q2} ∅ ∅ {q2}
{q0,q1,q2}

18
Exercise 1
Convert the following epsilon-NFA to DFA.
q (q, 0) (q, 1) (q, ε) E((q,0)) E((q,1))

{q0} {q0} ∅ {q1} {q0,q1,q2} ∅ 0


{q1} ∅ {q1} {q2} ∅ {q1,q2}
{q2} ∅ {q2} ∅ ∅ {q2} 1
{q0,q1,q2} {q1,q2}

19
Exercise 1
Convert the following epsilon-NFA to DFA.
q (q, 0) (q, 1) (q, ε) E((q,0)) E((q,1))

{q0} {q0} ∅ {q1} {q0,q1,q2} ∅ 0


{q1} ∅ {q1} {q2} ∅ {q1,q2}
{q2} ∅ {q2} ∅ ∅ {q2} 1 0
{q0,q1,q2} {q1,q2} ∅

20
Exercise 1
Convert the following epsilon-NFA to DFA.
q (q, 0) (q, 1) (q, ε) E((q,0)) E((q,1))

{q0} {q0} ∅ {q1} {q0,q1,q2} ∅ 0 1


{q1} ∅ {q1} {q2} ∅ {q1,q2}
{q2} ∅ {q2} ∅ ∅ {q2} 1 0
{q0,q1,q2} {q1,q2} ∅

21
Exercise 1
Convert the following epsilon-NFA to DFA.
q (q, 0) (q, 1) (q, ε) E((q,0)) E((q,1))

{q0} {q0} ∅ {q1} {q0,q1,q2} ∅ 0 1 0,1


{q1} ∅ {q1} {q2} ∅ {q1,q2}
{q2} ∅ {q2} ∅ ∅ {q2} 1 0
{q0,q1,q2} {q1,q2} ∅

22
Exercise 2 0
1 q1 0,1
Convert the following epsilon-NFA to DFA.
q0 q2
ε

23
Exercise 2 0
1 q1 0,1
Convert the following epsilon-NFA to DFA.
q (q, 0) (q, 1) (q, ε) E((q,0)) E((q,1)) q0 q2
ε
{q0}
0
{q1}
{q2}

24
Exercise 2 0
1 q1 0,1
Convert the following epsilon-NFA to DFA.
q (q, 0) (q, 1) (q, ε) E((q,0)) E((q,1)) q0 q2
ε
{q0} ∅ {q1} {q2} ∅ {q1}
0
{q1}
{q2}

25
Exercise 2 0
1 q1 0,1
Convert the following epsilon-NFA to DFA.
q (q, 0) (q, 1) (q, ε) E((q,0)) E((q,1)) q0 q2
ε
{q0} ∅ {q1} {q2} ∅ {q1}
0
{q1} {q1,q2} {q2} ∅ {q1,q2} {q2}
{q2}

26
Exercise 2 0
1 q1 0,1
Convert the following epsilon-NFA to DFA.
q (q, 0) (q, 1) (q, ε) E((q,0)) E((q,1)) q0 q2
ε
{q0} ∅ {q1} {q2} ∅ {q1}
0
{q1} {q1,q2} {q2} ∅ {q1,q2} {q2}
{q2} {q0} ∅ ∅ {q0,q2} ∅

27
Exercise 2 0
1 q1 0,1
Convert the following epsilon-NFA to DFA.
q (q, 0) (q, 1) (q, ε) E((q,0)) E((q,1)) q0 q2
ε
{q0} ∅ {q1} {q2} ∅ {q1}
0
{q1} {q1,q2} {q2} ∅ {q1,q2} {q2}
{q2} {q0} ∅ ∅ {q0,q2} ∅

{q0,q2}

28
Exercise 2 0
1 q1 0,1
Convert the following epsilon-NFA to DFA.
q (q, 0) (q, 1) (q, ε) E((q,0)) E((q,1)) q0 q2
ε
{q0} ∅ {q1} {q2} ∅ {q1}
0
{q1} {q1,q2} {q2} ∅ {q1,q2} {q2}
{q2} {q0} ∅ ∅ {q0,q2} ∅

0
{q0,q2}

29
Exercise 2 0
1 q1 0,1
Convert the following epsilon-NFA to DFA.
q (q, 0) (q, 1) (q, ε) E((q,0)) E((q,1)) q0 q2
ε
{q0} ∅ {q1} {q2} ∅ {q1}
0
{q1} {q1,q2} {q2} ∅ {q1,q2} {q2}
{q2} {q0} ∅ ∅ {q0,q2} ∅

0
{q0,q2}
1
{q1}

30
Exercise 2 0
1 q1 0,1
Convert the following epsilon-NFA to DFA.
q (q, 0) (q, 1) (q, ε) E((q,0)) E((q,1)) q0 q2
ε
{q0} ∅ {q1} {q2} ∅ {q1}
0
{q1} {q1,q2} {q2} ∅ {q1,q2} {q2}
{q2} {q0} ∅ ∅ {q0,q2} ∅

0
{q1,q2}
{q0,q2}
1 0

{q1}

31
Exercise 2 0
1 q1 0,1
Convert the following epsilon-NFA to DFA.
q (q, 0) (q, 1) (q, ε) E((q,0)) E((q,1)) q0 q2
ε
{q0} ∅ {q1} {q2} ∅ {q1}
0
{q1} {q1,q2} {q2} ∅ {q1,q2} {q2}
{q2} {q0} ∅ ∅ {q0,q2} ∅

0
{q1,q2}
{q0,q2}
1 0

{q1} 1
{q2}

32
Exercise 2 0
1 q1 0,1
Convert the following epsilon-NFA to DFA.
q (q, 0) (q, 1) (q, ε) E((q,0)) E((q,1)) q0 q2
ε
{q0} ∅ {q1} {q2} ∅ {q1}
0
{q1} {q1,q2} {q2} ∅ {q1,q2} {q2}
{q2} {q0} ∅ ∅ {q0,q2} ∅

0
{q1,q2}
{q0,q2}
1 0

{q1} 1
{q2}

0
33
Exercise 2 0
1 q1 0,1
Convert the following epsilon-NFA to DFA.
q (q, 0) (q, 1) (q, ε) E((q,0)) E((q,1)) q0 q2
ε
{q0} ∅ {q1} {q2} ∅ {q1}
0
{q1} {q1,q2} {q2} ∅ {q1,q2} {q2}
{q2} {q0} ∅ ∅ {q0,q2} ∅

0
{q1,q2}
{q0,q2}
1 0

{q1} 1
{q2} 1 ∅

0
34
Exercise 2 0
1 q1 0,1
Convert the following epsilon-NFA to DFA.
q (q, 0) (q, 1) (q, ε) E((q,0)) E((q,1)) q0 q2
ε
{q0} ∅ {q1} {q2} ∅ {q1}
0
{q1} {q1,q2} {q2} ∅ {q1,q2} {q2}
{q2} {q0} ∅ ∅ {q0,q2} ∅

0
0 {q0, q1,q2}
{q1,q2}
{q0,q2}
1 0

{q1} 1
{q2} 1 ∅

0
35
Exercise 2 0
1 q1 0,1
Convert the following epsilon-NFA to DFA.
q (q, 0) (q, 1) (q, ε) E((q,0)) E((q,1)) q0 q2
ε
{q0} ∅ {q1} {q2} ∅ {q1}
0
{q1} {q1,q2} {q2} ∅ {q1,q2} {q2}
{q2} {q0} ∅ ∅ {q0,q2} ∅

0
0 {q0, q1,q2}
{q1,q2}
{q0,q2}
1 0
1
{q1} 1
{q2} 1 ∅

0
36
Exercise 2 0
1 q1 0,1
Convert the following epsilon-NFA to DFA.
q (q, 0) (q, 1) (q, ε) E((q,0)) E((q,1)) q0 q2
ε
{q0} ∅ {q1} {q2} ∅ {q1}
0
{q1} {q1,q2} {q2} ∅ {q1,q2} {q2}
{q2} {q0} ∅ ∅ {q0,q2} ∅
0
0
0 {q0, q1,q2}
{q1,q2}
{q0,q2}
1 0
1
{q1} 1
{q2} 1 ∅

0
37
Exercise 2 0
1 q1 0,1
Convert the following epsilon-NFA to DFA.
q (q, 0) (q, 1) (q, ε) E((q,0)) E((q,1)) q0 q2
ε
{q0} ∅ {q1} {q2} ∅ {q1}
0
{q1} {q1,q2} {q2} ∅ {q1,q2} {q2}
{q2} {q0} ∅ ∅ {q0,q2} ∅
0
0
0 {q0, q1,q2}
{q1,q2}
{q0,q2} 1
1 0
1
{q1} 1
{q2} 1 ∅

0
38
Exercise 2 0
1 q1 0,1
Convert the following epsilon-NFA to DFA.
q (q, 0) (q, 1) (q, ε) E((q,0)) E((q,1)) q0 q2
ε
{q0} ∅ {q1} {q2} ∅ {q1}
0
{q1} {q1,q2} {q2} ∅ {q1,q2} {q2}
{q2} {q0} ∅ ∅ {q0,q2} ∅
0
0
0 {q0, q1,q2}
{q1,q2}
{q0,q2} 1
1 0
1 0,1
{q1} 1
{q2} 1 ∅

0
39

You might also like