15-251 Great Theoretical Ideas in Computer Science.

Slides:



Advertisements
Similar presentations
Formal Languages Languages: English, Spanish,... PASCAL, C,... Problem: How do we define a language? i.e. what sentences belong to a language? e.g.Large.
Advertisements

Deterministic Finite Automata (DFA)
YES-NO machines Finite State Automata as language recognizers.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
1 Languages. 2 A language is a set of strings String: A sequence of letters Examples: “cat”, “dog”, “house”, … Defined over an alphabet: Languages.
Finite Automata Section 1.1 CSC 4170 Theory of Computation.
CS21 Decidability and Tractability
NFAs Sipser 1.2 (pages 47–54). CS 311 Fall Recall… Last time we showed that the class of regular languages is closed under: –Complement –Union.
Regular operations Sipser 1.1 (pages 44 – 47). CS 311 Mount Holyoke College 2 Building languages If L is a language, then its complement is L’ = {w |
Finite Automata Great Theoretical Ideas In Computer Science Anupam Gupta Danny Sleator CS Fall 2010 Lecture 20Oct 28, 2010Carnegie Mellon University.
Intro to DFAs Readings: Sipser 1.1 (pages 31-44) With basic background from Sipser 0.
NFAs Sipser 1.2 (pages 47–54). CS 311 Mount Holyoke College 2 Recall… Last time we showed that the class of regular languages is closed under: –Complement.
Intro to DFAs Readings: Sipser 1.1 (pages 31-44) With basic background from Sipser 0.
Lecture 3UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 3.
1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY (For next time: Read Chapter 1.3 of the book)
CS5371 Theory of Computation
Regular Languages Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 3 Comments, additions and modifications.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
1 Languages and Finite Automata or how to talk to machines...
CS 310 – Fall 2006 Pacific University CS310 Finite Automata Sections: September 1, 2006.
Automata & Formal Languages, Feodor F. Dragan, Kent State University 1 CHAPTER 1 Regular Languages Contents Finite Automata (FA or DFA) definitions, examples,
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.
Foundations of (Theoretical) Computer Science Chapter 1 Lecture Notes (Section 1.1: DFA’s) David Martin With some modifications.
CS5371 Theory of Computation Lecture 4: Automata Theory II (DFA = NFA, Regular Language)
FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such.
1 Regular Languages Finite Automata eg. Supermarket automatic door: exit or entrance.
Topics Automata Theory Grammars and Languages Complexities
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.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
Finite State Machines Data Structures and Algorithms for Information Processing 1.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
Great Theoretical Ideas in Computer Science.
Regular Languages A language is regular over  if it can be built from ;, {  }, and { a } for every a 2 , using operators union ( [ ), concatenation.
Lecture 23: Finite State Machines with no Outputs Acceptors & Recognizers.
1 Unit 1: Automata Theory and Formal Languages Readings 1, 2.2, 2.3.
Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski
Languages Given an alphabet , we can make a word or string by concatenating the letters of . Concatenation of “x” and “y” is “xy” Typical example: 
CMSC 330: Organization of Programming Languages Theory of Regular Expressions Finite Automata.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
CS 203: Introduction to Formal Languages and Automata
Chapter 3 Regular Expressions, Nondeterminism, and Kleene’s Theorem Copyright © 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction.
Deterministic Finite Automata COMPSCI 102 Lecture 2.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
Machines That Can’t Count CS Lecture 15 b b a b a a a b a b.
UNIT - I Formal Language and Regular Expressions: Languages Definition regular expressions Regular sets identity rules. Finite Automata: DFA NFA NFA with.
Great Theoretical Ideas In Computer Science John LaffertyCS Fall 2005 Lecture 10Sept Carnegie Mellon University b b a b a a a b a b One.
Lecture Notes 
Transparency No. 2-1 Formal Language and Automata Theory Homework 2.
Great Theoretical Ideas In Computer Science John LaffertyCS Fall 2006 Lecture 22 November 9, 2006Carnegie Mellon University b b a b a a a b a b.
Great Theoretical Ideas in Computer Science for Some.
Nondeterministic Finite Automata (NFAs). Reminder: Deterministic Finite Automata (DFA) q For every state q in Q and every character  in , one and only.
Finite Automata Great Theoretical Ideas In Computer Science Victor Adamchik Danny Sleator CS Spring 2010 Lecture 20Mar 30, 2010Carnegie Mellon.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
 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.
Finite Automata A simple model of computation. 2 Finite Automata2 Outline Deterministic finite automata (DFA) –How a DFA works.
Set, Alphabets, Strings, and Languages. The regular languages. Clouser properties of regular sets. Finite State Automata. Types of Finite State Automata.
Great Theoretical Ideas In Computer Science Steven RudichCS Spring 2005 Lecture 9Feb Carnegie Mellon University b b a b a a a b a b One Minute.
Deterministic Finite-State Machine (or Deterministic Finite Automaton) A DFA is a 5-tuple, (S, Σ, T, s, A), consisting of: S: a finite set of states Σ:
Lecture Three: Finite Automata Finite Automata, Lecture 3, slide 1 Amjad Ali.
Languages.
Jaya Krishna, M.Tech, Assistant Professor
CS 154, Lecture 3: DFANFA, Regular Expressions.
COSC 3340: Introduction to Theory of Computation
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
Great Theoretical Ideas in Computer Science
One Minute To Learn Programming: Finite Automata
Chapter 1 Regular Language
CSCI 2670 Introduction to Theory of Computing
Presentation transcript:

Great Theoretical Ideas in Computer Science

Deterministic Finite Automata Lecture 19 (October 30, 2006)

Let me show you a machine so simple that you can understand it in less than two minutes

0 0, The machine accepts a string if the process ends in a double circle

0 0, The machine accepts a string if the process ends in a double circle Anatomy of a Deterministic Finite Automaton states q0q0 q1q1 q2q2 q3q3 start state (q 0 ) accept states (F)

Anatomy of a Deterministic Finite Automaton 0 0, q0q0 q1q1 q2q2 q3q3 The alphabet of a finite automaton is the set where the symbols come from: The language of a finite automaton is the set of strings that it accepts {0,1}

0,1 q0q0 L(M) = All strings of 0s and 1s  The Language of Machine M

q0q0 q1q L(M) = { w | w has an even number of 1s}

An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ. The set of all strings over Σ is denoted by Σ *. For x a string, |x| isthe length of x The unique string of length 0 will be denoted by ε and will be called the empty or null string Notation A language over Σ is a set of strings over Σ

Q is the set of states Σ is the alphabet  : Q  Σ → Q is the transition function q 0  Q is the start state F  Q is the set of accept states A finite automaton is a 5-tuple M = (Q, Σ, , q 0, F) L(M) = the language of machine M = set of all strings machine M accepts

Q = {q 0, q 1, q 2, q 3 } Σ = {0,1}  : Q  Σ → Q transition function q 0  Q is start state F = {q 1, q 2 }  Q accept states M = (Q, Σ, , q 0, F) where  01 q0q0 q0q0 q1q1 q1q1 q2q2 q2q2 q2q2 q3q3 q2q2 q3q3 q0q0 q2q2 q2q2 0 0, q0q0 q1q1 q3q3 M

Input StringResult aba aabb aabba  b b a b a a a b a b Accept Reject Accept “ABA” The Automaton

What machine accepts this language? L = all strings in {a,b}* that contain at least one a b a,b a

What machine accepts this language? L = strings with an odd number of b’s and any number of a’s a a b b

What is the language accepted by this machine? L = any string ending with a b a b b a

What is the language accepted by this machine? b a,b a b a L(M) = any string with at least two a’s

What machine accepts this language? L = any string with an a and a b a b b a a a,b b

What machine accepts this language? L = strings with an even number of ab pairs a b b a a b a b

Steven Rudich: du/~rudich rudich qq q0q0 q ,1 Build an automaton that accepts all and only those strings that contain 001

L = all strings containing ababb as a consecutive substring q q ab b b qaqa q aba a b a a q abab b q ababb b a,b a a Invariant: I am state s exactly when s is the longest suffix of the input (so far) forming a prefix of ababb.

Input: Text T of length t, string S of length n The “Grep” Problem Problem: Does string S appear inside text T? a 1, a 2, a 3, a 4, a 5, …, a t Naïve method: Cost:Roughly nt comparisons

Automata Solution Build a machine M that accepts any string with S as a consecutive substring Feed the text to M Cost: As luck would have it, the Knuth, Morris, Pratt algorithm builds M quickly t comparisons + time to build M

Grep Coke Machines Thermostats (fridge) Elevators Train Track Switches Lexical Analyzers for Parsers Real-life Uses of DFAs

A language is regular if it is recognized by a deterministic finite automaton L = { w | w contains 001} is regular L = { w | w has an even number of 1s} is regular

Union Theorem Given two languages, L 1 and L 2, define the union of L 1 and L 2 as L 1  L 2 = { w | w  L 1 or w  L 2 } Theorem: The union of two regular languages is also a regular language

Proof Sketch: Let M 1 = (Q 1, Σ,  1, q 0, F 1 ) be finite automaton for L 1 and M 2 = (Q 2, Σ,  2, q 0, F 2 ) be finite automaton for L 2 We want to construct a finite automaton M = (Q, Σ, , q 0, F) that recognizes L = L 1  L 2 1 2

Idea: Run both M 1 and M 2 at the same time! Q = pairs of states, one from M 1 and one from M 2 = { (q 1, q 2 ) | q 1  Q 1 and q 2  Q 2 } = Q 1  Q 2

Theorem: The union of two regular languages is also a regular language q0q0 q1q p0p0 p1p

q 0,p 0 q 1,p q 0,p 1 q 1,p Automaton for Union

q 0,p 0 q 1,p q 0,p 1 q 1,p Automaton for Intersection

Theorem: The union of two regular languages is also a regular language Corollary: Any finite language is regular

The Regular Operations Union: A  B = { w | w  A or w  B } Intersection: A  B = { w | w  A and w  B } Negation:  A = { w | w  A } Reverse: A R = { w 1 …w k | w k …w 1  A } Concatenation: A  B = { vw | v  A and w  B } Star: A* = { w 1 …w k | k ≥ 0 and each w i  A }

Regular Languages Are Closed Under The Regular Operations We have seen part of the proof for Union. The proof for intersection is very similar. The proof for negation is easy.

Are all languages regular?

i.e., a bunch of a’s followed by an equal number of b’s Consider the language L = { a n b n | n > 0 } No finite automaton accepts this language Can you prove this?

a n b n is not regular. No machine has enough states to keep track of the number of a’s it might encounter

That is a fairly weak argument Consider the following example…

L = strings where the # of occurrences of the pattern ab is equal to the number of occurrences of the pattern ba Can’t be regular. No machine has enough states to keep track of the number of occurrences of ab

M accepts only the strings with an equal number of ab’s and ba’s! b b a b a a a b a b

Let me show you a professional strength proof that a n b n is not regular…

Pigeonhole principle: Given n boxes and m > n objects, at least one box must contain more than one object Letterbox principle: If the average number of letters per box is x, then some box will have at least x letters (similarly, some box has at most x)

Theorem: L= {a n b n | n > 0 } is not regular Proof (by contradiction): Assume that L is regular Then there exists a machine M with k states that accepts L For each 0  i  k, let S i be the state M is in after reading a i  i,j  k such that S i = S j, but i  j M will do the same thing on a i b i and a j b i But a valid M must reject a j b i and accept a i b i

Advertisement You can learn much more about these creatures in the FLAC course. Formal Languages, Automata, and Computation There is a unique smallest automaton for any regular language It can be found by a fast algorithm.

Deterministic Finite Automata Definition Testing if they accept a string Building automata Regular Languages Definition Closed Under Union, Intersection, Negation Using Pigeonhole Principle to show language ain’t regular Here’s What You Need to Know…