Course 4 Finite Automata/Finite State Machines

Similar documents
Decision, Computation and Language

Nondeterministic Finite Automata

COM364 Automata Theory Lecture Note 2 - Nondeterminism

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

T (s, xa) = T (T (s, x), a). The language recognized by M, denoted L(M), is the set of strings accepted by M. That is,

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Chapter Five: Nondeterministic Finite Automata

CS 154. Finite Automata, Nondeterminism, Regular Expressions

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

Finite Automata. Seungjin Choi

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

Lecture 3: Nondeterministic Finite Automata

Automata and Languages

CS 154, Lecture 3: DFA NFA, Regular Expressions

Deterministic (DFA) There is a fixed number of states and we can only be in one state at a time

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

Sri vidya college of engineering and technology

Deterministic Finite Automata (DFAs)

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

Deterministic Finite Automata (DFAs)

Nondeterministic Finite Automata. Nondeterminism Subset Construction

Introduction to the Theory of Computation. Automata 1VO + 1PS. Lecturer: Dr. Ana Sokolova.

UNIT-II. NONDETERMINISTIC FINITE AUTOMATA WITH ε TRANSITIONS: SIGNIFICANCE. Use of ε-transitions. s t a r t. ε r. e g u l a r

Topics COSC Administrivia. Topics Today. Administrivia (II) Acknowledgements. Slides presented May 9th and 16th,

Introduction to the Theory of Computation. Automata 1VO + 1PS. Lecturer: Dr. Ana Sokolova.

Nondeterminism and Epsilon Transitions

CSC173 Workshop: 13 Sept. Notes

Lecture 4 Nondeterministic Finite Accepters

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

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

Computability and Complexity

Deterministic Finite Automata (DFAs)

Takeaway Notes: Finite State Automata

Introduction to the Theory of Computing

Theory of Computation (I) Yijia Chen Fudan University

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

Lecture 17: Language Recognition

Computational Models - Lecture 1 1

CS 455/555: Finite automata

Nondeterministic finite automata

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

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

Chapter 5. Finite Automata

Nondeterminism. September 7, Nondeterminism

Theory of Computation

Introduction to Turing Machines. Reading: Chapters 8 & 9

Nondeterministic Finite Automata

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

Closure under the Regular Operations

Deterministic Finite Automaton (DFA)

CISC 4090: Theory of Computation Chapter 1 Regular Languages. Section 1.1: Finite Automata. What is a computer? Finite automata

Non-deterministic Finite Automata (NFAs)

Chapter 6: NFA Applications

Further discussion of Turing machines

Nondeterministic Finite Automata

What languages are Turing-decidable? What languages are not Turing-decidable? Is there a language that isn t even Turingrecognizable?

Computational Models #1

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

Theory of Computation

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

Part I: Definitions and Properties

Computability Theory

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Finite Automata. Finite Automata

CS243, Logic and Computation Nondeterministic finite automata

Turing Machines (TM) Deterministic Turing Machine (DTM) Nondeterministic Turing Machine (NDTM)

Computational Models Lecture 2 1

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

Let us first give some intuitive idea about a state of a system and state transitions before describing finite automata.

Undecidability COMS Ashley Montanaro 4 April Department of Computer Science, University of Bristol Bristol, UK

CS21 Decidability and Tractability

Languages, regular languages, finite automata

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

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

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

Finite Automata and Regular languages

Undecidable Problems and Reducibility

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

Lecture 1: Finite State Automaton

Computational Models Lecture 2 1

CSE 105 Theory of Computation Professor Jeanne Ferrante

Theory of Computation (II) Yijia Chen Fudan University

Extended transition function of a DFA

CS 301. Lecture 18 Decidable languages. Stephen Checkoway. April 2, 2018

CSE 555 Homework Three Sample Solutions

Foundations of

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata

Theory of Computation

UNIT-I. Strings, Alphabets, Language and Operations

Closure under the Regular Operations

Part 4 out of 5 DFA NFA REX. Automata & languages. A primer on the Theory of Computation. Last week, we showed the equivalence of DFA, NFA and REX

Chap. 2 Finite Automata

Theory of computation: initial remarks (Chapter 11)

CONCATENATION AND KLEENE STAR ON DETERMINISTIC FINITE AUTOMATA

Theory of Languages and Automata

Equivalence of DFAs and NFAs

How do regular expressions work? CMSC 330: Organization of Programming Languages

Finite-state machines (FSMs)

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

CMSC 330: Organization of Programming Languages

Transcription:

Course 4 Finite Automata/Finite State Machines The structure and the content of the lecture is based on (1) http://www.eecs.wsu.edu/~ananth/cpts317/lectures/index.htm, (2) W. Schreiner Computability and Complexity, Lecture Notes, RISC-JKU, Austria 1

Excursion: Previous lecture 2

Finite Automaton (FA) Informally, a state diagram that comprehensively captures all possible states and transitions that a machine can take while responding to a stream or sequence of input symbols. Recognizer for Regular Languages Deterministic Finite Automata (DFA) The machine can exist in only one state at any given time Non-deterministic Finite Automata (NFA) The machine can exist in multiple states at the same time 3

Deterministic Finite Automata - Definition A Deterministic Finite Automaton (DFA) consists of: Q - a finite set of states - a finite set of input symbols (alphabet) q 0 - a start state (one of the elements from Q) F - set of accepting states δ : Q Σ Q - a transition function which takes a state and an input symbol as an argument and returns a state. A DFA is defined by the 5-tuple: {Q,, q 0,F, δ} 4

Example #1 Build a DFA for the following language: L = {w w is a binary string that contains 01 as a substring} same as L = {w w is of the form x01y where x,y are binary strings} same as L = {x01y x,y are binary strings} Examples: 01, 010, 011, 0011, etc. Counterexamples: ε, 0, 1, 111000 Steps for building a DFA to recognize L: = {0,1} Decide on the non-final (non-accepting) states: Q Designate start state and final (accepting) state(s): F Decide on the transitions: δ 5

states Regular expression: (01)*01(01)* DFA for strings containing 01 What makes this DFA deterministic? Q = {q 0,q 1,q 2 } start Transition diagram 1 0,1 0 q 0 0 q 1 What if the language allows empty strings? 1 q2 Accepting state = {0,1} start state = q 0 F = {q 2 } Transition table symbols 0 1 Start state q 0 q 1 q 0 q 1 q 1 q 2 Accepting/final state*q 2 q 2 q 2 6

Finite Automata (cont d) 7

Example #2 Build a DFA for the following language: L = { w w is a binary string that has exactly length 2} See whiteboard 8

What does a DFA do on reading an input string? Input: a word w in * Question: Is w acceptable by the DFA? Steps: Start at the start state q 0 For every input symbol in the sequence w do: Compute the next state from the current state, given the current input symbol in w and the transition function If after all symbols in w are consumed, the current state is one of the accepting states (F) then accept w; Otherwise, reject w. 9

Regular Languages Let L(A) be a language recognized by a DFA A. Then L(A) is called a Regular Language. 10

The Chomsky Hierachy Location regular languages in the Chomsky Hierarchy Regular (DFA) Contextfree (PDA) Contextsensitive (LBA) Recursivelyenumerable (TM) 11

Example #3: Clamping Logic Problem: A clamping circuit (https://en.wikipedia.org/wiki/clamper_(electronics)) waits for a 1 input, and turns on forever. However, to avoid clamping on spurious noise, we ll design a DFA that waits for two consecutive 1s in a row before clamping on. Solution: build a DFA for the following language: L = { w w is a bit string which contains the substring 11} State Design: q 0 : start state (initially off), also means the most recent input was not a 1 q 1 : has never seen 11 but the most recent input was a 1 q 2 : has seen 11 at least once 12

Example #4: Even Number of Digits Consider the program which reads symbols from an input stream and returns true if the stream contains an even number of 0 and an even number of 1 (and no other symbol). 13

Example #3: Even Number of Digits (cont d) 14

Extension of transitions (δ) to Paths (δ) δ (q,w) = destination state from state q on input string w; used for determining the language of a DFA (see next slide) Base case: δ (q,ε) = q Induction: δ (q,wa) = δ(δ (q,w), a) Example: Work out example #3 (Clamping Logic) using the input sequence w=10: δ (q 0,w) =? w=1110: δ (q 0,w) =? 15

Language of a DFA A DFA A accepts string w if there is a path from q 0 to an accepting (or final) state that is labeled by w i.e., L(A) = { w δ(q 0,w) F } i.e., L(A) = all strings that lead to an accepting state from q 0 16

Non-deterministic Finite Automata (NFA) A Non-deterministic Finite Automaton (NFA) is of course non-deterministic Implying that the machine can exist in more than one state at the same time Transitions could be non-deterministic q i 1 1 q j q k Each transition function therefore maps to a set of states 17

Non-deterministic Finite Automata (NFA) A Non-deterministic Finite Automaton (NFA) consists of: Q: a finite set of states : a finite set of input symbols (alphabet) Q 0 : a start state F: set of accepting states δ: a transition function, which is a mapping between Q x and a subset of Q An NFA is also defined by the 5-tuple: {Q,, q 0,F, δ } 18

How to use an NFA? Input: a word w in * Question: Is w acceptable by the NFA? Steps: Start at the start state q 0 For every input symbol in the sequence w do Determine all possible next states from all current states, given the current input symbol in w and the transition function If after all symbols in w are consumed and if at least one of the current states is a final state then accept w; Otherwise, reject w. 19

states Regular expression: (0+1)*01(0+1)* NFA for strings containing 01 Why is this non-deterministic? start 0,1 0,1 q 0 0 q 1 What will happen if at state q 1 an input of 0 is received? 1 q2 Final state Q = {q 0,q 1,q 2 } = {0,1} start state = q 0 F = {q 2 } Transition table symbols 0 1 q 0 {q 0,q 1 } {q 0 } q 1 Φ {q 2 } *q 2 {q 2 } {q 2 } 20

Note: Omitting to explicitly show error states is just a matter of design convenience (one that is generally followed for NFAs), and i.e., this feature should not be confused with the notion of non-determinism. What is an error state? A DFA for recognizing the key word while q 0 w q1 h q2 i q 3 l q 4 e q 5 Any other input symbol q err Any symbol An NFA for the same purpose: q 0 w q1 h q2 i q 3 l q 4 e q 5 Transitions into a dead state are implicit 21

Further examples NFA for the clamping logic example (see whiteboard). Build an NFA for the following language: L = { w w ends in 01} Compare them with the corresponding DFA (see whiteboard). Other examples Keyword recognizer (e.g., if, then, else, while, for, include, etc.) @seminar Strings where the first symbol is present somewhere later on at least once @seminar 22

Extension of δ to NFA Paths Basis: δ (q, ) = {q} Induction: Let δ (q 0,w) = {p 1,p 2,p k } δ (p i,a) = S i for i=1,2...,k Then, δ (q 0,wa) = S 1 U S 2 U U S k 23

Language of an NFA An NFA accepts w if there exists at least one path from the start state to an accepting (or final) state that is labeled by w L(N) = { w δ(q 0,w) F Φ } 24

Advantages & Caveats for NFA Great for modeling regular expressions String processing - e.g., grep, lexical analyzer 25

But, DFAs and NFAs are equivalent in their power to capture langauges!! Summary DFA 1. All transitions are deterministic Each transition leads to exactly one state 2. For each state, transition on all possible symbols (alphabet) should be defined 3. Accepts input if the last state visited is in F 4. Sometimes harder to construct because of the number of states 5. Practical implementation is feasible NFA 1. Some transitions could be non-deterministic A transition could lead to a subset of states 2. Not all symbol transitions need to be defined explicitly (if undefined will go to an error state this is just a design convenience, not to be confused with nondeterminism ) 3. Accepts input if one of the last states is in F 4. Generally easier than a DFA to construct 5. Practical implementations limited but emerging (e.g., Micron automata processor) 26