1.36k likes | 1.69k Views
Lecture 5: Finite Automata. 虞台文. 大同大學資工所 智慧型多媒體研究室. Content. Alphabets and Languages Deterministic Finite Automata Nondeterministic Finite Automata Equivalence of DFA &NFA Properties of Languages Accepted by FA’s Finite Automata & Regular Expressions Languages Not Accepted by FA’s.
E N D
Lecture 5: Finite Automata 虞台文 大同大學資工所 智慧型多媒體研究室
Content • Alphabets and Languages • Deterministic Finite Automata • Nondeterministic Finite Automata • Equivalence of DFA &NFA • Properties of Languages Accepted by FA’s • Finite Automata & Regular Expressions • Languages Not Accepted by FA’s
Lecture 5: Finite Automata Alphabets and Languages 大同大學資工所 智慧型多媒體研究室
Alphabets • Alphabet a finite set of symbols • Examples: binary alphabet decimal alphabet Roman alphabet Greek alphabet my alphabet
Strings • String over an alphabet () a finitesequence of symbols from • * the set of allstrings over • Examples:
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
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.
Countability of * * is countably infinite for any finite alphabet . Example: * can be enumerated by:
Languages • Language L over any subset of * i.e., L* • How many possible languages over ? • How to specify a language? uncountably infinite
Operations of Languages • Complement • Union • Intersection
Operations of Languages • Complement, Union and Intersection • Concatenation • Closure or Kleene Star • Positive Closure
? ? 1909 – 1994 Example: Kleene Star
? ? 1909 – 1994 Example: Kleene Star
? ? 1909 – 1994 Example: Kleene Star
Language Recognition Device A machine or algorithm to answer the question
Lecture 5: Finite Automata Deterministic Finite Automata 大同大學資工所 智慧型多媒體研究室
a b a a b b a b a a q0 q5 q1 Finite control q2 q4 q3 Finite State Machine Input tape Reading Head
Definition Deterministic Finite Automaton A deterministicfinite automaton is a 5-tuple (K, , , s, F) K: a finite set of states : a finite set of symbols : the transition functionK K sK: the initial state FK: the set of final states
1 1 q0 q1 0 0 > 1 0 0 symbol 1 0 1 q2 q3 q0 q2 q1 q1 q3 q0 state q2 q0 q3 q3 q1 q2 (K, , , s, F) Example K={q0, q1, q2, q3} ={0, 1} s=q0 F={q0}
1 Input tape 0 1 1 0 0 1 0 1 1 q0 q1 0 0 Reading Head > q0 q1 1 0 0 Finite control q3 q2 1 q2 q3 Operations of a DFA
1 Input tape 0 1 1 0 0 1 0 1 1 q0 q1 0 0 Reading Head > q0 q1 1 0 0 Finite control q3 q2 1 q2 q3 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
1 Input tape 0 1 1 0 0 1 0 1 1 q0 q1 0 0 Reading Head > q0 q1 1 0 0 Finite control q3 q2 1 q2 q3 DFA As a Language Acceptor Accepted • The input string is accepted by the machine if the reading head ends at a final state. • Otherwise, it is rejected. JFLAP Rejected
1 Input tape 0 1 1 0 0 1 0 1 1 q0 q1 0 0 Reading Head > q0 q1 1 0 0 Finite control q3 q2 1 q2 q3 DFA As a Language Acceptor What language the machine accepts? • The input string is accepted by the machine if the reading head ends at a final state. • Otherwise, it is rejected.
1 Input tape 0 1 1 0 0 1 0 1 1 0 0 Reading Head q0 q1 > q0 q1 1 0 0 Finite control q3 q2 1 q2 q3 DFA As a Language Acceptor What language the machine accepts? • The input string is accepted by the machine if the reading head ends at a final state. • Otherwise, it is rejected. q3
w u Input tape a b a a b b a b a a Reading Head q0 q5 q1 Finite control q2 q4 q3 M = (K, , , s, F) Memory Configuration of a DFA
w u Input tape a b a a b b a b a a Reading Head q0 q5 q1 Finite control q2 q4 q3 M = (K, , , s, F) Memory Configuration of a DFA Does not effect the result.
M = (K, , , s, F) Memory Configuration of a DFA
Memory Configuration of a DFA M = (K, , , s, F)
w u Input tape a b a a b b a b a a Reading Head q0 q5 q1 Finite control q2 q4 q3 Memory Configuration of a DFA
* Yields in some (including zero) steps if
String Acceptance by a DFA M = (K, , , s, F) w* is said to be accepted by M iff such that
Language Defined by a DFA M = (K, , , s, F) Language L(M) denotes the set of all strings accepted by M, i.e.,
1 1 q0 q1 0 0 (q2, 100100110) (q3, 00100110) > (q1, 0100110) 1 0 0 (q3, 100110) (q2, 00110) 1 (q0, 0110) q2 q3 (q2, 110) (q3, 10) (q2, 0) (q0, ) w=0100100110 Example wL(M)? (q0, 0100100110) M
1 1 q0 q1 0 0 (q2, 100100110) (q3, 00100110) > (q1, 0100110) 1 0 0 (q3, 100110) (q2, 00110) 1 (q0, 0110) q2 q3 (q2, 110) (q3, 10) (q2, 0) (q0, ) w=0100100110 Example wL(M)? (q0, 0100100110) M
1 1 q0 q1 0 0 > 1 0 0 1 q2 q3 Example M
a b a a > q0 q1 q2 q3 a b b b Example
a a a b a b > a, b > a, b b b a, b a, b a, b Exercises • Describe informally the languages accepted by the deterministic finite automata shown below: (a) (b)
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}.
Lecture 5: Finite Automata Nondeterministic Finite Automata 大同大學資工所 智慧型多媒體研究室
Review Deterministic Finite Automaton A deterministicfinite automaton is a 5-tuple (K, , , s, F) K: a finite set of states : a finite set of symbols : the transition functionK K sK: the initial state FK: the set of final states
non , Definition Nondeterministic Finite Automaton A nondeterministicfinite automaton is a 5-tuple (K, , , s, F) A deterministicfinite automaton is a 5-tuple (K, , , s, F) K: a finite set of states : a finite set of symbols : the transition functionK 2K : the transition functionK K 2K sK: the initial state FK: the set of final states
a a p p Transition Functions of FA’s : K K : K 2K K q Q K
a a p p Transition Functions of FA’s : K K : K 2K Change to one of state in Q nondeterministically. Change to state q deterministically. K q Q K
M = (K, , , s, F) Yields in One Step if
* if is possible. M = (K, , , s, F) Yields in some (including zero) steps
String Acceptance by a NFA M = (K, , , s, F) w* is said to be accepted by M iff such that
Language Defined by an NFA M = (K, , , s, F) Language L(M) denotes the set of all strings accepted by M, i.e.,
a a b a > a q0 q1 q2 q3 b > q0 a b b b q4 a b a,b Example: L=(ab+aba)* NFA DFA q1 q2
a > q0 a > q0 b a a b b L=(ab+aba)* Extension: -Move & Multi-Move q1 NFA q2 q1 q2