CSE 311 Foundations of Computing I Lecture 24 FSM Limits, Pattern Matching Autumn 2011 CSE 3111.

Slides:



Advertisements
Similar presentations
CSE 311 Foundations of Computing I
Advertisements

CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.
Regular Expressions and DFAs COP 3402 (Summer 2014)
CSE 311: Foundations of Computing Fall 2013 Lecture 23: Finite state machines and minimization.
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
3.2 Pumping Lemma for Regular Languages Given a language L, how do we know whether it is regular or not? If we can construct an FA to accept the language.
Introduction to Computability Theory
Finite Automata Great Theoretical Ideas In Computer Science Anupam Gupta Danny Sleator CS Fall 2010 Lecture 20Oct 28, 2010Carnegie Mellon University.
1 Introduction to Computability Theory Lecture2: Non Deterministic Finite Automata Prof. Amos Israeli.
Introduction to Computability Theory
1 Introduction to Computability Theory Discussion1: Non-Deterministic Finite Automatons Prof. Amos Israeli.
Courtesy Costas Busch - RPI1 Non Deterministic Automata.
Fall 2006Costas Busch - RPI1 Regular Expressions.
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.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 15 Instructor: Paul Beame.
CS 310 – Fall 2006 Pacific University CS310 Decidability Section 4.1/4.2 November 10, 2006.
1 Single Final State for NFAs and DFAs. 2 Observation Any Finite Automaton (NFA or DFA) can be converted to an equivalent NFA with a single final state.
CS5371 Theory of Computation Lecture 6: Automata Theory IV (Regular Expression = NFA = DFA)
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.
Fall 2006Costas Busch - RPI1 Non-Deterministic Finite Automata.
CS5371 Theory of Computation Lecture 4: Automata Theory II (DFA = NFA, Regular Language)
1 Non-Deterministic Automata Regular Expressions.
1.Defs. a)Finite Automaton: A Finite Automaton ( FA ) has finite set of ‘states’ ( Q={q 0, q 1, q 2, ….. ) and its ‘control’ moves from state to state.
Fall 2004COMP 3351 Another NFA Example. Fall 2004COMP 3352 Language accepted (redundant state)
Costas Busch - LSU1 Non-Deterministic Finite Automata.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
CSE 311: Foundations of Computing Fall 2014 Lecture 23: State Minimization, NFAs.
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,
Lexical Analysis — Part II: Constructing a Scanner from Regular Expressions Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
NFA ε - NFA - DFA equivalence. What is an NFA An NFA is an automaton that its states might have none, one or more outgoing arrows under a specific symbol.
Lexical Analysis — Part II: Constructing a Scanner from Regular Expressions.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
Theory of Computation, Feodor F. Dragan, Kent State University 1 Regular expressions: definition An algebraic equivalent to finite automata. We can build.
CSE 311 Foundations of Computing I Lecture 21 Finite State Machines Autumn 2011 CSE 3111.
CSE 311 Foundations of Computing I Lecture 21 Finite State Machines Spring
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong NFA to DFA.
Lexical Analysis Constructing a Scanner from Regular Expressions.
Overview of Previous Lesson(s) Over View  An NFA accepts a string if the symbols of the string specify a path from the start to an accepting state.
4b 4b Lexical analysis Finite Automata. Finite Automata (FA) FA also called Finite State Machine (FSM) –Abstract model of a computing entity. –Decides.
COMP3190: Principle of Programming Languages DFA and its equivalent, scanner.
Prof. Busch - LSU1 NFAs accept the Regular Languages.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
CHAPTER 1 Regular Languages
CSE 311 Foundations of Computing I Lecture 27 FSM Limits, Pattern Matching Autumn 2012 CSE
CSE 311 Foundations of Computing I Lecture 24 Finite State Machines Autumn 2012 CSE 3111.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
Conversions & Pumping Lemma CPSC 388 Fall 2001 Ellen Walker Hiram College.
Regular Expressions Costas Busch - LSU.
Exercise 1 Consider a language with the following tokens and token classes: ID ::= letter (letter|digit)* LT ::= " " shiftL ::= " >" dot ::= "." LP ::=
UNIT - I Formal Language and Regular Expressions: Languages Definition regular expressions Regular sets identity rules. Finite Automata: DFA NFA NFA with.
CSE 311 Foundations of Computing I Lecture 25 Pattern Matching, Cardinality, Computability Spring
CSE 311: Foundations of Computing Fall 2013 Lecture 26: Pattern matching, cardinality.
CS 154 Formal Languages and Computability February 11 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
CS 154 Formal Languages and Computability February 9 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
Finite Automata Great Theoretical Ideas In Computer Science Victor Adamchik Danny Sleator CS Spring 2010 Lecture 20Mar 30, 2010Carnegie Mellon.
 2004 SDU Lecture4 Regular Expressions.  2004 SDU 2 Regular expressions A third way to view regular languages. Say that R is a regular expression if.
LECTURE 5 Scanning. SYNTAX ANALYSIS We know from our previous lectures that the process of verifying the syntax of the program is performed in two stages:
Regular Languages Chapter 1 Giorgi Japaridze Theory of Computability.
CS412/413 Introduction to Compilers Radu Rugina Lecture 3: Finite Automata 25 Jan 02.
CSE 311 Foundations of Computing I Lecture 20 Context-Free Grammars and Languages Autumn 2012 CSE
 2005 SDU Lecture11 Decidability.  2005 SDU 2 Topics Discuss the power of algorithms to solve problems. Demonstrate that some problems can be solved.
CSE 311 Foundations of Computing I
Chapter 2 FINITE AUTOMATA.
CSE 105 theory of computation
CSE 311 Foundations of Computing I
CSE 311: Foundations of Computing
CSE 311: Foundations of Computing
CSE 311 Foundations of Computing I
Announcements - P1 part 1 due Today - P1 part 2 due on Friday Feb 1st
CSE 105 theory of computation
Presentation transcript:

CSE 311 Foundations of Computing I Lecture 24 FSM Limits, Pattern Matching Autumn 2011 CSE 3111

Announcements Reading assignments – 7 th Edition, Section 13.4 – 6 th Edition, Section 12.4 – 5 th Edition, Section 11.4 Autumn 2011CSE 3112

Last lecture highlights NFAs from Regular Expressions Autumn 2011CSE 3113 (01  1)*

Last lecture highlights “Subset construction”: NFA to DFA Autumn 2011CSE 3114 c a b 0 0,1 1 0 NFA a,b DFA 0 c 1 b b,c 1 0 a,b,c  1 0,

What can Finite State Machines do? We’ve seen how we can get DFAs to recognize all regular languages What about some other languages we can generate with CFGs? – { 0 n 1 n : n≥0 }? – Binary Palindromes? – Strings of Balanced Parentheses? Autumn 2011CSE 3115

A={0 n 1 n : n≥0} cannot be recognized by any DFA Consider the infinite set of strings S={, 0, 00, 000, 0000,...} Claim: No two strings in S can end at the same state of any DFA for A, so no such DFA can exist Proof: Suppose n  m and 0 n and 0 m end at the same state p. Since 0 n 1 n is in A, following 1 n after state p must lead to a final state. But then the DFA would accept 0 m 1 n which is a contradiction Autumn 2011CSE 3116

The set B of binary palindromes cannot be recognized by any DFA Consider the infinite set of strings S={, 0, 00, 000, 0000,...} Claim: No two strings in S can end at the same state of any DFA for B, so no such DFA can exist Proof: Suppose n  m and 0 n and 0 m end at the same state p. Since 0 n 10 n is in B, following 10 n after state p must lead to a final state. But then the DFA would accept 0 m 10 n which is a contradiction Autumn 2011CSE 3117

The set P of strings of balanced parentheses cannot be recognized by any DFA Autumn 2011CSE 3118

9 Pattern Matching Given – a string, s, of n characters – a pattern, p, of m characters – usually m<<n Find – all occurrences of the pattern p in the string s Obvious algorithm: – try to see if p matches at each of the positions in s stop at a failed match and try the next position

10 Pattern p = x y x y y x y x y x x String s = x y x x y x y x y y x y x y x y y x y x y x x

11 x y x y y x y x y x x String s = x y x x y x y x y y x y x y x y y x y x y x x

12 x y String s = x y x x y x y x y y x y x y x y y x y x y x x x y x y y x y x y x x

13 x y String s = x y x x y x y x y y x y x y x y y x y x y x x x x y x y y x y x y x x

14 x y String s = x y x x y x y x y y x y x y x y y x y x y x x x x y x y x y y x y x y x x

15 x y String s = x y x x y x y x y y x y x y x y y x y x y x x x x y x y x y y x y x y y x y x y x x

16 x y String s = x y x x y x y x y y x y x y x y y x y x y x x x x y x y x y y x x y x y y x y x y x x

17 x y String s = x y x x y x y x y y x y x y x y y x y x y x x x x y x y x y y x x y x y y x y x y x x

18 x y String s = x y x x y x y x y y x y x y x y y x y x y x x x x y x y x y y x x y x y y x y x y x x x

19 x y String s = x y x x y x y x y y x y x y x y y x y x y x x x x y x y x y y x x y x y y x y x y x x x x y x x y x y y x y x y x x

20 x y String s = x y x x y x y x y y x y x y x y y x y x y x x x x y x y x y y x x y x y y x y x y x x x x y x x x y x y y x y x y x x

21 x y String s = x y x x y x y x y y x y x y x y y x y x y x x x x y x y x y y x x y x y y x y x y x x x x y x x x x y x y y x y x y x x

22 x y String s = x y x x y x y x y y x y x y x y y x y x y x x x x y x y x y y x x y x y y x y x y x x x x y x x x x y x y y x y x y y x y x y x x

23 x y String s = x y x x y x y x y y x y x y x y y x y x y x x x x y x y x y y x x y x y y x y x y x x x x y x x x x y x y y x x y x y y x y x y x x Worst-case time O(mn)

24 x y String s = x y x x y x y x y y x y x y x y y x y x y x x x x y x y x y y x x y x y y x y x y x x x x y x x x x y x y y x x y x y y x y x y x x Lots of wasted work

25 Better Pattern Matching via Finite Automata Build a DFA for the pattern (preprocessing) of size O(m) – Keep track of the ‘longest match currently active’ – The DFA will have only m+1 states Run the DFA on the string n steps Obvious construction method for DFA will be O(m 2 ) but can be done in O(m) time. Total O(m+n) time

26 Building a DFA for the pattern Pattern p=x y x y y x y x y x x y yy xxxxy xy x

27 Preprocessing the pattern Pattern p=x y x y y x y x y x x y yy xxxxy xy x y

28 Preprocessing the pattern Pattern p=x y x y y x y x y x x y yy xxxxy xy x y x y x x

29 Preprocessing the pattern Pattern p=x y x y y x y x y x x y yy xxxxy xy x y x y x x y x y x

30 Preprocessing the pattern Pattern p=x y x y y x y x y x x y yy xxxxy xy x y x y x x y x y x y y x y

31 Generalizing Can search for arbitrary combinations of patterns – Not just a single pattern – Build NFA for pattern then convert to DFA ‘on the fly’. Compare DFA constructed above with subset construction for the obvious NFA.

A Quick Note... On how to convert NFAs and DFAs to equivalent regular expressions... We’ve already seen – DFAs and NFAs recognize the same languages – NFAs (and therefore DFAs) recognize any language given by a regular expression This completes the equivalence of DFAs and regular expressions Autumn 2011CSE 31132

Generalized NFAs Like NFAs but allow – Parallel edges – Regular Expressions as edge labels NFAs already have edges labeled or a An edge labeled by A can be followed by reading a string of input chars that is in the language represented by A A string x is accepted iff there is a path from start to final state labeled by a regular expression whose language contains x Autumn 2011CSE 31133

Starting from NFA Add new start state and final state Then eliminate original states one by one, keeping the same language, until it looks like: Final regular expression will be A Autumn 2011CSE λ λ λ A

Only two simplification rules: Rule 1: For any two states q 1 and q 2 with parallel edges (possibly q 1 =q 2 ), replace Rule 2: Eliminate non-start/final state q 3 by replacing all for every pair of states q 1, q 2 (even if q 1 =q 2 ) Autumn 2011CSE q1q1 q2q2 A B by A⋃BA⋃B q1q1 q2q2 A B CAB*C q1q1 q3q3 q2q2 q1q1 q2q2 by