You are on page 1of 17

DFA vs NFA

Deterministic Finite Automata Characterized as 5-tuple < S, A, T, s0, F > S is the set of states A is the alphabet T is the transition function: S xA S s0 is the start state F is the set of accepting states. Non-Deterministic Finite Automata Characterized as 5-tuple < S, A, T, s0, F > S is the set of states A is the alphabet T is the transition function: S x (A{}) PS s0 is the start state F is the set of accepting states.

Waseem Besada

From NFA To DFA


Transition function for NFA T 0 1 a {1} b {2} {3} 0 a 4

1
a

b 2

2
3 4

{3} {2}

{4}

Waseem Besada

Calculating The Transition function for DFA


Transition function for DFA
T {0,3,4} a ? b ?

Transition function for NFA


T 0 a {1} b {3}

TD({0,3,4},a) = ({0},a) ({3},a) ({4},a) = {1,3} {3,4} {2} = {1,2,3,4}


TD({0,3,4},b) = ({0},b) ({3},b) ({4},b)

1
2 3 4

{3} {2}

{2}

{4}

=
=

Waseem Besada

Calculating The Transition function for DFA (forts)


Transition function for DFA
T {0,3,4}
{1,2,3,4}

Transition function for NFA


T 0 1 2 3 4 {3} {2} a {1} b {2} {3} {4}

a
{1,2,3,4}

b ?
{2} ?

?
{2,3,4} ?

TD({1,2,3,4},a) = ({1},a) ({2},a) ({3},a) ({2},a) = {3,4} {2} = {2,3,4} Similarly, TD({1,2,3,4},b) = {2}

Waseem Besada

Calculating The Transition function for DFA (forts)


Transition function for DFA
T
{0,3,4}

Transition function for NFA


T 0 1 2 3 4 {3} {2} a {1} b {2} {3} {4}

a
{1,2,3,4}

b
{2}

{1,2,3,4}

{2,3,4}

{2,3,4}
{2}

{2,3,4}

{2}

Waseem Besada

Finally
4
b

Transition function for DFA


a,b 1

a
{1,2,3,4}

b ?
{2} {2}

2 a 3 a

0 1 2 3 4

{0,3,4}

{1,2,3,4} {2,3,4} {2}

?
{2,3,4}

{2,3,4}

Waseem Besada

Exercise 2, solution
2. Construct directly (that is dont use the transformation procedure given in the lecture) a DFA for each of the following REs. a) a | b b) a | b* c) ab* | bc*
b

a
b

a,b
a,b

a,b
a c b b a,b a,b

a
b c

a,c

a,b,c

a,b

a)

c)

b)
7

Waseem Besada

Exercise 4, solution
4. Construct directly (that is dont use the transformation procedure given in the lecture) a NFA for each of the following REs. a) a*bc*| bc b) a* | ab a c
a
a b c a b

a)

b)

Waseem Besada

Exercise 5
5. Construct a DFA table for the following NFA transition table. The start state is 0 and there is one accepting state, 2.
a 0 1 {2} 2 b {1,2} {2} {1} {1}

b 0

1
a

2 b

Waseem Besada

Solution to exercise 5
DFA transition table
T 0 1 a b {0,1} {1,2} {1,2} ? ? NFA transition table
a 0 1 {2} 2 b {1,2} {2} {1} {1}

{1,2}

{1,2} {1,2}
a,b

a,b

Waseem Besada

10

Exercise 6
6. Consider the following NFA over the alphabet {a,b}: a) Find a regular expression for the language accepted by the NFA. b) Write down the transition table for the NFA. c) Transform the NFA into a DFA d) Draw a picture of the resulting DFA.

a 0
b
11

0
a

Waseem Besada

Solution to exercise 6 (contd)


Transition table for NFA
T a
{1} {2}

b
{2}

0
{1,2}

0
1 2

Waseem Besada

12

Solution to exercise 6 (contd)


Transition table for DFA T a b Transition table for NFA T a b

{0,1,2} {1,2} {1,2} {2} {2} {2}

{2} {2}

0 {1} {1,2} 1 {2} 2 {2}

Waseem Besada

13

Solution to exercise 6(contd)

{0,1,2}

a
{1,2}

Transition table for DFA T a b {0,1,2} {1,2} {1,2} {2} {2} {2} {2} {2}

b a,b
{2}

Waseem Besada

14

Exercise 7
7. Transform each of the following REs into a NFA, then into a DFA a) a*b* Solution to a) 2 1 b) a* | b* a b c) (a|b)*

a 1

b 6

Waseem Besada 15

Solution, exercise 6-a


T
{0,1,2,3} {1,2,3} {2,3}

a
{1,2,3} {1,2,3}
a 0 b 2 b 1 b

b
{2,3} {2,3} {2,3}
0 b a,b 0

a 1

b 2 3

Can be reduced to:


a,b 2 b a 3

Waseem Besada

16

What to do next?

It is your turn to solve the rest of the exercises

Waseem Besada

17

You might also like