Lecture 5: Finite Automata - PowerPoint PPT Presentation

1 / 132
About This Presentation
Title:

Lecture 5: Finite Automata

Description:

Greek alphabet. my alphabet. Strings. String over an alphabet ( ) a finite sequence of symbols from ... String length # symbols in a string, e.g., A string, w, ... – PowerPoint PPT presentation

Number of Views:303
Avg rating:3.0/5.0
Slides: 133
Provided by: yueta
Category:

less

Transcript and Presenter's Notes

Title: Lecture 5: Finite Automata


1
Lecture 5 Finite Automata
  • ???

??????? ?????????
2
Content
  • Alphabets and Languages
  • Deterministic Finite Automata
  • Nondeterministic Finite Automata
  • Equivalence of DFA NFA
  • Properties of Languages Accepted by FAs
  • Finite Automata Regular Expressions
  • Languages Not Accepted by FAs

3
Lecture 5 Finite Automata
  • Alphabets
  • and
  • Languages

??????? ?????????
4
Alphabets
  • Alphabet ? a finite set of symbols
  • Examples

? binary alphabet
? decimal alphabet
? Roman alphabet
? Greek alphabet
? my alphabet
5
Strings
  • String over an alphabet (?) ? a finite sequence
    of symbols from ?
  • ? ? the set of all strings over ?
  • Examples

6
More on Strings
  • String length ? symbols in a string, e.g.,
  • A string, w, can be considered as a function
    , e.g.,
  • Some string operations
  • Concatenation
  • Reversal
  • Duplication

7
More on Strings
  • Substring
  • Suffix
  • Prefix

? a prefix of w and a substring of w.
? a suffix of w and a substring of w.
? a substring of w.
8
Countability of ?
? is countably infinite for any finite alphabet
?.
Example
? can be enumerated by
9
Languages
  • Language L over ? ? any subset of ? i.e., L ? ?
  • How many possible languages over ??
  • How to specify a language?

? uncountably infinite
10
Operations of Languages
  • Complement
  • Union
  • Intersection

11
Operations of Languages
  • Complement, Union and Intersection
  • Concatenation
  • Closure or Kleene Star
  • Positive Closure

12
Example Kleene Star
1909 1994
13
Example Kleene Star
1909 1994
?
?
14
Example Kleene Star
1909 1994
?
15
Language Recognition Device
A machine or algorithm to answer the question
16
Lecture 5 Finite Automata
  • Deterministic Finite Automata

??????? ?????????
17
Finite State Machine
Input tape
Reading Head
18
Definition ? Deterministic Finite Automaton
  • A deterministic finite automaton is a 5-tuple
  • (K, ?, ?, s, F)

K a finite set of states
? a finite set of symbols
? the transition function K??? K
s ?K the initial state
F ?K the set of final states
19
Example
(K, ?, ?, s, F)
Kq0, q1, q2, q3
?0, 1
sq0
F q0
20
Operations of a DFA
21
Operations of a DFA
Strings are fed into the device by means of an
input tape.
  • Main part of the machine
  • Initially,
  • putting reading head at the leftmost
  • in state s q0
  • Sense input symbol
  • Change state based on ?
  • Move head right one cell
  • Give answer when head reaches end

22
DFA As a Language Acceptor
  • The input string is accepted by the machine if
    the reading head ends at a final state.
  • Otherwise, it is rejected.

Accepted
JFLAP
Rejected
23
DFA As a Language Acceptor
  • The input string is accepted by the machine if
    the reading head ends at a final state.
  • Otherwise, it is rejected.

What language the machine accepts?
24
DFA As a Language Acceptor
  • The input string is accepted by the machine if
    the reading head ends at a final state.
  • Otherwise, it is rejected.

What language the machine accepts?
q3
25
Memory Configuration of a DFA
M (K, ?, ?, s, F)
26
Memory Configuration of a DFA
M (K, ?, ?, s, F)
Does not effect the result.
27
Memory Configuration of a DFA
M (K, ?, ?, s, F)
28
Memory Configuration of a DFA
M (K, ?, ?, s, F)
29
Memory Configuration of a DFA
30
Yields in One Step
if
31
Yields
in some (including zero) steps
if
32
String Acceptance by a DFA
M (K, ?, ?, s, F)
w?? is said to be accepted by M iff
such that
33
Language Defined by a DFA
M (K, ?, ?, s, F)
Language L(M) denotes the set of all strings
accepted by M, i.e.,
34
Example
w0100100110
w?L(M)?
(q0, 0100100110)
M
35
Example
w0100100110
?
w?L(M)?
(q0, 0100100110)
M
36
Example
M
37
Example
38
Exercises
  • Describe informally the languages accepted by the
    deterministic finite automata shown below

(a)
(b)
39
Exercises
  • Construct deterministic finite automata accepting
    each of the following languages
  • w?a, b each a in w is immediately preceded
    and immediately followed by a b.
  • w?a, b w has abab as a substring.
  • w?a, b w has neither aa nor bb as a
    substring.
  • w?a, b w has both ab and ba as a substring.

40
Lecture 5 Finite Automata
  • Nondeterministic Finite Automata

??????? ?????????
41
Review ? Deterministic Finite Automaton
  • A deterministic finite automaton is a 5-tuple
  • (K, ?, ?, s, F)

K a finite set of states
? a finite set of symbols
? the transition function K??? K
s ?K the initial state
F ?K the set of final states
42
Definition ?Nondeterministic Finite Automaton
  • A deterministic finite automaton is a 5-tuple
  • (K, ?, ?, s, F)

A nondeterministic finite automaton is a
5-tuple (K, ?, ?, s, F)
K a finite set of states
? a finite set of symbols
? the transition function K??? K
? the transition function K??? 2K
2K
s ?K the initial state
F ?K the set of final states
43
Transition Functions of FAs
? K??? 2K
? K??? K
? K
q
?K
Q
44
Transition Functions of FAs
? K??? 2K
? K??? K
Change to one of state in Q nondeterministically.
Change to state q deterministically.
? K
q
?K
Q
45
Yields in One Step
M (K, ?, ?, s, F)
if
46
Yields
M (K, ?, ?, s, F)
in some (including zero) steps
47
String Acceptance by a NFA
M (K, ?, ?, s, F)
w?? is said to be accepted by M iff
such that
48
Language Defined by an NFA
M (K, ?, ?, s, F)
Language L(M) denotes the set of all strings
accepted by M, i.e.,
49
Example L(ababa)
NFA
DFA
q1
q2
50
Extension ?-Move Multi-Move
L(ababa)
q1
NFA
q2
q1
q2
51
Extension ?-Move Multi-Move
L(ababa)
q1
NFA
q2
q1
q1
q2
52
Definition ?Nondeterministic Finite Automaton
A nondeterministic finite automaton is a
5-tuple (K, ?, ?, s, F)
K a finite set of states
? a finite set of symbols
? the transition function K??? 2K
s ?K the initial state
F ?K the set of final states
53
Yields in One Step
M (K, ?, ?, s, F)
54
Yields
M (K, ?, ?, s, F)
in some (including zero) steps
55
String Acceptance by a NFA
M (K, ?, ?, s, F)
w?? is said to be accepted by M iff
such that
56
Language Defined by an NFA
M (K, ?, ?, s, F)
Language L(M) denotes the set of all strings
accepted by M, i.e.,
57
Lecture 5 Finite Automata
  • Equivalence of DFA NFA

??????? ?????????
58
Equivalence of Finite Automata
Finite automata M1 and M2 are said to be
equivalent iff
59
Machine Simulation
Of Course
?
DFA
NFA
?
To be discussed
60
Lemma
For each NFA, there is an equivalent NFA finite
automaton without multi-move on the transition
function.
61
Example
In the following, we will assume the NFA being
discussed is one without multi-move unless
otherwise stated.
62
?-Closure
In the following, we will assume the NFA being
discussed is one without multi-move unless
otherwise stated.
M (K, ?, ?, s, F)
?-Closure of state q
63
Example
M
To be used in the next example.
64
Theorem
For each nondeterministic finite automaton, there
is an equivalent deterministic finite automaton.
65
Theorem
For each nondeterministic finite automaton, there
is an equivalent deterministic finite automaton.
Pf)
Let M (K, ?, ?, s, F) be an NFA.
To prove the theorem, we must be able to build a
DFA M (K, ?, ?, s, F) such that L(M)L(M).
66
Theorem
For each nondeterministic finite automaton, there
is an equivalent deterministic finite automaton.
Pf)
Let M (K, ?, ?, s, F) be an NFA.
To prove the theorem, we must be able to build a
DFA M (K, ?, ?, s, F) such that L(M)L(M).
67
Theorem
For each nondeterministic finite automaton, there
is an equivalent deterministic finite automaton.
Pf)
Next, we have to show that
68
Theorem
For each nondeterministic finite automaton, there
is an equivalent deterministic finite automaton.
  • Exercises
  • Referring to the textbook to complete the proof
    in detail.
  • To present the proof using PowerPoint.

Pf)
Next, we have to show that
69
Example
M
70
Example
M
71
Example
M
There are 32 possible subsets. However, most of
them are useless.
72
Example
M
73
Example
M
M
gt
74
Example
M
M
gt
75
Example
M
M
gt
?
76
Example
M
JFLAP
M
gt
?
77
Exercises
  • Construct deterministic finite automata
    equivalent to the nondeterministic automata shown
    below

(a)
(b)
78
Lecture 5 Finite Automata
  • Properties of Languages Accepted by Finite
    Automata

??????? ?????????
79
The Chomsky Hierarchy
80
The Chomsky Hierarchy
81
Properties of Languages Accepted by FAs
  • The class of languages accepted by finite
    automata is
  • closed under
  • union
  • concatenation
  • Keene star
  • complementation
  • intersection.

82
Properties of Languages Accepted by FAs
  • The class of languages accepted by finite
    automata is
  • closed under
  • union
  • concatenation
  • Keene star
  • complementation
  • intersection.

accepts
83
Properties of Languages Accepted by FAs
  • The class of languages accepted by finite
    automata is
  • closed under
  • union
  • concatenation
  • Keene star
  • complementation
  • intersection.

accepts
84
Properties of Languages Accepted by FAs
  • The class of languages accepted by finite
    automata is
  • closed under
  • union
  • concatenation
  • Keene star
  • complementation
  • intersection.

accepts
85
Properties of Languages Accepted by FAs
  • The class of languages accepted by finite
    automata is
  • closed under
  • union
  • concatenation
  • Keene star
  • complementation
  • intersection.

86
Properties of Languages Accepted by FAs
  • The class of languages accepted by finite
    automata is
  • closed under
  • union
  • concatenation
  • Keene star
  • complementation
  • intersection.

87
Theorem
  • There are algorithms to answer the following
  • questions about finite automata
  • w ? L(M)?
  • L(M) ??
  • L(M) ??
  • L(M1) ? L(M2) ?
  • L(M1) L(M2) ?

88
Theorem
  • There are algorithms to answer the following
  • questions about finite automata
  • w ? L(M)?
  • L(M) ??
  • L(M) ??
  • L(M1) ? L(M2) ?
  • L(M1) L(M2) ?

? Feed w into M.
? Check any final state is reachable
  • Check L(M1) ? L(M2) ?
  • L(M2) ? L(M1) ?

89
Exercises
  • Draw state diagrams for nondeterministic finite
    automata accepting these languages
  • (ab)(ba)?aa
  • ((ab?aab)a)
  • ((aba)b)
  • (ba?b)?(bb?a)

90
Lecture 5 Finite Automata
  • Finite Automata
  • Regular Expressions

??????? ?????????
91
The Languages Accepted by FAs
  • The languages accepted by FAs are called regular
    sets.
  • How to describe a regular set?
  • Regular Expression

92
Definition ? Regular Expressions
A regular expression is defined inductively over
the alphabet ? ? (, ), ?, ?, , as
follows
  • ?, ?, and each ??? is a regular expression
  • If ? and ? are regular expressions, then
  • (? ?)
  • (? ?)
  • ?
  • are regular expressions

? basic
? inductive
93
Definition ? Regular Expressions
A regular expression is defined inductively over
the alphabet ? ? (, ), ?, ?, , as
follows
  • ?, ?, and each ??? is a regular expression
  • If ? and ? are regular expressions, then
  • (? ?)
  • (? ?)
  • ?
  • are regular expressions

? basic
? union, or
? concatenation
? Kleene closure
? inductive
94
Writing a Regular Expression
For omitting parentheses, the precedence of
operators are assigned as follows
gt gt
?
((0(1))0)
010
What is this language?
95
Examples
What do the following regular expressions
represent?
  • 00
  • (01)
  • (01) 00 (01)
  • (0?) (110)
  • (01)011
  • 012
  • 001122

96
More Examples
Is the following language L an r.e. over ?a-z?
Lwhat, which, when, where.
Write L as an r.e.
L what which when where
L (wh)(at ich en ere)
L (wh)(at ich) (whe) (n re)
97
Theorem
A language is regular if and only if it is
accepted by a finite automaton.
Pf)
?
Given a regular expression, how to construct an
FA to accept the language described by it?
?
Given an FA, what is its corresponding regular
expression?
98
Theorem
A language is regular if and only if it is
accepted by a finite automaton.
?
Pf)
Suppose that we are given a regular expression r,
we can construct an NFA to accept the language
described it inductively based on the number of
operators' it possesses as follows.
Basis (zero operators)
Case 1 r ?
Case 2 r ?
Case 3 r a
99
Theorem
A language is regular if and only if it is
accepted by a finite automaton.
?
Pf)
Suppose that we are given a regular expression r,
we can construct an NFA to accept the language
described it inductively based on the number of
operators' it possesses as follows.
? true
Basis (zero operators)
Hypothesis
Assumed true for r.e.s few than m operators
Induction
To be shown true for r.e.s with m1 operators
Case 1 r r1r2
r m1 operators r1 ? m operators r2 ? m
operators
Case 2 r r1r2
Case 3 r r1
100
Theorem
A language is regular if and only if it is
accepted by a finite automaton.
?
Pf)
Suppose that we are given a regular expression r,
we can construct an NFA to accept the language
described it inductively based on the number of
operators' it possesses as follows.
? true
Basis (zero operators)
Hypothesis
Assumed true for r.e.s few than m operators
Induction
To be shown true for r.e.s with m1 operators
Case 1 r r1r2
r m1 operators r1 ? m operators r2 ? m
operators
Case 2 r r1r2
Case 3 r r1
101
Theorem
A language is regular if and only if it is
accepted by a finite automaton.
?
Pf)
Suppose that we are given a DFA, we will
determine its corresponding regular expression
also inductively.
Consider DFA M (q1, q2,,qn, ?, ?, q1, F).
Define
l ? k
ql
y
qi
qj
102
Theorem
A language is regular if and only if it is
accepted by a finite automaton.
?
Pf)
Suppose that we are given a DFA, we will
determine its corresponding regular expression
also inductively.
Consider DFA M (q1, q2,,qn, ?, ?, q1, F).
Define
is regular for any i, j, and k.
103
Theorem
A language is regular if and only if it is
accepted by a finite automaton.
?
Pf)
Suppose that we are given a DFA, we will
determine its corresponding regular expression
also inductively.
Consider DFA M (q1, q2,,qn, ?, ?, q1, F).
Define
is regular for any i, j, and k.
104
Equivalence FA RE
FA
RE
105
The Chomsky Hierarchy
106
The Chomsky Hierarchy
107
Example
Find an r.e. to represent the following FA.
M
108
Example
k 0
k 1
?
0
1
0
?
1
?
01
?
109
Example
k 0
k 1
k 2
?
(00)
0
0(00)
01
1
0
0(00)
?
(00)
1
01
(01)(00)0
?
01
(01)(00)
?
?(01)01
110
Example
k 0
k 1
k 2
?
(00)
0
0(00)
01
1
0
0(00)
?
(00)
1
01
(01)(00)0
?
01
(01)(00)
?
?(01)01
111
Example
k 0
k 1
k 2
?
(00)
0
0(00)
01
1
0
0(00)
?
(00)
1
01
(01)(00)0
?
01
(01)(00)
?
?(01)01
112
Lecture 5 Finite Automata
  • Languages Not Accepted by Finite Automata

??????? ?????????
113
What FAs can? What FAs cannot?
Which of the following languages are regular?
114
The Pumping Theory
Let L be an infinite regular set. Then there are
strings u,v, and w st. vgt0 and uvnw?L for all n
? 0.
Pf)
Let L is accepted by a DFA M (K, ?, ?, q0 , F)
with m states.
Consider input w ?1 ? 2 ?l, l ? m.
Then,
. . .
By pigeonhole, there exists j, k with 0? j lt k ?
l st. qj qk.
115
The Pumping Theory
Let L be an infinite regular set. Then there are
strings u,v, and w st. vgt0 and uvnw?L for all n
? 0.
Pf)
Let L is accepted by a DFA M (K, ?, ?, q0 , F)
with m states.
Consider input w ?1 ? 2 ?l, l ? m.
Then,
. . .
By pigeonhole, there exists j, k with 0? j lt k ?
l st. qj qk.
It is then seen that if qm?F, then
uw ?L,
uvw ?L,
uv2w ?L,
. . .,
uvnw?L for all n ? 0.
116
Example
  • Show that the language Lanbn n?0 is not
    regular.

Pf)
By pumping theorem,
Suppose that L is regular.
? z anbn uvw?L st. uvmw?L for all m ? 0.
w
Case 1 z a a a b b b
v
u
uvmw?L for all m ? 0
Case 2 z a a a b b b
v
w
u
u
Case 3 z a a a b b b
w
v
117
The Chomsky Hierarchy
Lanbn n?0
118
Lecture 5 Finite Automata
  • Implementation of DFA

??????? ?????????
119
Example
  • Input a 0/1 sting.
  • If the numbers of 0 and 1 in the string are both
    even, then it is legal otherwise, it is illegal.
  • 0011001001(legal)
  • 11001001001(illegal)
  • Writing a C program to do so.

120
Finite State Machine
Examples
00100011ltCRgt
01101011ltCRgt
001010101ltCRgt
0010010101ltCRgt
121
Finite State Machine
q1
q2
ok
q0
q3
err
q3
q0
err
err
q2
q1
The Parser
122
Implementation (I)
define q0 0 define q1 1 define q2 2 define q3
3 define fini 4
123
Implementation (I)
int parser43 q1, q2, fini, q0, q3, fini,
q3, q0, fini, q2, q1, fini int stateq0 int
event char str
124
Implementation (I)
void ToEvent(char c) if(c 0) event
0 else if(c 1) event 1 else event
2
Event (or Message) Encoding
125
Implementation (I)
void main() // Ask user to input a 0/1
string // Store the string into str state q0
//initialization while(state!fini) ToEvent(s
tr) EventHandler(event)
Event (or Message) Loop
126
Implementation (I)
void EventHandler(int event) int next_state
parserstateevent switch(next_state)
case fini printf(s\n, stateq0 ? ok
err) default state next_state
//change state
Event Handler
127
Implementation (II)
pq1
pq2
ok
pq0
pq3
err
pq3
pq0
err
err
pq2
pq1
The Parser
128
Implementation (II)
define q0 0 define q1 1 define q2 2 define q3
3 define fini 4
void pq0(), pq1(), pq2(), pq3() void ok(), err()
129
Implementation (II)
void pq0() state q0 void pq1() state
q1
void pq2() state q2 void pq3() state
q3
130
Implementation (II)
void ok() printf(ok\n) state
fini void err() printf(error\n) state
fini
131
Implementation (II)
typedef void (FUNCTION)() FUNCTION
parser43 pq1, pq2, ok, pq0, pq3,
err, pq3, pq0, err, pq2, pq1, err
132
Implementation (II)
void main() // Ask user to input a 0/1
string // Store the string into str state q0
//initialization while(state!fini) ToEvent(s
tr) (parserstateevent)()
Event (or Message) Loop
Write a Comment
User Comments (0)
About PowerShow.com