finite automata
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 PresentationTRANSCRIPT
1
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
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
4
Operational Manner
Control unitq0
Input file
yes/no
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
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
7
Extended Transition Function
(q0, a) = q1 & (q1, b) = q2 *(q0, ab) = q2
8
Extended Transition Function
(q0, a) = q1 & (q1, b) = q2 *(q0, ab) = q2
*(q, ) = q
*(q, wa) = (*(q, w), a)
9
Languages and DFAs
M = (Q, , , q0, F)
L(M) = {w* | *(q0, w)F}
L(M) = {w* | *(q0, w)F}
10
Example 1
M = ({q0, q1, q2}, {a, b}, , q0, {q1})
L(M) = ?
q0 q1 q2
a, b
a, b
ab
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
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
13
Example 2
L(M) = {w{a, b}* | w starts with ab}
14
Example 2
L(M) = {w{a, b}* | w starts with ab}
q0 q1 q2
ba, b
b
a
trap stateq3
a
a, b
15
Example 3
L(M) = {w{0, 1}* | w does not contain 001}
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
17
Regular Languages
L is regular iff L = L(M) for some DFA M
18
Example 4
L = {awa | w{a, b}*}
19
Example 4
L = {awa | w{a, b}*}
q0 q2 q3
b a
b
a
trap state q1
a
a, b
b
20
Example 5
L = {awa | w{a, b}*}
L2 = {aw1aaw2a | w1, w2{a, b}*}
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
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
23
Example 6
q1 q2 q3
aa
q4 q5
a
a
q0
a
a
24
Example 7
q0 q1 q2
1
0
0, 1
25
Extended Transition Function
*(qi, w) = Qj
26
Extended Transition Function
*(qi, w) contains qj iff there is a walk labelled w
from qi to qj
27
Example 8
*(q1, a) = ?
*(q2, ) = ?
q0 q1 q2
a
28
Example 8
*(q1, a) = {q0, q1, q2}
*(q2, ) = {q0, q2}
q0 q1 q2
a
29
Example 8
*(qi, w) = ?
q0 q1 q2
a
30
Example 8
*(qi, w) = ?
Evaluate all walks of length at most + (1 + )|w|
is the number of -edges
q0 q1 q2
a
31
Languages and NFAs
M = (Q, , , q0, F)
L(M) = {w* | *(q0, w) F }
32
Languages and NFAs
q0 q1 q21
0
0, 1
L(M) = ?
33
Languages and NFAs
L(M) = {(10)n | n 0}
q0 q1 q21
0
0, 1
34
Languages and NFAs
*(q0, 110) = (q2, 0) =
dead configuration
q0 q1 q21
0
0, 1
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).
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}
37
Equivalence of DFAs and NFAs
• DFA and NFA are equally powerful.
NFA: *(q, w) = {qi, qj, ..., qk}
a label of one state
38
Example 9
2Q = {, {q0}, {q1}, {q0, q1}}
q0 q1 q2
a
b
a
39
Example 9
({q0}, a) = {q1, q2} ({q0}, b) =
q0 q1 q2
a
b
a
40
Example 9
({q0}, a) = {q1, q2} ({q0}, b) =
({q1, q2}, a) = {q1, q2} ({q1, q2}, b) = {q0}
q0 q1 q2
a
b
a
41
Example 9
{q0} {q1,q2}
b
a
b
a
a, b
42
Theorem
Given MN = (QN, , N, q0N, FN)
there exists MD = (QD, , D, q0D, FD)
such that L(MD) = L(MN)
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.
44
Example 10
q0 q1 q2
0, 1
0
0, 1
1
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).