Lecture 3: Finite Automata. Finite Automata. Deterministic Finite Automata. Summary. Dr Kieran T. Herley

Similar documents
Lecture 4: Nondeterministic Finite Automata

Chapter 5. Finite Automata

Decision, Computation and Language

Deterministic Finite Automata. Non deterministic finite automata. Non-Deterministic Finite Automata (NFA) Non-Deterministic Finite Automata (NFA)

Finite Automata. Finite Automata

September 7, Formal Definition of a Nondeterministic Finite Automaton

CS 154 Formal Languages and Computability Assignment #2 Solutions

Nondeterminism. September 7, Nondeterminism

Computer Sciences Department

Closure under the Regular Operations

COM364 Automata Theory Lecture Note 2 - Nondeterminism

Clarifications from last time. This Lecture. Last Lecture. CMSC 330: Organization of Programming Languages. Finite Automata.

Deterministic Finite Automaton (DFA)

CS 154, Lecture 2: Finite Automata, Closure Properties Nondeterminism,

Inf2A: Converting from NFAs to DFAs and Closure Properties

CS 154, Lecture 3: DFA NFA, Regular Expressions

September 11, Second Part of Regular Expressions Equivalence with Finite Aut

Finite-State Machines (Automata) lecture 12

Author: Vivek Kulkarni ( )

Theory of Computation (I) Yijia Chen Fudan University

CMPSCI 250: Introduction to Computation. Lecture #22: From λ-nfa s to NFA s to DFA s David Mix Barrington 22 April 2013

Closure under the Regular Operations

Uses of finite automata

Computability Theory

Finite Automata. BİL405 - Automata Theory and Formal Languages 1

CSE 311: Foundations of Computing. Lecture 23: Finite State Machine Minimization & NFAs

Computational Models #1

Finite Automata. Seungjin Choi

Extended transition function of a DFA

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

CSE 311 Lecture 23: Finite State Machines. Emina Torlak and Kevin Zatloukal

Nondeterministic Finite Automata

CS 530: Theory of Computation Based on Sipser (second edition): Notes on regular languages(version 1.1)

Finite Automata. Dr. Neil T. Dantam. Fall CSCI-561, Colorado School of Mines. Dantam (Mines CSCI-561) Finite Automata Fall / 35

Deterministic Finite Automata (DFAs)

CMSC 330: Organization of Programming Languages. Theory of Regular Expressions Finite Automata

Lecture 1: Finite State Automaton

Computational Models - Lecture 1 1

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata (cont )

Deterministic Finite Automata (DFAs)

Finite Automata. Wen-Guey Tzeng Computer Science Department National Chiao Tung University

Nondeterministic Finite Automata

Lecture 3: Nondeterministic Finite Automata

Finite Automata. Mahesh Viswanathan

CHAPTER 1 Regular Languages. Contents

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Sri vidya college of engineering and technology

CSE 105 Theory of Computation Professor Jeanne Ferrante

Fooling Sets and. Lecture 5

Deterministic Finite Automata (DFAs)

Theory of Computation

Midterm Exam 2 CS 341: Foundations of Computer Science II Fall 2018, face-to-face day section Prof. Marvin K. Nakayama

Intro to Theory of Computation

Finite Automata. Dr. Neil T. Dantam. Fall CSCI-561, Colorado School of Mines. Dantam (Mines CSCI-561) Finite Automata Fall / 43

CMSC 330: Organization of Programming Languages

CS:4330 Theory of Computation Spring Regular Languages. Finite Automata and Regular Expressions. Haniel Barbosa

Nondeterministic Finite Automata

CSE 105 THEORY OF COMPUTATION

Course 4 Finite Automata/Finite State Machines

CSC236 Week 11. Larry Zhang

Equivalence of DFAs and NFAs

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Automata Theory. Lecture on Discussion Course of CS120. Runzhe SJTU ACM CLASS

Constructions on Finite Automata

Lecture 2: Regular Expression

I have read and understand all of the instructions below, and I will obey the University Code on Academic Integrity.

Finite Automata. Warren McCulloch ( ) and Walter Pitts ( )

Recitation 2 - Non Deterministic Finite Automata (NFA) and Regular OctoberExpressions

Constructions on Finite Automata

CS 154. Finite Automata vs Regular Expressions, Non-Regular Languages

Outline. Nondetermistic Finite Automata. Transition diagrams. A finite automaton is a 5-tuple (Q, Σ,δ,q 0,F)

Compilers. Lexical analysis. Yannis Smaragdakis, U. Athens (original slides by Sam

2017/08/29 Chapter 1.2 in Sipser Ø Announcement:

Examples of Regular Expressions. Finite Automata vs. Regular Expressions. Example of Using flex. Application

Languages. Non deterministic finite automata with ε transitions. First there was the DFA. Finite Automata. Non-Deterministic Finite Automata (NFA)

Theory of Computation Lecture 1. Dr. Nahla Belal

UNIT-VIII COMPUTABILITY THEORY

Midterm Exam 2 CS 341: Foundations of Computer Science II Fall 2016, face-to-face day section Prof. Marvin K. Nakayama

Theory of Computation (II) Yijia Chen Fudan University

Deterministic finite Automata

Finite Automata and Regular languages

Chapter Five: Nondeterministic Finite Automata

Finite Automata Part Two

Computational Models Lecture 2 1

Griffith University 3130CIT Theory of Computation (Based on slides by Harald Søndergaard of The University of Melbourne) Turing Machines 9-0

CSCI 2200 Foundations of Computer Science Spring 2018 Quiz 3 (May 2, 2018) SOLUTIONS

Nondeterministic Finite Automata

NFA and regex. the Boolean algebra of languages. regular expressions. Informatics 1 School of Informatics, University of Edinburgh

CSE 105 THEORY OF COMPUTATION

Classes and conversions

Nondeterminism and Epsilon Transitions

Computational Models Lecture 2 1

Recap DFA,NFA, DTM. Slides by Prof. Debasis Mitra, FIT.

Lecture 3: Finite Automata

CS 154. Finite Automata, Nondeterminism, Regular Expressions

CS 581: Introduction to the Theory of Computation! Lecture 1!

Announcements. Problem Set Four due Thursday at 7:00PM (right before the midterm).

Mathematics for linguists

Finite Automata Part Two

Lecture 17: Language Recognition

Transcription:

Lecture 3: Finite Automata Dr Kieran T. Herley Department of Computer Science University College Cork Summary Deterministic finite automata (DFA). Definition and operation of same. DFAs as string classifiers or pattern recognizers. Algorithm for simulation of DFAs. 2017-2018 KH (12/10/17) Lecture 3: Finite Automata 2017-2018 1 / 1 KH (12/10/17) Lecture 3: Finite Automata 2017-2018 2 / 1 Finite Automata Deterministic Finite Automata A finite automaton (aka finite state machine) is a simple abstract device that categorizes input strings as either accepted or rejected. Operation of (deterministic) finite automaton: Place token on start state. For each input symbol in turn, move token along (unique) edge whose label matches that symbol. Accept/reject input if token in accept/non-accept state at the end. Definition Deterministic Finite Automaton (DFA) a consists of Σ an alphabet S s 0 A a finite set of states a start state a set of accept states and T = (S, E) a directed graph in which each edge in E is labelled with one or more elements of Σ and no two edges bearing the same label emanate from the same state. a Will consider nondeterministic finite automata (NFA) later KH (12/10/17) Lecture 3: Finite Automata 2017-2018 3 / 1 KH (12/10/17) Lecture 3: Finite Automata 2017-2018 4 / 1

Example cont d Aside Σ = {a, b, c} S = {s 0, s 1, s 2, s 3 } A = {s 2 } T = (S, E) Transition graph often represented by a transition table: a b c s 0 s 1 s 2 s 1 s 1 s 1 s 2 s 1 s 2 s 2 s 3 s 2 s 3 s 3 s 3 s 3 KH (12/10/17) Lecture 3: Finite Automata 2017-2018 5 / 1 KH (12/10/17) Lecture 3: Finite Automata 2017-2018 6 / 1 Illustration of FA in Action Formal Acceptance Criterion Input: a c a c c a Reject! Input: a c b c c a Accept! Input: a a b b c a Reject! Input: b a c b c a Reject! Input: b b c a c a Reject! Formal Criterion Definition The automaton accepts string x 1 x 2 x n if there is a path in T from the start state to one of the accept states such that for each i, the ith edge on the path bears label x i. All other strings are rejected. Pic Observation Accepts all strings with exactly one b. KH (12/10/17) Lecture 3: Finite Automata 2017-2018 7 / 1 KH (12/10/17) Lecture 3: Finite Automata 2017-2018 8 / 1

Example Another Example Accepts 01001: Rejects 010101. s 0 0 s0 1 s1 0 s1 0 s1 1 s0 Observation Accepts strings of even parity, rejects odd. Claim Accepts all strings containing exactly three 1s. Each 0 leaves state unchanged, each 1 moves one state to right Rightmost state is a trap state : once entered there is no way of escaping and reaching the accept state to its left. How to prove this? KH (12/10/17) Lecture 3: Finite Automata 2017-2018 9 / 1 KH (12/10/17) Lecture 3: Finite Automata 2017-2018 10 / 1 Yet Another Example Claim Accepts strings that do not contain two consecutive bs KH (12/10/17) Lecture 3: Finite Automata 2017-2018 11 / 1 KH (12/10/17) Lecture 3: Finite Automata 2017-2018 12 / 1

M = Automaton M.start start state M.accept accept states M.moveTo(..) transition function X = input X.nextChar() returns next char eof Special end-ofinput char Algorithm emulates token-tracing process: s encodes state holding token moveto emulates state transitions KH (12/10/17) Lecture 3: Finite Automata 2017-2018 13 / 1 KH (12/10/17) Lecture 3: Finite Automata 2017-2018 14 / 1 For DFAs, string-path correspondance is unique Sequence of s values implicitly defines path and vice versa Theorem DfaAccept returns true if and only if automaton M accepts string X. Claim DfaAccept(M, X ) runs in O( X ) time i.e. linear in the input length. KH (12/10/17) Lecture 3: Finite Automata 2017-2018 15 / 1 KH (12/10/17) Lecture 3: Finite Automata 2017-2018 16 / 1

Representing the Transition Function FAs As Pattern Recognizers Transition function typically represented as table Example: s 0 s 1 s 2 a b c z. s n For large alphabets and state sets, tables can be huge; also typically sparse. Permits fast lookup (O(1)), but space hungry. (Could also represent function using (say) map.) Since FAs categorize strings (accept/reject), can think of them as language recognizers: device to characterize which strings belong to some set and which don t. Accepts strings consisting of letters and digits that begin with a letter i.e. valid Pascal identifiers KH (12/10/17) Lecture 3: Finite Automata 2017-2018 17 / 1 KH (12/10/17) Lecture 3: Finite Automata 2017-2018 18 / 1 Aside String Matching DFAs and String Matching Setting Matches P occurs with shift s if P[1..m] = T [s + 1..s + m] Goal Locate all occurrences of P in T. Naive Algorithm Algorithm NaiveStringMatch(T, P): for s 0 to n m do if P [1.. m] = T[s+1..s+m] then print pattern occurs with shift s Running Time = O(nm) (SLOW) Recall DFA can act as simple pattern recognition device, accepting some strings, rejecting others Fact For every string p there is a simple DFA M(p) that recognizes it. (Not obvious, but true.) Cunning Plan Build a DFA that recognizes string p Run input through DFA Watch for token entering accept state (signifies pattern occurrence) KH (12/10/17) Lecture 3: Finite Automata 2017-2018 19 / 1 KH (12/10/17) Lecture 3: Finite Automata 2017-2018 20 / 1

M(ababaca) a DFA for ababaca M(ababaca) cont d Notes Complete DFA has exactly one transition per state for each alphabet symbol Implicit transitions of for s? s 0 are not shown to avoid cluttering diagram Fascinating Fact Beginning at any state s, by following transitions labelled a-b-a-b-a-c-a you end up in the accept state! Corollary DFA detects (by entering accept state) each occurrence of pattern ababaca in the input string KH (12/10/17) Lecture 3: Finite Automata 2017-2018 21 / 1 KH (12/10/17) Lecture 3: Finite Automata 2017-2018 22 / 1