1 / 30

Finite State Machines Concepts DFA NFA

Finite State Machines Concepts DFA NFA. Graphs and More. Finites state machines are directed graphs. Nodes-states, Edges-input. Each city represents a state you can be in. Take and edge on some desire(input) Imagine you are doing a food tour of the country, starting in Atlanta

abra-barker
Download Presentation

Finite State Machines Concepts DFA NFA

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Finite State Machines Concepts DFA NFA

  2. Graphs and More • Finites state machines are directed graphs.

  3. Nodes-states, Edges-input • Each city represents a state you can be in. • Take and edge on some desire(input) • Imagine you are doing a food tour of the country, starting in Atlanta • You want to eat…Perogies, Philly Cheese Steak, Cuban

  4. Edges as input • The food transitions are along the pathway. • Certain food tours are allowed, others just don’t work out! • Valid: Perogies, Philly Cheese Steak, Miami Cuban • Invalid: Perogies, Jambalaya, Cuban • Same food can be found in several places, and assume there is a finite set of foods – the alphabet • There are also a finite set of cities that you can be in, or go to – the states • Add restriction that for health reasons, the last food you eat has to be Cuban! ( ACCEPTING vs REJECT states) • What kind of questions can we answer!

  5. FSM Input String {Yes, No} Finite State Machines (FSMs) • What are the problems we are trying to solve? • Acceptor – takes an input and tells you whether the input matches some specifications. (Are you in or are you out) • Transducers – working thru input data to modify the behavior of some process. • Key limitation - memory size is fixed • Independent of input size.

  6. a a 0 1 2 b b a,b FSM Input String {Yes, No} The FSM model • Inputs: • Strings built from a fixed alphabet • Machine: A directed graph • Nodes: states of the machine • Edges: transitions from one state to another • Special states • Start • Finalor accepting

  7. 2 FSM Decider Example • Which strings of as and bs are accepted? • Input alphabet {a, b} • States {q0, q1, q2} • Start state q0 • Final states {q2} a a 0 1 b b a,b

  8. The soda machine – concretely

  9. Input alphabet $0.25 Return-coin States Ready-for-coins 25 50 Empty … The soda machine – abstractly

  10. Making the DFA model precise • Input alphabet • SState set • q0  S Initial state • F  S Final states • :S   S Transition function M = (, S, q0, F, )

  11. Building FSMs • An FSM is a directed graph • How large is the input alphabet? • How many states? • How fast must it run? • How to minimize space? • Representations • Matrix • Array of lists • Hashtable • Overlapping hashtable • Switch statement

  12. Representing the machine • Matrix representation • Why? • Running Time?

  13. Process machines • Coke machine • Speech recognition – add probability to the transitions • TCP protocol • Parsers (HTML)

  14. TCP Protocol ( don’t worry …)

  15. Deciders • “Are you IN or are you OUT” - Jerry Maguire

  16. Simple DFA example • HTML Parser – Is it valid HTML? • Accepts strings that end in 1 , å= {0,1} • Create a machine that accepts string which contain the sub-string “001” • 0010, 1001 are in. • 11, 0000 are out • Working it out… Skip all 1’s, perk up when you see a 0. ( you may have just come upon the substring ). Skip back if you see a 1 too early. • 1. Seen no symbols of the pattern • 2. Just seen a 0 • 3. Just seen a 00 • 4. Just seen the entire pattern 001

  17. Regular Expressions • Regular expression. • Way to describe sets of strings • Examples – • (“|” – OR) • (“*” – 0 or more, “+” – one or more) • (01)* • (a|b)*ab • this | that | theother • 00*11*22* =0+1+2+

  18. Languages and FSMs • A language that can be DECIDED by an FSM is called regular. • Examples • (accepts only these and no other) • a(a|b)*b Easiest way to test whether a language is regular is to see if you can create a machine! L = {a(a|b)*b}

  19. Problems types • What about… a(a|b)*b • What does this mean? • | - OR • * - 0 or more

  20. Problems types • Ends with… (a+b)*ab • Begins with… ab(a+b)* • Contains substring ‘w1’ (a+b)*w1(a+b)* • Even / odd numbers of some character or both! • Leverage the power of the guess

  21. Enhancing the model - NFA • Non-determinism • Allow the machine to be in more than one state at once • On a given input, you could follow multiple paths • If there EXISTS a pathway to an ACCEPT state to deal with the given input, ACCEPT • Examples: • 001 sub-string • a(a|b)*b

  22. The Idea of Non-determinism • An NFA can be in more than one state at a time • 3 ways of looking at it • Coins/fingers on every state you can be at. • A tree of outcomes, put a lemming on each path, if any of them end on a final state, we ACCEPT • Oracle approach. Someone is telling you the right way to go

  23. I like lemmings… • Lemming approach Deterministic Non-deterministic …

  24. More examples • “[.?!][]\"')]*\\($\\|\t\\| \\)[ \t\n]*” • [.?!][]\"')]*($|<tab>|)[<tab><C-j>]* • Emacs regexp: • Any of .? !followed by • Zero or more of ] “ ‘ )followed by • Any of end-of-line, tab, two spaces followed by • Zero or more of space, tab, newline

  25. Big Question • Are there languages L that can be accepted by NFAs but not DFAs? • Are they more “powerful”?

  26. Big Question • Are there languages L that can be accepted by NFAs but not DFAs? No!

  27. What have we gained? • Can we solve harder problems? • We have assumed we can solve problems by only parsing the data once… • What about the ability to back-track? Turing Machines… ( If I only had a memory…)

  28. What can’t you do • Counting (on an unbounded set) • L = {0n1n | n>0} • It needs to remember the number of 0’s it has seen. Since the number of 0’s is not limited we would have to track an infinite set of states. • Violates our memory condition… • We can do L = {0515}

  29. What can’t you do • Counting (on an unbounded set) • L = {0n1n | n>0} • It needs to remember the number of 0’s it has seen. Since the number of 0’s is not limited we would have to track an infinite set of states. • Violates our memory condition… • We can do L = {0515} NEED MORE POWER

  30. End

More Related