Non-Deterministic Finite Automata. Fall 2018 Costas Busch - RPI 1

Similar documents
Non Deterministic Automata. Linz: Nondeterministic Finite Accepters, page 51

Non-Deterministic Finite Automata

Non Deterministic Automata. Formal Languages and Automata - Yonsei CS 1

Theory of Computation Regular Languages. (NTU EE) Regular Languages Fall / 38

Theory of Computation Regular Languages

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

Chapter 2 Finite Automata

CS:4330 Theory of Computation Spring Regular Languages. Equivalences between Finite automata and REs. Haniel Barbosa

5.1 Definitions and Examples 5.2 Deterministic Pushdown Automata

CS375: Logic and Theory of Computing

Lecture 6 Regular Grammars

Recursively Enumerable and Recursive. Languages

Chapter Five: Nondeterministic Finite Automata. Formal Language, chapter 5, slide 1

Deterministic Finite Automata

CHAPTER 1 Regular Languages. Contents

Non-deterministic Finite Automata

Anatomy of a Deterministic Finite Automaton. Deterministic Finite Automata. A machine so simple that you can understand it in less than one minute

NFAs and Regular Expressions. NFA-ε, continued. Recall. Last class: Today: Fun:

Regular expressions, Finite Automata, transition graphs are all the same!!

Non-deterministic Finite Automata

Nondeterminism. Nondeterministic Finite Automata. Example: Moves on a Chessboard. Nondeterminism (2) Example: Chessboard (2) Formal NFA

Fundamentals of Computer Science

Finite Automata. Informatics 2A: Lecture 3. John Longley. 22 September School of Informatics University of Edinburgh

Worked out examples Finite Automata

a,b a 1 a 2 a 3 a,b 1 a,b a,b 2 3 a,b a,b a 2 a,b CS Determinisitic Finite Automata 1

CMSC 330: Organization of Programming Languages. DFAs, and NFAs, and Regexps (Oh my!)

Finite Automata. Informatics 2A: Lecture 3. Mary Cryan. 21 September School of Informatics University of Edinburgh

Lecture 08: Feb. 08, 2019

Designing finite automata II

Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Kleene-*

CISC 4090 Theory of Computation

Let's start with an example:

CSCI FOUNDATIONS OF COMPUTER SCIENCE

Automata and Languages

input tape head moves current state

1 From NFA to regular expression

CSCI 340: Computational Models. Kleene s Theorem. Department of Computer Science

Convert the NFA into DFA

Deterministic Finite-State Automata

Some Theory of Computation Exercises Week 1

Finite-State Automata: Recap

Formal Language and Automata Theory (CS21004)

CS 301. Lecture 04 Regular Expressions. Stephen Checkoway. January 29, 2018

11.1 Finite Automata. CS125 Lecture 11 Fall Motivation: TMs without a tape: maybe we can at least fully understand such a simple model?

CMSC 330: Organization of Programming Languages

Formal Languages and Automata

Today s Topics Automata and Languages

Automata and Languages

1.4 Nonregular Languages

More on automata. Michael George. March 24 April 7, 2014

Minimal DFA. minimal DFA for L starting from any other

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

1 Nondeterministic Finite Automata

CMPSCI 250: Introduction to Computation. Lecture #31: What DFA s Can and Can t Do David Mix Barrington 9 April 2014

Lexical Analysis Finite Automate

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. NFA for (a b)*abb.

NFAs continued, Closure Properties of Regular Languages

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. Comparing DFAs and NFAs (cont.) Finite Automata 2

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true.

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

Turing Machines Part One

Grammar. Languages. Content 5/10/16. Automata and Languages. Regular Languages. Regular Languages

CS415 Compilers. Lexical Analysis and. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

Assignment 1 Automata, Languages, and Computability. 1 Finite State Automata and Regular Languages

Finite Automata-cont d

CS 275 Automata and Formal Language Theory

Regular languages refresher

State Minimization for DFAs

Formal languages, automata, and theory of computation

Probabilistic Model Checking Michaelmas Term Dr. Dave Parker. Department of Computer Science University of Oxford

This lecture covers Chapter 8 of HMU: Properties of CFLs

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY. FLAC (15-453) - Spring L. Blum

Speech Recognition Lecture 2: Finite Automata and Finite-State Transducers

CHAPTER 1 Regular Languages. Contents. definitions, examples, designing, regular operations. Non-deterministic Finite Automata (NFA)

Nondeterminism and Nodeterministic Automata

Section: Other Models of Turing Machines. Definition: Two automata are equivalent if they accept the same language.

Java II Finite Automata I

Lecture 09: Myhill-Nerode Theorem

FABER Formal Languages, Automata and Models of Computation

Turing Machines Part One

Homework 4. 0 ε 0. (00) ε 0 ε 0 (00) (11) CS 341: Foundations of Computer Science II Prof. Marvin Nakayama

Normal Forms for Context-free Grammars

Harvard University Computer Science 121 Midterm October 23, 2012

1.3 Regular Expressions

First Midterm Examination

For convenience, we rewrite m2 s m2 = m m m ; where m is repeted m times. Since xyz = m m m nd jxyj»m, we hve tht the string y is substring of the fir

12.1 Nondeterminism Nondeterministic Finite Automata. a a b ε. CS125 Lecture 12 Fall 2014

12.1 Nondeterminism Nondeterministic Finite Automata. a a b ε. CS125 Lecture 12 Fall 2016

Nondeterministic Biautomata and Their Descriptional Complexity

Chapter 1, Part 1. Regular Languages. CSC527, Chapter 1, Part 1 c 2012 Mitsunori Ogihara 1

In-depth introduction to main models, concepts of theory of computation:

Introduction to ω-autamata

80 CHAPTER 2. DFA S, NFA S, REGULAR LANGUAGES. 2.6 Finite State Automata With Output: Transducers

CS 373, Spring Solutions to Mock midterm 1 (Based on first midterm in CS 273, Fall 2008.)

5. (±±) Λ = fw j w is string of even lengthg [ 00 = f11,00g 7. (11 [ 00)± Λ = fw j w egins with either 11 or 00g 8. (0 [ ffl)1 Λ = 01 Λ [ 1 Λ 9.

Chapter 4 Regular Grammar and Regular Sets. (Solutions / Hints)

CS375: Logic and Theory of Computing

NFA DFA Example 3 CMSC 330: Organization of Programming Languages. Equivalence of DFAs and NFAs. Equivalence of DFAs and NFAs (cont.

Closure Properties of Regular Languages

3 Regular expressions

Transcription:

Non-Deterministic Finite Automt Fll 2018 Costs Busch - RPI 1

Nondeterministic Finite Automton (NFA) Alphbet ={} q q2 1 q 0 q 3 Fll 2018 Costs Busch - RPI 2

Nondeterministic Finite Automton (NFA) Alphbet ={} q q2 1 λ Σ- q3 Σ- q 1 q 2 q 1 q 2 q 1 q 2 A B C Fll 2018 Costs Busch - RPI 3

Alphbet ={} Two choices q q2 1 q 0 q 3 Fll 2018 Costs Busch - RPI 4

Alphbet ={} Two choices q q2 1 No trnsition q 0 q 3 No trnsition Fll 2018 Costs Busch - RPI 5

First Choice q q2 1 q 0 q 3 Fll 2018 Costs Busch - RPI 6

First Choice q q2 1 q 0 q 3 Fll 2018 Costs Busch - RPI 7

First Choice All input is consumed q q2 1 ccept q 0 q 3 Fll 2018 Costs Busch - RPI 8

Second Choice q q2 1 q 0 q 3 Fll 2018 Costs Busch - RPI 9

q 0 Second Choice Input cnnot be consumed q q2 1 q 3 Automton Hlts reject Fll 2018 Costs Busch - RPI 10

An NFA ccepts string: if there is computtion of the NFA tht ccepts the string i.e., ll the input string is processed nd the utomton is in n ccepting stte Fll 2018 Costs Busch - RPI 11

is ccepted by the NFA: ccept q q1 2 q1 q2 q 0 q 3 becuse this computtion ccepts Fll 2018 Costs Busch - RPI 12 q 0 q 3 reject this computtion is ignored

Rejection exmple q q2 1 q 0 q 3 Fll 2018 Costs Busch - RPI 13

First Choice reject q q2 1 q 0 q 3 Fll 2018 Costs Busch - RPI 14

Second Choice 1 q q2 q 0 q 3 Fll 2018 Costs Busch - RPI 15

Second Choice 1 q q2 q 0 q 3 reject Fll 2018 Costs Busch - RPI 16

Another Rejection exmple q q2 1 q 0 q 3 Fll 2018 Costs Busch - RPI 17

First Choice q q2 1 q 0 q 3 Fll 2018 Costs Busch - RPI 18

First Choice Input cnnot be consumed q q2 1 reject q 0 q 3 Automton hlts Fll 2018 Costs Busch - RPI 19

Second Choice q q2 1 q 0 q 3 Fll 2018 Costs Busch - RPI 20

q 0 Second Choice Input cnnot be consumed q q2 1 q 3 Automton hlts reject Fll 2018 Costs Busch - RPI 21

An NFA rejects string: if there is no computtion of the NFA tht ccepts the string. For ech computtion: All the input is consumed nd the utomton is in non finl stte OR The input cnnot be consumed Fll 2018 Costs Busch - RPI 22

is rejected by the NFA: q q1 2 reject q1 2 q q 0 q 3 reject q 0 q 3 All possible computtions led to rejection Fll 2018 Costs Busch - RPI 23

is rejected by the NFA: reject q q1 2 q1 q2 q 0 q 3 q 0 q 3 reject All possible computtions led to rejection Fll 2018 Costs Busch - RPI 24

Lnguge ccepted: L {} q q2 1 q 0 q 3 Fll 2018 Costs Busch - RPI 25

NFA: Mouse Mze Fll 2018 Costs Busch - RPI 26

Lmbd Trnsitions q0 q1 q 2 q3 Fll 2018 Costs Busch - RPI 27

q0 q1 q 2 q3 Fll 2018 Costs Busch - RPI 28

q0 q1 q 2 q3 Fll 2018 Costs Busch - RPI 29

input tpe hed does not move q0 q1 q 2 q3 Fll 2018 Costs Busch - RPI 30

ll input is consumed q0 ccept q1 q 2 q3 String is ccepted Fll 2018 Costs Busch - RPI 31

Rejection Exmple q0 q1 q 2 q3 Fll 2018 Costs Busch - RPI 32

q0 q1 q 2 q3 Fll 2018 Costs Busch - RPI 33

(red hed doesn t move) q0 q1 q 2 q3 Fll 2018 Costs Busch - RPI 34

Input cnnot be consumed Automton hlts reject q0 q1 q 2 q3 String is rejected Fll 2018 Costs Busch - RPI 35

Lnguge ccepted: L {} q0 q1 q 2 q3 Fll 2018 Costs Busch - RPI 36

Another NFA Exmple q b q 2 q0 1 q 3 Fll 2018 Costs Busch - RPI 37

b q b q 2 q0 1 q 3 Fll 2018 Costs Busch - RPI 38

b q b q 2 0 q 1 q 3 Fll 2018 Costs Busch - RPI 39

b ccept q q1 b 0 q 2 q 3 Fll 2018 Costs Busch - RPI 40

Another String b b q q b 1 q2 q3 0 Fll 2018 Costs Busch - RPI 41

b b q q b 1 q2 q3 0 Fll 2018 Costs Busch - RPI 42

b b q q b 1 q2 q3 0 Fll 2018 Costs Busch - RPI 43

b b q q b 1 q2 q3 0 Fll 2018 Costs Busch - RPI 44

b b q q b 1 q2 q3 0 Fll 2018 Costs Busch - RPI 45

b b q q b 1 q2 q3 0 Fll 2018 Costs Busch - RPI 46

b b q q b 1 q2 q3 0 ccept Fll 2018 Costs Busch - RPI 47

Lnguge ccepted L b, bb, bbb,... b q b q 2 q0 1 q 3 Fll 2018 Costs Busch - RPI 48

Another NFA Exmple Wht is the lnguge ccepted?? 0 q0 1 1 q 0,1 q2 Fll 2018 Costs Busch - RPI 49

Lnguge ccepted 0 q0 1 1 q 0,1 q2 (redundnt stte) Fll 2018 Costs Busch - RPI 50

Remrks: The symbol never ppers on the input tpe Simple utomt: M 1 q 0 M 2 q 0 L(M 1 ) ={} (M ) = {λ} L 2 Fll 2018 Costs Busch - RPI 51

NFAs re interesting becuse we cn express lnguges esier thn DFAs NFA M 1 DFA M 2 q 0 q1 q 2 q 0 q 1 L( M1) = { } L( M2) = { } Fll 2018 Costs Busch - RPI 52

Forml Definition of NFAs M Q,,, q0, F Q : Set of sttes, i.e. q, q q 0 1, 2 Input plhbet, i.e., b : : Trnsition function q 0 : Initil stte F : Accepting sttes Fll 2018 Costs Busch - RPI 53

Trnsition Function q x q, q,,, 1 2 q k x q 1 resulting sttes with q x x q 1 following one trnsition with symbol x q k Fll 2018 Costs Busch - RPI 54

q, q 0 1 1 0 q0 1 1 q 0,1 q2 Fll 2018 Costs Busch - RPI 55

( q1,0) { q0, q2} 0 q 0 1 0 q 0,1 q2 1 Fll 2018 Costs Busch - RPI 56

( q, ) { q } 0 2 0 q 0 1 q 0,1 q2 1 Fll 2018 Costs Busch - RPI 57

( q,1) 2 q 0 0 1 q 0,1 q2 1 Fll 2018 Costs Busch - RPI 58

Extended Trnsition Function * Sme with but pplied on strings * q, q 0 1 q 4 q 5 q 0 q 1 b q 2 q 3 Fll 2018 Costs Busch - RPI 59

* q, q, q 0 4 5 q 4 q 5 q 0 q 1 b q 2 q 3 Fll 2018 Costs Busch - RPI 60

* q, b q, q, q 0 2 3 0 q 4 q 5 q 0 q 1 b q 2 q 3 Fll 2018 Costs Busch - RPI 61

Specil cse: for ny stte q q * q, Fll 2018 Costs Busch - RPI 62

Fll 2018 Costs Busch - RPI 63 w q q i j, * : there is wlk from to with lbel i q j q w i q j q w w k 2 1 1 2 k i q j q In generl

The Lnguge of n NFA The lnguge ccepted by M is: M M w w L,... 1, 2 w n where * ( q 0, w m ) { q i,..., q k,, q j } nd there is some q k F (ccepting stte) Fll 2018 Costs Busch - RPI 64

w m L M * ( q, w 0 m ) w m q i q0 w m qk q k F w m q j Fll 2018 Costs Busch - RPI 65

F q 0,q 5 q 4 q 5 q 0 q 1 b q 2 q 3 * q, q, q 0 4 5 F L(M) Fll 2018 Costs Busch - RPI 66

F q 0,q 5 q 4 q 5 q 0 q 1 b q 2 q 3 q, b q, q, q * b LM 0 2 3 0 F Fll 2018 Costs Busch - RPI 67

F q 0,q 5 q 4 q 5 q 0 q 1 b q 2 q 3 * q, b q, q 0 4 5 bl(m ) F Fll 2018 Costs Busch - RPI 68

F q 0,q 5 q 4 q 5 q 0 q 1 b q 2 q 3 * q 0, b q b LM 1 F Fll 2018 Costs Busch - RPI 69

q 4 q 5 q 0 q 1 b q 2 q 3 L M b* b * { } Fll 2018 Costs Busch - RPI 70

NFAs ccept the Regulr Lnguges Fll 2018 Costs Busch - RPI 71

Equivlence of Mchines Definition: Mchine M1 is equivlent to mchine M2 if LM 1 L M 2 Fll 2018 Costs Busch - RPI 72

Exmple of equivlent mchines LM 1 {10} * NFA 0 q q 0 1 1 M 1 LM 2 {10} * q q 1 0 1 q2 1 Fll 2018 Costs Busch - RPI 73 0 DFA 0 M 2 0,1

0 q1 1 q2 Fll 2018 Costs Busch - RPI 74

Theorem: Lnguges ccepted by NFAs Regulr Lnguges Lnguges ccepted by DFAs NFAs nd DFAs hve the sme computtion power, ccept the sme set of lnguges Fll 2018 Costs Busch - RPI 75

Proof: we only need to show Lnguges ccepted by NFAs Lnguges ccepted by NFAs AND Regulr Lnguges Regulr Lnguges Fll 2018 Costs Busch - RPI 76

Proof-Step 1 Lnguges ccepted by NFAs Regulr Lnguges Every DFA is trivilly n NFA Any lnguge L ccepted by DFA is lso ccepted by n NFA Fll 2018 Costs Busch - RPI 77

Proof-Step 2 Lnguges ccepted by NFAs Regulr Lnguges Any NFA cn be converted to n equivlent DFA Any lnguge L is lso ccepted by DFA ccepted by n NFA Fll 2018 Costs Busch - RPI 78

NFA M Conversion NFA to DFA q 0 q1 q2 b DFA M q 0 Fll 2018 Costs Busch - RPI 79

NFA M * ( q0, ) { q1, q2 } q 0 q1 q2 b DFA M q 0 q 1,q 2 Fll 2018 Costs Busch - RPI 80

NFA M * ( q 0, b) q 0 q1 q2 b empty set DFA M q 0 q 1,q 2 b trp stte Fll 2018 Costs Busch - RPI 81

NFA DFA M M q 0 q1 q2 b q 0 q 1,q 2 b * ( q1, ) { q1, q2 } * ( q 2, ) union q 1,q 2 Fll 2018 Costs Busch - RPI 82

NFA M q 0 q1 q2 b * ( q1, b) { q0} * q, b) { q } ( 2 0 union q 0 DFA M b q 0 q 1,q 2 b Fll 2018 Costs Busch - RPI 83

NFA M q 0 q1 q2 b DFA M b q 0 q 1,q 2 b,b trp stte Fll 2018 Costs Busch - RPI 84

NFA M END OF CONSTRUCTION q 0 q1 q2 b q F 1 DFA M b q 0 q 1,q 2 b q q F 1, 2,b Fll 2018 Costs Busch - RPI 85

Generl Conversion Procedure Input: n NFA M Output: n equivlent DFA with LM L(M ) M Fll 2018 Costs Busch - RPI 86

The NFA hs sttes q, q, q,... 0 1 2 The DFA hs sttes from the power set,,,,,,,..., q q q q q q q 0 1 0 1 1 2 3 Fll 2018 Costs Busch - RPI 87

Conversion Procedure Steps step 1. Initil stte of NFA: q 0 Initil stte of DFA: q 0 Fll 2018 Costs Busch - RPI 88

Exmple NFA M q 0 q1 q2 b DFA M q 0 Fll 2018 Costs Busch - RPI 89

Fll 2018 Costs Busch - RPI 90 2. For every DFA s stte compute in the NFA dd trnsition to DFA },...,, { m j i q q q q q q m j i, *..., *, * },...,, { n l k q q q },...,, { },,...,, { n l k m j i q q q q q q Union step

Exmple NFA M *( q0, ) { q1, q2} q 0 q1 q2 b DFA M q, q q 0 1, q 0 q 1,q 2 2 Fll 2018 Costs Busch - RPI 91

step 3. Repet Step 2 for every stte in DFA nd symbols in lphbet until no more sttes cn be dded in the DFA Fll 2018 Costs Busch - RPI 92

Exmple NFA M q 0 q1 q2 b DFA M b q 0 q 1,q 2 b,b Fll 2018 Costs Busch - RPI 93

step 4. For ny DFA stte { qi, q j,..., qm} if some q j is ccepting stte in NFA Then, { qi, q j,..., qm} is ccepting stte in DFA Fll 2018 Costs Busch - RPI 94

Exmple NFA M q 0 q1 q2 b q F 1 DFA M b q 0 q 1,q 2 b q q F 1, 2,b Fll 2018 Costs Busch - RPI 95

Lemm: If we convert NFA M to DFA then the two utomt re equivlent: LM LM M Proof: We only need to show: LM LM AND LM LM Fll 2018 Costs Busch - RPI 96

First we show: LM LM We only need to prove: wl(m ) wl(m ) Fll 2018 Costs Busch - RPI 97

NFA Consider wl(m ) q0 w q f symbols w 1 2 k q0 1 2 k q f Fll 2018 Costs Busch - RPI 98

symbol q i i q j denotes possible sub-pth like qi symbol i q j Fll 2018 Costs Busch - RPI 99

We will show tht if wl(m ) NFA M : q0 1 2 w 1 2 k k q f then DFA M : { q 0 } stte lbel 1 2 w L(M ) Fll 2018 Costs Busch - RPI 100 k {, } q f stte lbel

More generlly, we will show tht if in : M NFA (rbitrry string) M : q0 v 1 1 2 qi 2 q j n ql n qm then DFA M : { q 0 } 1 2 {, } q i n { q, } { q, } {, } j l q m Fll 2018 Costs Busch - RPI 101

Proof by induction on v v Induction Bsis: v 1 1 NFA M : q 1 0 q i DFA M : { q 0 } 1 {, } q i is true by construction of M Fll 2018 Costs Busch - RPI 102

Induction hypothesis: 1 v k v 1 2 k NFA M Suppose tht the following hold : q0 1 2 qi q j qc k qd DFA M : { q 0 } 1 2 k { q, } { q, } { q, } {, } i j c q d Fll 2018 Costs Busch - RPI 103

Induction Step: v k 1 NFA M : q0 v 1 2 qi 1 2 k k1 k1 v Then this is true by construction of M q j qc k qd v k1 q e v DFA M : { q 0 } 1 2 k { q, } { q, } { q, } {, } i j c q d k1 {, } q e Fll 2018 Costs Busch - RPI 104 v

Therefore if wl(m ) w 1 2 k NFA M : q0 1 2 k q f then DFA M : { q 0 } 1 2 k {, } q f w L(M ) Fll 2018 Costs Busch - RPI 105

We hve shown: LM LM With similr proof we cn show: LM LM Therefore: LM LM END OF LEMMA PROOF Fll 2018 Costs Busch - RPI 106