Deterministic Finite Automata (DFA)

Slides:



Advertisements
Similar presentations
Properties of Regular Languages
Advertisements

8/27/2009 Sofya Raskhodnikova Intro to Theory of Computation L ECTURE 2 Theory of Computation Finite Automata Operations on languages Nondeterminism L2.1.
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.
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.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
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)
Finite Automata and Non Determinism
CS5371 Theory of Computation
CS 310 – Fall 2006 Pacific University CS310 Finite Automata Sections:1.1 page 44 September 8, 2006.
Fall 2006Costas Busch - RPI1 Deterministic Finite Automata And Regular Languages.
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.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
1 Languages and Finite Automata or how to talk to machines...
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.
Courtesy Costas Busch - RPI1 Non-regular languages.
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.
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
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.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 5 School of Innovation, Design and Engineering Mälardalen University 2012.
REGULAR LANGUAGES.
1 Unit 1: Automata Theory and Formal Languages Readings 1, 2.2, 2.3.
Theory of Languages and Automata
1 Strings and Languages. 2 Review Sets and sequences Functions and relations Graphs Boolean logic:      Proof techniques: – Construction, Contradiction,
Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski
Great Theoretical Ideas in Computer Science.
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: 
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
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.
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.
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.
Costas Busch - LSU1 Deterministic Finite Automata And Regular Languages.
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 Σ:
Languages.
PROPERTIES OF REGULAR LANGUAGES
Jaya Krishna, M.Tech, Assistant Professor
Deterministic Finite Automata And Regular Languages Prof. Busch - LSU.
Knuth-Morris-Pratt KMP algorithm. [over binary alphabet]
COSC 3340: Introduction to Theory of Computation
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
Great Theoretical Ideas in Computer Science
Deterministic Finite Automaton (DFA)
One Minute To Learn Programming: Finite Automata
Chapter 1 Regular Language
CSCI 2670 Introduction to Theory of Computing
Presentation transcript:

Deterministic Finite Automata (DFA) Borrowed from CMU / COMPSCI 102

The machine accepts a string if the process ends in a double circle 11 1 0,1 1 0111 111 1 1 The machine accepts a string if the process ends in a double circle

Anatomy of a Deterministic Finite Automaton 0,1 1 accept states (F) states q1 q0 q2 The machine accepts a string if the process ends in a double circle start state (q0) q3

Anatomy of a Deterministic Finite Automaton 0,1 1 q0 q1 q2 q3 The alphabet of a finite automaton is the set where the symbols come from: {0,1} The language of a finite automaton is the set of strings that it accepts

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

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

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

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

* M M = (Q, Σ, , q0, F) where Q = {q0, q1, q2, q3} Σ = {0,1}  : Q  Σ → Q transition function* q0  Q is start state F = {q1, q2}  Q accept states q2 0,1 1 q0 q1 q3 M *  1 q0 q1 q2 q3

Build an automaton that accepts all and only those strings that contain 001 q q00 1 q0 q001 0,1

L = { w | w has an even number of 1s} is regular 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, L1 and L2, define the union of L1 and L2 as L1  L2 = { w | w  L1 or w  L2 } Theorem: The union of two regular languages is also a regular language

Theorem: The union of two regular languages is also a regular language Proof Sketch: Let M1 = (Q1, Σ, 1, q0, F1) be finite automaton for L1 and M2 = (Q2, Σ, 2, q0, F2) be finite automaton for L2 1 2 We want to construct a finite automaton M = (Q, Σ, , q0, F) that recognizes L = L1  L2

Idea: Run both M1 and M2 at the same time! Q = pairs of states, one from M1 and one from M2 = { (q1, q2) | q1  Q1 and q2  Q2 } = Q1  Q2

Theorem: The union of two regular languages is also a regular language q0 q1 1 p0 p1 1

Automaton for Union 1 q0,p0 q1,p0 1 1 q0,p1 q1,p1 1

Automaton for Intersection 1 q0,p0 q1,p0 1 1 q0,p1 q1,p1 1

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 } Reverse: AR = { w1 …wk | wk …w1  A } Negation: A = { w | w  A } Concatenation: A  B = { vw | v  A and w  B } Star: A* = { w1 …wk | k ≥ 0 and each wi  A } note: can be different wi-s

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.

The “Grep” Problem a1, a2, a3, a4, a5, …, at Input: Text T of length t, string S of length n Problem: Does string S appear inside text T? Naïve method: a1, a2, a3, a4, a5, …, at 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: t comparisons + time to build M As luck would have it, the Knuth-Morris-Pratt (KMP) algorithm builds M quickly

Real-life Uses of DFAs Grep Coke Machines Train Track Switches Lexical Analyzers for Parsers ...

Are all languages regular?

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

anbn 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!

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

Pigeonhole principle: Given n boxes and m > n objects, at least one box must contain more than one object

Theorem: L= {anbn | 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, let Si be the state M is in after reading ai i,j such that Si = Sj, but i  j Why? after reading an for some n > k this must hold because there are not enough states

L= {anbn | n > 0 } is not regular (proof continued...) i,j such that Si = Sj, but i  j M will do the same thing on aibi and ajbi But a valid M must reject ajbi and accept aibi

Deterministic Finite Automata Summary Deterministic Finite Automata Definition Testing if they accept a string Building automata Regular Languages Closed Under Union, Intersection, Negation Using Pigeonhole Principle to show language ain’t regular