UW-Madison CS 240 - Lecture 21 - Finite State Machines

Unformatted text preview:

CS/Math 240: Introduction to Discrete Mathematics 4/14/2011Lecture 21 : Finite State MachinesInstructor: Dieter van Melkebeek Scribe: Dalibor Zelen´yDRAFTLast time we started discussing applications of graphs in computer science. We phrased theregister allocation problem in terms of graph coloring. Today we discuss finite state machines, asimple model of a computer that can be viewed as a graph.21.1 Finite State MachinesA finite state machine consists of a finite control, which we view as a set of states the machine canbe in. The machine runs in steps. In each step, it receives an input signal. Upon its receipt, themachine produces an output signal and changes its state according to some rules.One way of describing the functionality of a finite state machine is to draw a graph. Each stateof the machine corresponds to one vertex of the graph. We draw an arrow pointing to the statein which the machine starts after being “powered on”. We use edges to describe the transitionsbetween states. For each transition, we list the inputs that cause it, and also the outputs that areproduced when this transition is made. For example, in Figure 21.1, there is an edge from state 5to state 15. The edge is labeled 10; 0, which means that this transition occurs when the machinereceives the input 10 in state 5. The machine then goes to state 15 and outputs 0.Example 2 1.1 : Consider a vending machine. For simplic ity, suppose i t only sells one item, pricedat 30 cents, and doesn’t give any change. It accepts 5-cent, 10-cent, and 25-cent coins.The states of the machine represent how much money has been put in since the machine firststarted, or since the last item disposal, whichever came last. The machine outputs 1 (i.e., dispensesan i tem) if it has received enough money to dispense an item, and outputs 0 (i.e., does not dispensean item) in all other cases. When it dispenses an item, it goes back to the state that indicates nomoney has been put in. All other state changes are shown in Figure 21.1.⊠Before we define a finite state machine more formally, let’s see another example. This one bringsus closer to the notion of a finite state automaton which we will be discussing for the rest of thelecture.Example 21.2: Consider a machine that recei ves one of the letters A through Z in each step. Itoutputs 1 if the word NANO appears in the sequence of letters given to the machine.We design the machine so that its states indicate how much of the word NANO it has recentlyseen. We label the states 0 through 4. State i indicates that the last i symbols received were thefirst i symbols from the word NANO.If the machine is in state i for i ∈ {0, 1, 2, 3}, it goes to state i + 1 if the next letter given to itas input is the (i + 1)st letter of the word NANO.What if the machine receives an input that does not continue spelling the word NANO? Thenthe machine must go back to an earlier state, but not necessarily the starting state. For example, ifthe last three inputs received were NAN, the machine is in state 3. If the next input is A, the lasttwo letters received are also the first two letters of the word NANO, so the machine goes to state 2.1Lecture 21: Finite State Machines 21.2. Finite State Automata0 5 10 15 20 255;010;025;05;010;025;15;010;025;15;010;025;15;010, 25;15, 10, 25;1Figure 21.1: The transition diagram for the vending machine.Going to any other state could cause the machine to produce incorrect output. For example, if thenext two letters after A were NO, the machine would not recognize that the word NANO appearedin the input if it went to state 0 instead of state 2 after seeing A.Finally, once the machine finds the word NANO, it stays in state 4 and keeps outputting 1 toindicate that it has seen the word. We show all the transitions in Figure 21.2.0 1 2 3 4N;0A;0N;0/∈{A,N};0N;06=N;0O;0N;0A;0/∈{A,N};1anything;1Figure 21.2: A finite state automaton that decides whether a sequence of inputs contains the wordNANO in it.⊠21.2 Finite State AutomataThe finite state machine from Example 21.2 has two special properties. First, there are only twooutput symbols, 0 and 1, which we can interpret as “no” and “yes” (or “reject” and “accept”),respectively. Second, the output symbol only depends on the state to which the machine transitions,and does not depend on the input. Any finite state machine that satisfies these two properties iscalled a finite state automaton.When can simplify the drawing of a finite state automaton. Since there are only two outputs,and the output only depends on the destination of the transition, we don’t show outputs on theedge labels, and, instead, draw the vertices representing states where the output is “yes” differently2Lecture 21: Finite State Machines 21.2. Finite State Automatathan the vertices representing states where the output i s “no”. We use two circles for the former,and one circle for the latter. We show the result of making there changes to Figure 21.2 in Figure21.3.0 1 2 3 4NAN/∈{A,N}N6=NONA/∈{A,N}anythingFigure 21.3: A finite state automaton that decides whether a sequence of inputs contains the wordNANO in it.21.2.1 Formal DefinitionA finite state automaton receives inputs from some finite set of symbols. We call this finite setan alphabet. The alphabet for Example 21.1 was the set {5, 10, 25}, and the alphabet for Example21.2 was the set {A,. . . ,Z}.Definition 21.1. A finite state automaton is a 5-tuple (S, Σ, ν, s0, A), where• S is a finite set of states.• Σ is a finite set of symbols called the alphabet.• ν : S × Σ → S is the transition function. The inputs to this function are the current stateand the last input symbol. The function val ue ν(s, x) is the state the a uto mato n goes to fromstate s afte r reading symbol x.• The automaton starts in the start state s0∈ S.• The set of accepting states A indicates which states cause the automaton t o output “yes”.Example 21.3: We show what the five parts of the tuple M1= (S, Σ, ν, s0, A) are for the finite stateautomaton in Figure 21.4.• S = {s0, s1}.• Σ = {0, 1}.• ν(s0, 0) = s0, ν(s0, 1) = s1, ν(s1, 0) = s1, ν(s1, 1) = s0.• The start state is s0.• A = {1}.⊠3Lecture 21: Finite State Machines 21.2. Finite State Automatas0s11100Figure 21.4: The automaton M1used in Example 21.3.21.2.2 Strings and LanguagesIn e ach step, a finite state automaton processes some symbol from the alphabet. The input sequencecould be infinite, thus


View Full Document

UW-Madison CS 240 - Lecture 21 - Finite State Machines

Download Lecture 21 - Finite State Machines
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 21 - Finite State Machines and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 21 - Finite State Machines 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?