160 likes | 251 Views
Magical YES-NO machines. Non-deterministic Finite State Automata (NFA). An idea is born ….
E N D
Magical YES-NO machines Non-deterministic Finite State Automata (NFA)
An idea is born … In 1957, while getting his doctor's degree in mathematics at Princeton, he (Scott)took a summer job at IBM's newly established T. J. Watson Research Center. There, he and a fellow student, Michael Rabin, now a professor at Harvard and the Hebrew University in Jerusalem, developed a new approach to automata theory, the mathematical theory of machines. The results they described in their joint paper subsequently won them computing's highest honor, the Turing Award, in 1976. (See http://www.cs.berkeley.edu/~agni/education.html) Dana Scott Michael Rabin M. Rabin and D. Scott. Finite automata and their decision problems, IBM J. Res. Dev. 3 (1959), 114-125. (you can download this classic paper from IBM’s website: http://domino.research.ibm.com/tchjr/journalindex.nsf/0/cdf6b2949432156385256bfa00683d63?OpenDocument) • Turing Award Citation • For their joint paper "Finite Automata and Their Decision Problem," which introduced the idea of nondeterministic machines, which has proved to be an enormously valuable concept. Their (Scott & Rabin) classic paper has been a continuous source of inspiration for subsequent work in this field. • (See http://www.acm.org/awards/turing_citations/rabin.html)
2 2 1 1 a b b a a b a (2) (1) What is the award-winning idea about? Bluntly put, they added a “magical element” to the usual clock-work of automata and mathematically analyzed its effect! The “magical element”: An “ordinary” clock-work (deterministic) automaton in one of its internal states can react to an input symbol in only one possible way (given by its transition table/diagram). See example (1). But, a magical (non-deterministic) automaton (abbreviated as NFA) in one of its internal states could react to an input symbol in different (more than one) ways “as the situation would demand”—depending on the kind of symbols that might follow in the input string (even before sighting them!). Given an input, one can imagine the machine to “magically choose” a sequence of states that leads to a final state (if one exists). See example (2). • The state-transition of the machine • for input “a” is 1 2 (accepts) and (ii) for input “aa”, 1 1 2 (accepts). Note the different ways in which the machine responds to the first symbol ‘a’ in each case.
What is the award-winning idea about? According to Scott and Rabin*, “A nondeterministic automaton is not a probabilistic machine but rather a machine with many choices in its moves. At each stage of its motion across a tape it will be at liberty to choose one of several new internal states. Of course, some sequence of choices will lead either to impossible situations from which no moves are possible or to final states not in the designated class F. We disregard all such failures, however, and agree to let the machine accept a tape if there is at least one winning combination of choices of states leading to a designated final state.” * M. Rabin and D. Scott. Finite automata and their decision problems, IBM J. Res. Dev. 3 (1959), 114-125.
3 b a a 2 b a 1 How does the “magic” help? According to Scott and Rabin, “The main advantage ofthese machines is the small number of internal states that they require in many cases and the ease in which specific machines can be described.” To be able to appreciate this, consider the following: NFA recognizing L = { wє {a,b}* : w contains an ‘a’ in its last-but-one position } Try to develop a DFA recognizing the same language * • Use your intuition, and not a standard procedure for converting an NFA into an equivalent DFA.
Go away Go away Go away Wel-come How does the “magic” help? Hypothetical programs that exhibit non-determinism (a facility to make magical guesses) apparently solve search problems much faster than their deterministic counterparts. It is not hard to see that making the right guesses (at cross-roads) reduces the search and helps reach an unknown destination (not shown on the map) quicker.
The NFA NFAs: Demonstrating ease of design Consider the language L = {wє {0,1}* | w has a 0 on the 5th position from the end }
NFAs: Demonstrating ease of design … and smaller number of states The equivalent DFAfor the NFA on previous slide!! (Do you think, you could’ve designed this directly, just by intuitive thinking?)
set of states Q (includes s and F) stringwoverΣ set of final states δ: Q x ΣεP (Q) start state s єQ transition function δ: Q x ΣεP (Q) finite set of states input alphabet P(Q) Q Σ 1 2 3 a b {1} {1,2} {1,2,3} . . . x F Q U δ : ? ? ? a 1 Definition of NFA Non-deterministic Finite State Automaton (NFA) (earlier, we had referred to an NFA as a magical “YES-NO machine”.) A 5-tuple (Q, Σ,δ, s, F )
NFAs versus DFAs By definition, DFAs are specific cases of NFAs. But, the following are NOT legitimate for DFAs (but, they are legitimate in the case of NFAs): • Multiple transitions over the same symbol from a certain state • Absence of transitions over some symbol (in the alphabet) from a certain state • Presence of ε-transitions
NFAs: Evolution of states a b b 2 3 1 a b 4 4 4 a a 1 2 a a a a a 1 2 2 1 b b b b 3 1 a 1 3 b b b a a b b b 1 3 1 1 1 2 Consider the language L = {wє {a,b}* | w ends with abb} Input string: aababb 1 Input string: abb 1
0 1 0 ε C NFAs: Demonstrating ease of design Consider the language L = { 0m1n0k : n, m >= 0 and k >= 1 } 0 B A Try to develop a DFA recognizing the same language * • Use your intuition, and not a standard procedure for converting an NFA into an equivalent DFA.
M1 ε s1 f1 f2 f M2 s2 ε final states of the new “combined machine” Start state of the new “combined machine” NFAs: The role of ε’s New machine M: L(M) = L(M1)U L(M2) s
cat rat mat sat . . . tac tar tam tas . . . R(L) L NFA that recognizes the “reverse” of a language Given a language L, its “reverse” is R(L) = { w’ | w’ is the reverse of some wєL }
NFA that recognizes the “reverse” of a language b b L: a’sand b’s, starting with an a 2 1 b a a 1 a b 2 a Given a machine (NFA / DFA) M that recognizes L, how to “transform” it into an NFA M’ (a reverse-machine) that recognizes R(L) ? 1. Change the “start state” into “final state”. 2. Change the “final state” into “start state”. 3. Reverse the arrows of all transitions. Iff δ(q, a) = r in the old machine, then the new machine has δ(r, a) = q R(L): a’sand b’s, ending with an a
2 ε 0 0 2 3 1 0 0 0 ε 1 1 1 3 1 1 NFA that recognizes the “reverse” of a language What if there were more than one final states? Change them into “ordinary states”; add a new start state and draw ε-transitions (arcs) from the new start state to the “old” final states