Finite-State Machines 15-211 Fundamental Data Structures and Algorithms Peter Lee March 11, 2003.

Slides:



Advertisements
Similar presentations
CS 345: Chapter 9 Algorithmic Universality and Its Robustness
Advertisements

CSE 311 Foundations of Computing I
CSC 361NFA vs. DFA1. CSC 361NFA vs. DFA2 NFAs vs. DFAs NFAs can be constructed from DFAs using transitions: Called NFA- Suppose M 1 accepts L 1, M 2 accepts.
Complexity and Computability Theory I Lecture #4 Rina Zviel-Girshin Leah Epstein Winter
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University 2005.
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
1 Section 14.1 Computability Some problems cannot be solved by any machine/algorithm. To prove such statements we need to effectively describe all possible.
Finite Automata Great Theoretical Ideas In Computer Science Anupam Gupta Danny Sleator CS Fall 2010 Lecture 20Oct 28, 2010Carnegie Mellon University.
Introduction to Computability Theory
Lecture 3UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 3.
Lexical Analysis III Recognizing Tokens Lecture 4 CS 4318/5331 Apan Qasem Texas State University Spring 2015.
Courtesy Costas Busch - RPI1 Non Deterministic Automata.
61 Nondeterminism and Nodeterministic Automata. 62 The computational machine models that we learned in the class are deterministic in the sense that the.
Finite Automata Finite-state machine with no output. FA consists of States, Transitions between states FA is a 5-tuple Example! A string x is recognized.
Lecture 3 Goals: Formal definition of NFA, acceptance of a string by an NFA, computation tree associated with a string. Algorithm to convert an NFA to.
Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Fall 2008.
Lecture 18 NFA’s with -transitions –NFA- ’s Formal definition Simplifies construction –LNFA- –Showing LNFA  is a subset of LNFA and therefore a subset.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Nondeterminism.
Lecture 3 Goals: Formal definition of NFA, acceptance of a string by an NFA, computation tree associated with a string. Algorithm to convert an NFA to.
Automata & Formal Languages, Feodor F. Dragan, Kent State University 1 CHAPTER 5 Reducibility Contents Undecidable Problems from Language Theory.
Fall 2006Costas Busch - RPI1 Non-Deterministic Finite Automata.
CS5371 Theory of Computation Lecture 4: Automata Theory II (DFA = NFA, Regular Language)
CS Chapter 2. LanguageMachineGrammar RegularFinite AutomatonRegular Expression, Regular Grammar Context-FreePushdown AutomatonContext-Free Grammar.
Costas Busch - LSU1 Non-Deterministic Finite Automata.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
Finite State Machines Data Structures and Algorithms for Information Processing 1.
CS 540 Spring CS 540 Spring 2013 GMU2 The Course covers: Lexical Analysis Syntax Analysis Semantic Analysis Runtime environments Code Generation.
Formal Language Finite set of alphabets Σ: e.g., {0, 1}, {a, b, c}, { ‘{‘, ‘}’ } Language L is a subset of strings on Σ, e.g., {00, 110, 01} a finite language,
REGULAR LANGUAGES.
1 Unit 1: Automata Theory and Formal Languages Readings 1, 2.2, 2.3.
Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski
Introduction to CS Theory Lecture 15 –Turing Machines Piotr Faliszewski
Lexical Analysis Constructing a Scanner from Regular Expressions.
4b 4b Lexical analysis Finite Automata. Finite Automata (FA) FA also called Finite State Machine (FSM) –Abstract model of a computing entity. –Decides.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
CSE 311 Foundations of Computing I Lecture 27 FSM Limits, Pattern Matching Autumn 2012 CSE
Finite State Machines Concepts DFA NFA.
D E C I D A B I L I T Y 1. 2 Objectives To investigate the power of algorithms to solve problems. To explore the limits of algorithmic solvability. To.
Regular Expressions Fundamental Data Structures and Algorithms Peter Lee March 13, 2003.
Finite State Machines 1.Finite state machines with output 2.Finite state machines with no output 3.DFA 4.NDFA.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 1 Regular Languages Some slides are in courtesy.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2007.
Transparency No. 2-1 Formal Language and Automata Theory Homework 2.
1 Turing Machines and Equivalent Models Section 13.1 Turing Machines.
Nondeterministic Finite Automata (NFAs). Reminder: Deterministic Finite Automata (DFA) q For every state q in Q and every character  in , one and only.
Chapter 5 Finite Automata Finite State Automata n Capable of recognizing numerous symbol patterns, the class of regular languages n Suitable for.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
Complexity and Computability Theory I Lecture #5 Rina Zviel-Girshin Leah Epstein Winter
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2006.
1 Unit – 5 : STATE MACHINES Syllabus: Languages and Grammars – Finite State Machines State machines and languages – Turing Machines – Computational Complexity.
CS412/413 Introduction to Compilers Radu Rugina Lecture 3: Finite Automata 25 Jan 02.
MA/CSSE 474 Theory of Computation Universal Turing Machine Church-Turing Thesis (Winter 2016, these slides were also used for Day 33)
CIS 262 Automata, Computability, and Complexity Fall Instructor: Aaron Roth
WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Dr. Mohammad Nassef Department of Computer Science, Faculty of Computers and Information, Cairo University.
CIS Automata and Formal Languages – Pei Wang
Non Deterministic Automata
Chapter 2 Finite Automata
CSE 105 theory of computation
Chapter 2 FINITE AUTOMATA.
Hierarchy of languages
COSC 3340: Introduction to Theory of Computation
Non-Deterministic Finite Automata
8. Introduction to Turing Machines
Finite Automata Reading: Chapter 2.
4b Lexical analysis Finite Automata
4b Lexical analysis Finite Automata
Instructor: Aaron Roth
CSCI 2670 Introduction to Theory of Computing
Chapter 1 Regular Language
CSCI 2670 Introduction to Theory of Computing
Presentation transcript:

Finite-State Machines Fundamental Data Structures and Algorithms Peter Lee March 11, 2003

Announcements  Homework #4 is due next week!  Monday, March 17, 11:59pm  Reading:  Handout  Midterm Exam has been graded  Get your exam at recitation

Models of Computation

Models of computation  Understanding computation – 1.What problems can be solved by computers? 2.What problems cannot? 3.What problems can be solved “quickly”? 4.Are there fundamental differences among computers with respect to the kinds of problems they can solve? (Ignoring space and time.)

Models of computation  What details of these machines do we need to understand in order to understand computation?

Models of computation  What details about these computers can be ignored in answering these questions?  In other words:  What can abstracted away?  abstrahere = to drag away

Time, code, space

Computability theory 1.What problems can be solved by computers? 2.Are there well-stated mathematical problems that cannot be solved by computers?

Computability theory  The Halting Problem:  Can a program be written that, given another program and its input, determines if that program will terminate when executed?  Can the Java compiler be enhanced to check whether programs will always terminate?

Computability theory  Note:  We can prove termination (or show a counterexample) for most programs we write.  The question is whether this can be done, in an automatic way, for all programs.

Computability theory 1.Which problems can be solved by computers? 2.Are there well-stated mathematical problems that cannot be solved by computers?

Computability theory  The Halting Problem is undecidable.  Turing, Church (1936)  This means that it is not possible to write a program to solve the Halting Problem.  Proofs of such statements are made on simplified mathematical models of computation

Other questions  Performance of algorithms  Model is surrogate for “computer time”  Which operations get counted?  What are their relative costs?  Does it matter? Why do we use big-O?  Correctness of algorithms and code  How can we be sure the programs does what it is intended to do?  If it fails, what is broken?  Computer?  Program?  Compiler?  OS?

Examples of general computational models Examples of general models of computation  CPU + Memory  Random access machine  CPU + “Tape”  Turing machine (1936)  CPU + Many counters  Minsky machine (1960s)  Functions of functions  Lambda calculus  String matching systems  Post production systems  Function programs  General recursive functions General purpose computers  laptop  cell phone  palm device  calculator ?

 Abstractly Infinite tape Finite control  Concretely The Turing Machine

 Abstractly Infinite 2D array Finite control  Concretely The Random Access Machine

The general models  These general models are essentially equivalent.  Each model can solve the same problems as any other model.  This is shown by simulating one model with another.  Example: simulating the Turing machine tape with a random access memory.

The general models  Anything that is felt to be effectively computable can be described within one of the formal models.  Church’s Thesis (1930s)

Simpler models But:  There are some simpler models that cannot compute all computable functions M 1 < M 2 < … < Computable  One class of simple models: Finite State Machines Finite control

FSMs

The FSM model  A finite-state machine is a computing machine that  takes a string as input, and  outputs a yes/no answer  When an FSM outputs “yes” for a particular input string, we say that it “accepts” or “recognizes” it Input String FSM {Yes, No}

The FSM model  Inputs:  Strings built from a fixed alphabet Alphabet: {a,b,c} Strings: aabbacabcaa aba b aaac  Machine: A directed graph  Nodes: states of the machine  Edges: transitions from one state to another  Determined by the next input character 1 0 a b

The FSM model  Special states  Start state  Final or accepting state Input String FSM {Yes, No} aa bba,b

FSM Example  Input alphabet{a, b}  States{q0, q1, q2}  Start stateq0  Final states{q2}  Transitions{ (q0,a)  q1, … } aa bba,b Which strings of as and bs are accepted?

Finite State Machines (FSMs)  Key limitation: memory size is fixed  Independent of input size.  No infinite tape or random-access memory Input String FSM {Yes, No}

What is not finite state?  There are simple string languages that cannot be recognized using FSMs  Examples (w is any string)  ww  ww R  Hint: How much memory is needed to recognize ww?  Hint: How can ww R be recognized?  Other computational models  finite state < [other models] < computable

Why study FSMs  A common algorithm design technique  Tokenization (“lexical analysis”)  Programs, web pages, text, …  Control systems  Elevators, boilers, soda machines, …  Computational model  Linear time stream processing  Simple and elegant

History  Origin: Neuronal models  McCulloch and Pitts (1943)  Reworked into finite state machines  Kleene (1954)  Related to Markov chains

The soda machine – concretely

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

FSM Example  Which strings of as and bs are accepted?  Input alphabet{a, b}  States{q0, q1, q2}  Start stateq0  Final states{q2} a a b bb

Deterministic FSMs (aka, DFAs)   Input alphabet  S State set  q0  S Initial state  F  S Final states  :S    S Transition function M = (, S, q0, F, )

Transition functions  Given a state and the next input symbol, give us the next state. :S    S This is normally extended to ’:S  *  S

Transition functions  Inductively: ’(q, ) = q ’(q, aw) = ’((q, a), w) the empty string input symbol remainder of input string

Formal languages  The language accepted by M: L(M) = {w | ’(q0,w)  F} This is the set of all strings accepted by M

Formal languages  What is the language accepted by this DFA? a a b bb

Enhancing the model  Nondeterminism  Allow the machine to be in more than one state at once  Equivalently, allow more than one transition on any given input symbol  Enable the machine to “guess” which transition is the correct one

Making the NFA model precise   Input alphabet  S State set  q0  S Initial state  F  S Final states  :S    (S) Transition function M = (, S, q0, F, )

The language of the NFA  Extend :S    P(S) to ’:S  *  P(S) ’(q, ) = {q} ’(q, aw) =  p(q, a) ’(p, w)  Language accepted by M  L(M) = {w | ’(q0,w)  F  }

The language of the NFA  Enhance :S    P(S) to ’:S  *  P(S) to ’’:P(S)  *  P(S) ’’({q1,…qn}, w) =  i ’(qi, w)

Formal languages  What is the language accepted by this NFA? a b a, b

Quiz Break

Red-green quiz AB CD x1x1 x2x2 x3x3 Consider this marble toy. 1) Model it as a FSM: marble in A is 0 input marble in B is 1 input sequence of marbles is accepted if the last marble comes out of D 2) What is the language accepted by this toy?

A Big Question  Are there languages L that can be accepted by an NFA but no DFA?

Another extension  Add  transitions  The “” represents “empty”, so a  transition means a transition without consuming any input.

Big Questions 1. Are there languages L that can be accepted by NFAs but not DFAs? 2. Are there languages L that can be accepted by NFAs but not NFAs?

Big Questions 1. Are there languages L that can be accepted by NFAs but not DFAs? No! 2. Are there languages L that can be accepted by NFAs but not NFAs? No!

Proving DFA  NFA  DFA  NFA   NFA  DFA 

Proving DFA  NFA  DFA  NFA  Obvious  NFA  DFA 

The Idea  An NFA can be in more than one state at a time  Define a DFA whose states correspond to combinations of the NFA states  In the NFA, let N = |S|  How many states will the corresponding DFA have?

Doing it  In the NFA  Suppose S = {0,1,2}  In the DFA, construct  S = {[],[0],[1],[2],[01],[02],[12],[012]}

Doing it: the subset construction  Both machines have the same input alphabet  In the NFA  Suppose S = {0,1,2}  3 states  In the DFA, construct  S = {[],[0],[1],[2],[01],[02],[12],[012]}  8 states  Modeling all possible combinations of the 3 NFA states

Doing it  In the NFA  Suppose S = {0,1,2}  In the DFA, construct  S = {[],[0],[1],[2],[01],[02],[12],[012]}  In the NFA  Suppose ({0}, a) = {0,1}  In the DFA, construct  ([0], a) = [01]

Doing it  In the NFA  Suppose S = {0,1,2}  In the DFA, construct  S = {[],[0],[1],[2],[01],[02],[12],[012]}  In the NFA  Suppose ({0}, a) = {0,1}  Suppose ({0,1}, b) = {0,2}  In the DFA, construct  ([0], a) = [01]  ([01], b) = [02]

Doing it  In the DFA, construct  Initial state [0]  In the DFA, construct  Final states [2], [02], [12], [012]

Completing the proof  Show that the two machines accept the same language Next time

Big Question, revisited  Are there languages L that can be accepted by NFAs but not DFAs? No! We sketched the proof of this by showing how, given an NFA, a DFA can be constructed that accepts the same languages

Big Questions, revisited 1. Are there languages L that can be accepted by NFAs but not DFAs? No! We sketched the proof of this by showing how, given an NFA, a DFA can be constructed that accepts the same languages 2. Are there languages L that can be accepted by NFAs but not NFAs? No! Similar proof technique…

Summary  Introduction to some big concepts  models of computation  finite state machines  deterministic and nondeterministic automata  formal languages  Next time:  what can we do with FSMs?