Presentation is loading. Please wait.

Presentation is loading. Please wait.

Finite State Machines Concepts DFA NFA.

Similar presentations


Presentation on theme: "Finite State Machines Concepts DFA NFA."— 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 What kind of questions can we answer!
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 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. Input String FSM {Yes, No}

6 The FSM model Inputs: Machine: A directed graph Special states 1 2 FSM
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 Final or accepting 1 2 a b a,b Input String FSM {Yes, No}

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

8 The soda machine – concretely

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

10 Making the DFA model precise
 Input alphabet S State 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 to minimize space?
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 a b 1 2 3 4

12 Representing the machine
Matrix representation Why? Running Time? a b 1 2

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* =

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


Download ppt "Finite State Machines Concepts DFA NFA."

Similar presentations


Ads by Google