280 likes | 851 Views
Finite State Automata. Formal Specification of Languages. Generators Context-free Grammars Regular Expressions Recognizers Parsers, Push-down Automata Finite State Automata FSA is a mechanism to recognize a set of valid inputs before carrying out an action.
E N D
Finite State Automata L9FSA
Formal Specification of Languages • Generators • Context-free Grammars • Regular Expressions • Recognizers • Parsers, Push-down Automata • Finite State Automata • FSA is a mechanism to recognize a set of valid inputs before carrying out an action. • FSA is a notation for describing a family of language recognition algorithms. L9FSA
Parity Problem 1 0 EP 0 OP 1 L9FSA
Basic Features • Consumes the entire input string. • Remembers the parity of the bit string by abstracting from the number of 1s in the string. • Finite amount of memory required for this purpose. • Observe that counting requires unbounded memory, while computing the parity requires very small and fixed amount of memory. • Accepts/Rejects the input in a deterministic fashion. L9FSA
State • Indicates the status of the machine after consuming some portion of the input. • Summarizes the history of the computation that is relevant to the future course of action. • Initial / Start State • Final / Accepting state • State Transition 0 1 Even Parity Odd Parity L9FSA
Deterministic Finite State Automaton (DFA) Q: Finite set of states S: Finite Alphabet d: Transition function total function from QxS to Q : Initial/Start State F : Set of final/accepting state L9FSA
Operation of the machine 0 0 1 Input Tape • Read the current letter of input under the tape head. • Transit to a new state depending on the current input and the current state, as dictated by the transition function. • Halt after consuming the entire input. Finite Control L9FSA
Associating Language with the DFA • Machine configuration: • Yields relation: • Language: L9FSA
Examples L9FSA
Set of strings over {a,b} that contain bb • Design states by parititioning S*. • Strings containing bb q2 • Strings not containing bb • Strings that end in b q1 • Strings that do not end in b q0 • Initial state: q0 • Final state: q2 L9FSA
State Diagram and Table a a b q0 q1 q2 b a b L9FSA
Strings over {a,b} that do not contain bb a a b q0 q1 q2 b a b L9FSA
DFA for the complement of L given DFA for L Let M = (Q,S,d,q0,F) be a DFA. Then, M’ = (Q,S,d,q0,Q-F) is a DFA with L(M’) = S* - L(M). Implication: Languages associated with DFAs are closed under complementation. (Recall that languages associated with regular expressions are closed under union, concatenation, and Kleene Star operations, by definition.) L9FSA
Strings over {a,b} containing even number of a’s and odd number of b’s. S* Ea Oa Eb Ob Eb Ob b [Ea,Eb] [Ea,Ob] b a a a a b [Oa,Ob] [Oa,Eb] b L9FSA
(ab)*c S* valid prefix invalid prefix end_a end_b end_c a a Ea Eb b c a,c l b c Ec Err a,b,c a,b,c b L9FSA
(ab)*c S* valid prefix invalid prefix end_a end_b end_c a Ea Eb b c a,c b Ec Err a,b,c a,b,c L9FSA
Nondeterministic Finite Automata a a qi qi qj qj a DFA a qk q NFA L9FSA
How do we associate a language with an NFA? • Every DFA is an NFA. However, does non-determinism make NFAs strictly more expressive (powerful) than DFAs? DFA: Unique computation for a given string NFA: Accept if there exists an accepting computation L9FSA
NFA State Diagram (Strings over {a,b} ending in bb) b a q0 q1 q2 b b L9FSA
Halts in non-accepting state after consuming the input. Halts in accepting state after consuming the input. L9FSA
a b b a q0 q1 q2 b b NFA State Diagram (a Ub)*bb (a Ub)* DFA a b a q0 q1 q2 b b a L9FSA
a b b a q0 q1 q2 a a NFA for (a Ub)*(aaUbb)(a Ub)* a b q11 q22 b b L9FSA
Introducing l-transitions into NFA • A l-transition causes the machine to change its state non-deterministically, without consuming any input. L9FSA
Closure Properties of NFA-ls l l M1 l l M M2 l l L(M)* L(M1) UL(M2) l l l M1 M2 L(M1) L(M2) L9FSA
a1 a2 a3 a3 b3 b1 b2 b3 a … a a a a0 an b b b b … b b b bn This construction cannot be generalized to recognize because the machine will have infinite number of states. L9FSA