finite automata

45
1 Finite Automata

Upload: brice

Post on 29-Jan-2016

30 views

Category:

Documents


0 download

DESCRIPTION

Finite Automata. Introductory Example. An automaton that accepts all legal Pascal identifiers:. Letter. 2. 2. 1. "yes". Digit. Letter or Digit. 3. "no". Letter or Digit. Deterministic Finite Automata (DFA). M = (Q,  ,  , q 0 , F) Q: finite set of internal states - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Finite Automata

1

Finite Automata

Page 2: Finite Automata

2

Introductory Example

An automaton that accepts all legal Pascal identifiers:

1 2

3

Letter

Digit

Letter or Digit

Letter or Digit

"yes"

"no"

2

Page 3: Finite Automata

3

Deterministic Finite Automata (DFA)

M = (Q, , , q0, F)

Q: finite set of internal states

: finite set of symbols - input alphabet

: Q Q transition function

q0Q: initial state

FQ: set of final states

Page 4: Finite Automata

4

Operational Manner

Control unitq0

Input file

yes/no

Page 5: Finite Automata

5

Transition Graphs

M = (Q, , , q0, F)

• |Q| vertices (circles)

• Edge (qi, qj) labelled a for (qi, a) = qj

• Initial vertice q0

• Final vertices (double circles) in F

Page 6: Finite Automata

6

Example 1

M = ({q0, q1, q2}, {0, 1}, , q0, {q1})

(q0, 0) = q0 (q0, 1) = q1

(q1, 0) = q0 (q1, 1) = q2

(q2, 0) = q2 (q2, 1) = q1

q0 q1

1

q2

100 0

1

Page 7: Finite Automata

7

Extended Transition Function

(q0, a) = q1 & (q1, b) = q2 *(q0, ab) = q2

Page 8: Finite Automata

8

Extended Transition Function

(q0, a) = q1 & (q1, b) = q2 *(q0, ab) = q2

*(q, ) = q

*(q, wa) = (*(q, w), a)

Page 9: Finite Automata

9

Languages and DFAs

M = (Q, , , q0, F)

L(M) = {w* | *(q0, w)F}

L(M) = {w* | *(q0, w)F}

Page 10: Finite Automata

10

Example 1

M = ({q0, q1, q2}, {a, b}, , q0, {q1})

L(M) = ?

q0 q1 q2

a, b

a, b

ab

Page 11: Finite Automata

11

Example 1

M = ({q0, q1, q2}, {a, b}, , q0, {q1})

L(M) = {anb | n 0}

trap stateq0 q1 q2

a, b

a, b

ab

Page 12: Finite Automata

12

Theorem

M = (Q, , , q0, F)

GM: associated transition graph

w+

*(qi, w) = qj iff there is a walk labelled w from qi to qj

Page 13: Finite Automata

13

Example 2

L(M) = {w{a, b}* | w starts with ab}

Page 14: Finite Automata

14

Example 2

L(M) = {w{a, b}* | w starts with ab}

q0 q1 q2

ba, b

b

a

trap stateq3

a

a, b

Page 15: Finite Automata

15

Example 3

L(M) = {w{0, 1}* | w does not contain 001}

Page 16: Finite Automata

16

Example 3

L(M) = {w{0, 1}* | w does not contain 001}

0 001

0

0, 1

1 1

000 1

0

trap state

Page 17: Finite Automata

17

Regular Languages

L is regular iff L = L(M) for some DFA M

Page 18: Finite Automata

18

Example 4

L = {awa | w{a, b}*}

Page 19: Finite Automata

19

Example 4

L = {awa | w{a, b}*}

q0 q2 q3

b a

b

a

trap state q1

a

a, b

b

Page 20: Finite Automata

20

Example 5

L = {awa | w{a, b}*}

L2 = {aw1aaw2a | w1, w2{a, b}*}

Page 21: Finite Automata

21

Example 5

L2 = {aw1aaw2a | w1, w2{a, b}*}

q4 q5

b a

b

a

trap stateq1

a

a, b

b

q0 q2 q3

b

b

a

a

b

Page 22: Finite Automata

22

Nondeterministic Finite Automata (NFA)

M = (Q, , , q0, F)

Q: finite set of internal states

: finite set of symbols - input alphabet

: Q ( {}) 2Q transition function

q0Q: initial state

FQ: set of final states

Page 23: Finite Automata

23

Example 6

q1 q2 q3

aa

q4 q5

a

a

q0

a

a

Page 24: Finite Automata

24

Example 7

q0 q1 q2

1

0

0, 1

Page 25: Finite Automata

25

Extended Transition Function

*(qi, w) = Qj

Page 26: Finite Automata

26

Extended Transition Function

*(qi, w) contains qj iff there is a walk labelled w

from qi to qj

Page 27: Finite Automata

27

Example 8

*(q1, a) = ?

*(q2, ) = ?

q0 q1 q2

a

Page 28: Finite Automata

28

Example 8

*(q1, a) = {q0, q1, q2}

*(q2, ) = {q0, q2}

q0 q1 q2

a

Page 29: Finite Automata

29

Example 8

*(qi, w) = ?

q0 q1 q2

a

Page 30: Finite Automata

30

Example 8

*(qi, w) = ?

Evaluate all walks of length at most + (1 + )|w|

is the number of -edges

q0 q1 q2

a

Page 31: Finite Automata

31

Languages and NFAs

M = (Q, , , q0, F)

L(M) = {w* | *(q0, w) F }

Page 32: Finite Automata

32

Languages and NFAs

q0 q1 q21

0

0, 1

L(M) = ?

Page 33: Finite Automata

33

Languages and NFAs

L(M) = {(10)n | n 0}

q0 q1 q21

0

0, 1

Page 34: Finite Automata

34

Languages and NFAs

*(q0, 110) = (q2, 0) =

dead configuration

q0 q1 q21

0

0, 1

Page 35: Finite Automata

35

Homework

• Exercises: 1, 5, 6, 11, 14, 17, 15, 17 of Section 2.1 - Linz’s book.

• Exercises: 3, 4, 6, 7, 9, 10 of Section 2.2 - Linz’s book.

• Reading: Why nondeterminism - Linz’s book.

• Presentation: Section 2.4 - Linz’s book (procedures mark and reduce).

Page 36: Finite Automata

36

Equivalence of DFAs and NFAs

• A class of automata may be more powerful than another.

• DFA is a restricted kind of NFA.

DFA: (qi, a) = qj

NFA: (qi, a) = {qj}

Page 37: Finite Automata

37

Equivalence of DFAs and NFAs

• DFA and NFA are equally powerful.

NFA: *(q, w) = {qi, qj, ..., qk}

a label of one state

Page 38: Finite Automata

38

Example 9

2Q = {, {q0}, {q1}, {q0, q1}}

q0 q1 q2

a

b

a

Page 39: Finite Automata

39

Example 9

({q0}, a) = {q1, q2} ({q0}, b) =

q0 q1 q2

a

b

a

Page 40: Finite Automata

40

Example 9

({q0}, a) = {q1, q2} ({q0}, b) =

({q1, q2}, a) = {q1, q2} ({q1, q2}, b) = {q0}

q0 q1 q2

a

b

a

Page 41: Finite Automata

41

Example 9

{q0} {q1,q2}

b

a

b

a

a, b

Page 42: Finite Automata

42

Theorem

Given MN = (QN, , N, q0N, FN)

there exists MD = (QD, , D, q0D, FD)

such that L(MD) = L(MN)

Page 43: Finite Automata

43

Procedure NFADFA

1. Create GD with vertex q0D = {q0N}.

2. Repeat:

• Take any vertex {qi, qj, ..., qk} of GD that has a missing edge for a.

• Compute *(qi, a), *(qj, a), ..., *(qk, a).

• Create new {ql, qm, ..., qn} = *(qi, a)*(qj, a) ... *(qk, a).

• Add {qi, qj, ..., qk} a {ql, qm, ..., qn}.

3. Every state of GD containing qf FN is a final vertex.

4. If L(MN) then {q0N} is also a final vertex.

Page 44: Finite Automata

44

Example 10

q0 q1 q2

0, 1

0

0, 1

1

Page 45: Finite Automata

45

Homework

• Exercises: 3, 8, 11, 12 of Section 2.3 - Linz’s book.

• Exercises: 1, 4 of Section 2.4 - Linz’s book.

• Programming: Implement procedures mark and reduce (Section 2.4)

(Submission: 15/October).