waseem besada1 dfa vs nfa deterministic finite automata characterized as 5-tuple s is the set of...

17
Waseem Besada 1 DFA vs NFA Deterministic Finite Automata Characterized as 5-tuple < S, A, T, s 0 , F > S is the set of states A is the alphabet T is the transition function: S x A S s 0 is the start state F is the set of accepting states. Characterized as 5-tuple < S, A, T, s 0 , F > • S is the set of states • A is the alphabet • T is the transition function: S x (A{}) P PS s 0 is the start state • F is the set of accepting states. Non-Deterministic Finite Automata

Upload: hailey-curran

Post on 26-Mar-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Waseem Besada1 DFA vs NFA Deterministic Finite Automata Characterized as 5-tuple S is the set of states A is the alphabet T is the transition function:

Waseem Besada 1

DFA vs NFADeterministic 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 S• s0 is the start state• F is the set of accepting states.

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{}) PPS• s0 is the start state• F is the set of accepting states.

Non-Deterministic Finite Automata

Page 2: Waseem Besada1 DFA vs NFA Deterministic Finite Automata Characterized as 5-tuple S is the set of states A is the alphabet T is the transition function:

Waseem Besada 2

From NFA To DFA

0

1

2

43a

a b

a

T a b

0 {1} ø {3}

1 ø {2} ø

2 ø ø ø

3 {3} ø {4}

4 {2} ø ø

Transition function for NFA

Page 3: Waseem Besada1 DFA vs NFA Deterministic Finite Automata Characterized as 5-tuple S is the set of states A is the alphabet T is the transition function:

Waseem Besada 3

Calculating The Transition function for DFA

T a b

0 {1} ø {3}

1 ø {2} ø

2 ø ø ø

3 {3} ø {4}

4 {2} ø ø

T a b

{0,3,4} ? ?

Transition function for DFA

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)

= ø ø ø = ø

Transition function for NFA

Page 4: Waseem Besada1 DFA vs NFA Deterministic Finite Automata Characterized as 5-tuple S is the set of states A is the alphabet T is the transition function:

Waseem Besada 4

Calculating The Transition function for DFA (forts)

T a b

0 {1} ø {3}

1 ø {2} ø

2 ø ø ø

3 {3} ø {4}

4 {2} ø ø

T a b

{0,3,4} {1,2,3,4} ø

Transition function for DFA

ø ? ?

{1,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}

{2,3,4} {2}

Transition function for NFA

Page 5: Waseem Besada1 DFA vs NFA Deterministic Finite Automata Characterized as 5-tuple S is the set of states A is the alphabet T is the transition function:

Waseem Besada 5

Calculating The Transition function for DFA (forts)

T a b

0 {1} ø {3}

1 ø {2} ø

2 ø ø ø

3 {3} ø {4}

4 {2} ø ø

T a b

{0,3,4} {1,2,3,4} ø

Transition function for DFA

ø ø ø

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

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

{2} ø ø

Transition function for NFA

Page 6: Waseem Besada1 DFA vs NFA Deterministic Finite Automata Characterized as 5-tuple S is the set of states A is the alphabet T is the transition function:

Waseem Besada 6

Finally

T a b

{0,3,4} {1,2,3,4} ø

Transition function for DFA

ø ? ?

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

ø ø

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

{2} ø ø

01234

0 2

4

3

1

b

a,bb

a

ab

a

Page 7: Waseem Besada1 DFA vs NFA Deterministic Finite Automata Characterized as 5-tuple S is the set of states A is the alphabet T is the transition function:

Waseem Besada 7

Exercise 2, solution 2. Construct directly (that is don’t 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*

a

b

a,b

a,b

a,b

a

b

a,b

a

a,b

b

a

b

a,c

a,b

a,b,c

c

b

a)

b)

c)

c

Page 8: Waseem Besada1 DFA vs NFA Deterministic Finite Automata Characterized as 5-tuple S is the set of states A is the alphabet T is the transition function:

Waseem Besada 8

Exercise 4, solution4. Construct directly (that is don’t 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

ab

c

ab

a

a) b)

Page 9: Waseem Besada1 DFA vs NFA Deterministic Finite Automata Characterized as 5-tuple S is the set of states A is the alphabet T is the transition function:

Waseem Besada 9

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 b 0 Ø {1,2} {1} 1 {2} Ø Ø 2 Ø {2} {1}

10

2

a

b

b

b

Page 10: Waseem Besada1 DFA vs NFA Deterministic Finite Automata Characterized as 5-tuple S is the set of states A is the alphabet T is the transition function:

Waseem Besada 10

Solution to exercise 5

a b

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

T a b

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

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

NFA transition tableDFA transition table

0

1

0 1a,b a,b

Page 11: Waseem Besada1 DFA vs NFA Deterministic Finite Automata Characterized as 5-tuple S is the set of states A is the alphabet T is the transition function:

Waseem Besada 11

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 DFAd) Draw a picture of the resulting DFA.

0 0 0

ab

a

Page 12: Waseem Besada1 DFA vs NFA Deterministic Finite Automata Characterized as 5-tuple S is the set of states A is the alphabet T is the transition function:

Waseem Besada 12

Solution to exercise 6 (cont’d)

0 1 2

ab

a

Transition table for NFA

T a b

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

Page 13: Waseem Besada1 DFA vs NFA Deterministic Finite Automata Characterized as 5-tuple S is the set of states A is the alphabet T is the transition function:

Waseem Besada 13

Solution to exercise 6 (cont’d)

T a b

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

Transition table for NFA

T a b

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

Transition table for DFA

Page 14: Waseem Besada1 DFA vs NFA Deterministic Finite Automata Characterized as 5-tuple S is the set of states A is the alphabet T is the transition function:

Waseem Besada 14

Solution to exercise 6(cont’d)

T a b

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

Transition table for DFA{0,1,2}

{1,2}

{2}

a

ba,b

a

Page 15: Waseem Besada1 DFA vs NFA Deterministic Finite Automata Characterized as 5-tuple S is the set of states A is the alphabet T is the transition function:

Waseem Besada 15

Exercise 77. Transform each of the following REs into a NFA, then into a DFA

a) a*b* b) a* | b* c) (a|b)*

Solution to a)

0 12 3

4 5

6

a

b

610

a b

Page 16: Waseem Besada1 DFA vs NFA Deterministic Finite Automata Characterized as 5-tuple S is the set of states A is the alphabet T is the transition function:

Waseem Besada 16

Solution, exercise 6-a

3210

a b

T a b

{0,1,2,3} {1,2,3} {2,3} {1,2,3} {1,2,3} {2,3} {2,3} Ø {2,3} Ø Ø Ø

0

1

2 3

a

bb

a

b

aa,b

0

2 3

ba

a,b

a

b

Can be reduced to:

Page 17: Waseem Besada1 DFA vs NFA Deterministic Finite Automata Characterized as 5-tuple S is the set of states A is the alphabet T is the transition function:

Waseem Besada 17

What to do next?

It is your turn to solve the rest of the exercises