CSE 311 Foundations of Computing I Lecture 24 Finite State Machines Autumn 2012 CSE 3111.

16
CSE 311 Foundations of Computing I Lecture 24 Finite State Machines Autumn 2012 Autumn 2012 CSE 311 1

Transcript of CSE 311 Foundations of Computing I Lecture 24 Finite State Machines Autumn 2012 CSE 3111.

CSE 311: Foundations of Computing

CSE 311 Foundations of Computing ILecture 24Finite State MachinesAutumn 2012

Autumn 2012CSE 3111AnnouncementsReading assignments7th Edition, Sections 13.3 and 13.46th Edition, Section 12.3 and 12.45th Edition, Section 11.3 and 11.4Homework 9 will be posted todayDue date, Friday November 30

Autumn 2012CSE 3112Last lecture highlightsFinite state machinesStates, transitions, start state, final statesLanguages recognized by FSMs

Autumn 20123s0s2As110,10,10,1R00,10010111111101010100001001110111100010000100001101111100000001111Non-determinismA non-deterministic finite automaton (NFA) allows multiple outputs to have the same labelA string s is accepted by a NFA if there is some path through the NFA with labels s that reaches an accepting stateAutumn 2012CSE 3114s0s2As10,10,110,1Strings over {0, 1, 2}*M1: Strings with an even number of 2s

M2: Strings where the sum of digits mod 3 is 0Autumn 2012CSE 3115s0s1t0t2t1Recognize strings with an even number of 2s and a mod 3 sum of 0Autumn 2012CSE 3116s0t0s1t0s1t2s0t1s0t2s1t1State machines with outputAutumn 2012CSE 3117InputOutputStateL Rs1s1s2Beeps2s1s3s3s2s4s4s3s4BeepS3S4S1S2RLRLRLLRTug-of-warVending MachineAutumn 2012CSE 3118

Enter 15 cents in dimes or nickelsPress S or B for a candy bar

Vending Machine, Version 1051015DDNNN, DB, SBasic transitions on N (nickel), D (dime), B (butterfinger), S (snickers)Vending Machine, Version 20 B51015Adding output to states: N Nickel, S Snickers, B Butterfinger15 N00 SNNNNNBDDDDDBSSVending Machine, Final Version0 B51015Adding additional unexpected transitions15 N00 SNNNNNBDDDDDBSS15 DSBB,SB,SB,SB,SB,SNNNDDDVending Machine, Final Version0 B51015Slide from Nov 21, 2011 Lecture15 N00 SNNNNNBDDDDDBSS15 DSBB,SB,SB,SB,SB,SNNNDDDFind the bug!Another way to look at DFAsAutumn 2011CSE 31113s0s2s3s11110,1000Lemma: x is in the language recognized by a DFA iff x labels a path from the start state to some final stateDefinition: The label of a path in a DFA is the concatenation of all the labels on its edges in orderNondeterministic Finite Automaton (NFA)Graph with start state, final states, edges labeled by symbols (like DFA) butNot required to have exactly 1 edge out of each state labeled by each symbol - can have 0 or >1Also can have edges labeled by empty string Definition: x is in the language recognized by an NFA iff x labels a path from the start state to some final state

Autumn 2011CSE 31114s0s2s3s11110,10,1Design an NFA to recognize the set of binary strings that contain 111 or have an even # of 1sAutumn 2011CSE 31115Three ways of thinking about NFAsOutside observer: Is there a path labeled by x from the start state to some final state?

Perfect guesser: The NFA has input x and whenever there is a choice of what to do it magically guesses a good one (if one exists)

Parallel exploration: The NFA computation runs all possible computations on x step-by-step at the same time in parallel

Autumn 2011CSE 31116