You are on page 1of 24

# Conversion of an NFA to a DFA

using
Subset Construction Algorithm

## Operations on NFA States

Example:
By using subset construction algorithm convert the following NFA

## Example: To apply subset construction

we need to remove :

1. transition
That require to construct closure (s)

Mov(T,a)

## Example: First step: construct closure (s)

{0} =
{1} =
{2} =
{3} =
{4} =
{5} =
{6} =
{7} =
{8} =
{9} =
{10} =

{0 , 1, 2, 4, 7}
{1, 2, 4}
{2}
{1, 2, 3, 4, 6, 7}
{4}
{1, 2, 4, 5, 6, 7}
{1, 2, 4, 6, 7}
{7}
{8}
{9}
{10}

Example: Second step: Looking for the start state for the DFA
The start state A of the equivalent DFA is closure (0)
The closure (0) = {0, 1, 2, 4, 7}
Then the starting state

A = {0, 1, 2, 4, 7}
b

{0, 1, 2, 4, 7}
A

## Example: Third step: Compute U = -closure(move(T,a)

First determine the input alphabet

## here input alphapet = {a,b}

Second compute:
1. Dtran[A,a] = -closure(move(A,a))
2. Dtran[A,b] = -closure(move(A,b))

Remember:
A = {0, 1, 2, 4, 7}

1. Dtran[A,a] = -closure(move(A,a))
Among the state 0, 1, 2, 4, 7, only 2 and 7 have transitions on a to 3 and 8,
respectively.
Thus move(A,a)

= {3, 8}

## Also, - closure ({3,8} = {1, 2, 3, 4, 6, 7, 8}

So we conclude:
Dtran[A,a] = -closure(move(A,a)) = - closure ({3,8} = {1, 2, 3, 4, 6, 7, 8}
Let us call this set B so:
Dtran[A,a] = B

{1, 2, 3, 4, 6, 7, 8}

2. Dtran[A,b] = -closure(move(A,b))
Among the states in A, only 4 has a transition on b, and it goes to 5
Thus:
Dtran[A,b] = -closure(move(A,b)) = - closure ({5} = {1, 2, 4, 5, 6, 7 }
Let us call this set C so:
Dtran[A,b] = C

{1, 2, 4, 5, 6, 7 }

Third compute:

3. Dtran[B,a] = -closure(move(B,a))
4. Dtran[B,b] = -closure(move(B,b))

3. Dtran[B,a] = -closure(move(B,a))
Among the states in B, only 2, 7 has a transition on a, and it goes to {3, 8}
respectively
Thus:
Dtran[B,a] = -closure(move(B,a)) = - closure ({3,8} = {1, 2, 3, 4, 6, 7, 8 }
Dtran[B,a] = B

{1, 2, 3, 4, 6, 7, 8 }

4. Dtran[B,b] = -closure(move(B,b))
Among the states in B, only 4, 8 has a transition on b, and it goes to {5, 9}
respectively
Thus:
Dtran[B,b] = -closure(move(B,b)) = - closure ({5,9} = {1, 2, 4, 5, 6, 7,9}

Dtran[B,b] = D

{1, 2, 4, 5, 6, 7,9}

Fourth compute:
5. Dtran[C,a] = -closure(move(C,a))
6. Dtran[C,b] = -closure(move(C,b))

5. Dtran[C,a] = -closure(move(C,a))
Among the states in C, only 2, 7 has a transition on a, and it goes to {3, 8}
respectively
Thus:
Dtran[C,a] = -closure(move(C,a)) = - closure ({3,8} = {1, 2, 3, 4, 6, 7, 8 }
Dtran[C,a] = B

{1, 2, 4, 5, 6, 7 }

6. Dtran[C,b] = -closure(move(C,b))
Among the states in C, only 4 has a transition on b, and it goes to {5}
respectively
Thus:
Dtran[C,b] = -closure(move(C,b)) = - closure ({5} = {1, 2, 4, 5, 6, 7}
Dtran[C,b] = C

{1, 2, 4, 5, 6, 7}
C

Fifth compute:

7. Dtran[D,a] = -closure(move(D,a))
8. Dtran[D,b] = -closure(move(D,b))

7. Dtran[D,a] = -closure(move(D,a))
Among the states in D, only 2, 7 has a transition on a, and it goes to {3, 8}
respectively
Thus:
Dtran[D,a] = -closure(move(D,a)) = - closure ({3,8} = {1, 2, 3, 4, 6, 7, 8 }
Dtran[D,a] = B

{1, 2, 4, 5, 6, 7,9}

8. Dtran[D,b] = -closure(move(D,b))
Among the states in D, only 4 and 9 has a transition on b, and it goes to {5,
10} respectively
Thus:
Dtran[D,b] = -closure(move(D,b)) = - closure ({5,10} = {1,2, 4, 5, 6, 7, 10}
Dtran[D,b] = E

b
a

{1, 2, 4, 5, 6, 7, 9}

## {1, 2, 4, 5,6, 7, 10}

Finally compute:
9. Dtran[E,a] = -closure(move(E,a))
10. Dtran[E,b] = -closure(move(E,b))

9. Dtran[E,a] = -closure(move(E,a))
Among the states in E, only 2, 7 has a transition on a, and it goes to {3, 8}
respectively
Thus:
Dtran[E,a] = -closure(move(E,a)) = - closure ({3,8} = {1, 2, 3, 4, 6, 7, 8 }
Dtran[E,a] = B

{1, 2, 4, 5, 6, 7,9}

## 10. Dtran[E,b] = -closure(move(E,b))

Among the states in E, only 4 has a transition on b, and it goes to {5}
respectively
Thus:
Dtran[E,b] = -closure(move(E,b)) = - closure ({5} = {1,2, 4, 5, 6, 7}
Dtran[E,b] = C

for (alb) * abb