Nondeterminism and Nodeterministic Automata

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

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

1 Nondeterministic Finite Automata

Theory of Computation Regular Languages

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

Designing finite automata II

Deterministic Finite Automata

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

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.

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

Convert the NFA into DFA

Formal languages, automata, and theory of computation

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

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

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

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.

Non-deterministic Finite Automata

Finite Automata-cont d

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

Minimal DFA. minimal DFA for L starting from any other

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

Formal Languages and Automata

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

First Midterm Examination

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

Nondeterministic Automata vs Deterministic Automata

5.1 Definitions and Examples 5.2 Deterministic Pushdown Automata

First Midterm Examination

Intermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4

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

NFAs continued, Closure Properties of Regular Languages

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

CMSC 330: Organization of Programming Languages

Chapter 2 Finite Automata

1.4 Nonregular Languages

Lexical Analysis Finite Automate

Homework 3 Solutions

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

Non-deterministic Finite Automata

Talen en Automaten Test 1, Mon 7 th Dec, h45 17h30

Let's start with an example:

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

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

CISC 4090 Theory of Computation

CS375: Logic and Theory of Computing

CHAPTER 1 Regular Languages. Contents

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

Lecture 08: Feb. 08, 2019

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

Java II Finite Automata I

Worked out examples Finite Automata

Harvard University Computer Science 121 Midterm October 23, 2012

Formal Language and Automata Theory (CS21004)

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

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

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER LANGUAGES AND COMPUTATION ANSWERS

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

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

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

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

Non-Deterministic Finite Automata

CS 310 (sec 20) - Winter Final Exam (solutions) SOLUTIONS

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

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

Closure Properties of Regular Languages

Finite-State Automata: Recap

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

Some Theory of Computation Exercises Week 1

Languages & Automata

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Normal Forms for Context-free Grammars

NFAs continued, Closure Properties of Regular Languages

Revision Sheet. (a) Give a regular expression for each of the following languages:

CSCI 340: Computational Models. Transition Graphs. Department of Computer Science

FABER Formal Languages, Automata and Models of Computation

Context-Free Grammars and Languages

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

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

CS 275 Automata and Formal Language Theory

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

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

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

Lexical Analysis Part III

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

Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem 2/16/15

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

Name Ima Sample ASU ID

Scanner. Specifying patterns. Specifying patterns. Operations on languages. A scanner must recognize the units of syntax Some parts are easy:

Part 5 out of 5. Automata & languages. A primer on the Theory of Computation. Last week was all about. a superset of Regular Languages

Automata Theory 101. Introduction. Outline. Introduction Finite Automata Regular Expressions ω-automata. Ralf Huuck.

3 Regular expressions

Introduction to ω-autamata

CS 267: Automated Verification. Lecture 8: Automata Theoretic Model Checking. Instructor: Tevfik Bultan

1 From NFA to regular expression

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.

Tutorial Automata and formal Languages

State Minimization for DFAs

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

CS 330 Formal Methods and Models

Lecture 09: Myhill-Nerode Theorem

Transcription:

Nondeterminism nd Nodeterministic Automt 61

Nondeterminism nd Nondeterministic Automt The computtionl mchine models tht we lerned in the clss re deterministic in the sense tht the next move is uniquely determined y the current stte nd the input (ie, externl stimulus) Thus, the stte trnsition grphs of DFA's hve one (nd only one) edge for ech input symol (Recll tht, just for convenience, we greed not to drw the edge for trnsition with n input symol leding to the ded stte) Deterministic mchines follow our intuition, ecuse the models re sed on the determinism, which propose tht, for given cuse (current stte of the system nd externl input), the effect (stte chnge nd the output of the system) is uniquely determined Nondeterminism does not go long our intuition ecuse it llows multiple conflicting effects for given cuse Consider the stte trnsition grph shown on the following pge, which hs trnsitions which violte the determinism For exmple, the trnsition δ(1, ) = {1, 2} sys tht in stte 1 the utomton, reding input symol, enters sttes 1 nd 2 (Note tht the mchine enters sttes 1 nd 2 t the sme timewe cll such mchines nondeterministic finite utomt (NFA) 62

Nondeterministic Automt (cont ed) Nodeterministic FA: 2 e 1 3, 4 Nondeterministic trnsitions: δ(1, ) = {1, 2} δ(4, ) = {2, 3, 4} * δ(2, e) = {2, 3} Deterministic trnsitions: δ(1, ) = {3} δ(3, ) = {4} δ(4, ) = {2} * Notice tht in ny stte p, the mchine stys in the sme stte while there is no input, which implicitly there is δ(p, e) = {p} Therefore, if there is n explicit trnsition, like from stte 2 to stte 3 in the ove grph, the trnsition is nondeterministic, ecuse δ(2, e) = {2, 3} We will del with such ε-trnsitions lter s seprte topic Until then we study nondeterministic utomt with no ε-trnsitions 63

Nondeterministic Automt (cont ed) If n FA hs trnsition δ(p, ) = {q, r}, we sy tht the mchine, in stte p reding, nondeterministiclly enters sttes q nd r After tking this trnsition, the mchine is in oth q nd r We think tht two mchines, one in qnd the other in r, continue the computtion independently for the sme input Formlly n NFA M is defined y the sme tuple M = (Q, Σ, δ, q 0, Z 0, F ) s for DFA The only difference is the trnsition function; δ : Q Σ 2 Q,which implies tht in stte in Q, reding symol in Σ, the mchine cn enter simultneously in some sttes (ie, suset of Q) Notice tht DFA is specil cse of NFA which for n input symol, tkes trnsition to single stte For string x, let δ(q 0, x) = S, where S is the set of sttes tht the mchine enters fter reding string x The lnguge ccepted y n NFA M is defined s follows; L(M) = {x x {,} *, δ(q 0, x) = S, nd S F } Notice the ccepting condition, S F This implies tht if there exists t lest one sequence of trnsition tht ends up in n ccepting stte, then we sy the input x is ccepted All non-ccepting cses re ignored If there is no ccepting cse (ie, S F = ), then we sy the input is rejected 64

Nondeterministic Automt (cont ed) For exmple, consider the NFA shown in Figure () elow Figure () shows ll possile sequences of trnsitions for input, where nodes with lel X denote the ded stte which is not shown on the stte trnsition grph String is ccepted y the mchine since there exists sequence of trnsitions, which ends in n ccepting stte (q 2 in the figure) Note tht NFA's re similr to prllel mchines in the sense tht they explore n nswer simultneously in more thn one wy However, nondeterministic mchines do not produce (or nnounce) the finl result out of ll possile sequences of opertions We, the user, must serch ll possile terminting sttes of the mchine nd decide whether it stisfies the ccepting condition or not q 0 q 0, q 1 q 2 q 0 q 1 q 0 q 0 q 1 q 2 q 1 q 1 X X Figure (): An NFA Figure (): The profile of nondeterministic trnsition for input string 65

Nondeterministic Automt (cont ed) Designing NFA:, {x x {, } * },,, {x x {, } * nd there is followed y somewhere in x} 66

Nondeterministic Automt (cont ed) (, /) 1 Nodeterministic PDA: 2 (, /) (, /) 3 (, /) (, /) (, /ε ), (, /), (, /) 4 (, /) (, /), (ε, /ε ) Nondeterministic trnsitions: δ(1,, ) = {(2, ), (3, )} δ(3,, ) = {(3, ε ), (3, )} d(4,, ) = {(4, )} }* d(4, e, ) = {(2, ε)} Deterministic trnsitions: δ(2,, ) = {(3, )} δ(3,, ) = {(4, )} δ(3,, ) = {(2, )} δ(4,, ) = {(2, )} Notice tht PDA is nondeterministic if there is stte q, n input symol t, nd stck symol s such tht either () δ(q, t, s) > 1, or () δ(q, t, s) 0 nd δ(q, ε, s) 0 (see cse * ove) 67

Designing NPDA: Nondeterministic Automt (cont ed) (Y, X/YX ) X, Y {, } (X, Z 0 /X Z 0 ) q 1 (e, X/X ) ( ε, Z 0 /Z 0 ) q 3 strt q 0 q 2 (X, X/ε ) Figure (): NPDA ccepting {xx R x {, } + } 68

Nondeterministic Automt (cont ed) Designing NPDA: (, / ) (, /ε) (, /ε) (, Z 0 /Z 0 ) (c, Z 0 / Z 0 ) (c, Z 0 / Z 0 ) strt (, Z 0 /Z 0 ) (, /) (c, / ε ) (ε, Z 0 / Z 0 ) (, Z 0 /Z 0 ) (, Z 0 /Z 0 ) (c, / ε) Figure (): NPDA ccepting { i j c k i, j, k > 0, nd i = j or j = k } 69

Nondeterministic Automt (cont ed) Nodeterministic TM nd LBA: (,, R) 1 (,, R) (,, R), (,, R) 3 2 (,, L) (,, R) 4 (,, R), (,, L), (,, L) (,, R) Nondeterministic trnsitions: δ(1, ) = {(2,, R), (3,, R)} δ(2, ) = {(2,, R), (2,, R), (2,, L)} δ(3, ) = {(4,, R), (4,, L)} Deterministic trnsitions: δ(3, ) = {(4,, L)} δ(4, ) = {(4,, R)} δ(4, ) = {(2,, R)} Notice tht if there is pir of stte q nd symol t such tht δ(q, t) > 1, then the utomton is nondeterministic 70

Nondeterminism nd nondeterministic Algorithms Nondeterministic utomt re different from proilistic mchines which chnge their stte sed on some proility If n NFA hs nondetermininistic trnsition δ (p, ) = {q, r}, then reding in stte p the mchine definitely enters oth sttes q nd r The sme concept of nondeterminism cn e pplied to lgorithm design Insted of nondeterministic trnsition, we use nondeterministic guess (or choose) in nondeterministic lgorithms For finite set S, let nondet_choose(s) men nondeterministiclly choosing n element in S For exmple, suppose tht in n lgorithm we hve the following sttement x = nondet_choose (q, r) ; 71

Nondeterministic Algorithms Upon execution of this ssignment sttement the lgorithm forks into two independently running progrm instnces, one with x = q, nd the other with x = r x = nondet_choose (q, r) ; x = nondet_choose (q, r) ; {proceed with x = q) x = nondet_choose (q, r) ; (proceed with x = r) This wy nondeterministic lgorithms cn serch the solution spce of the given prolem simultneously As in the nondeterministic utomt, if there is no instnces of computtion generting the nswer, we sy the lgorithm fils to give the nswer 72

Nondeterministic Algorithms (cont ed) If we ssume tht the sttement nondet_choose( ) tkes constnt time, we cn solve mny, so clled, intrctle prolems, for which only exponentil-time lgorithms re ville, cn e solved in polynomil time For exmple, consider the sum-of-suset prolem, which is given s follows; Given set S of n integers nd n integer M, is there ny sum of suset of S tht is equl to M? Given S = {8, 21, 13, 20, 7, 11, 5} nd M = 34, for exmple, the nswer should e yes, since 8 + 21 + 5 = 34 This prolem, which is one of the well known intrctle prolems, cn e solved in liner-time, if we use the function nondet_choose( ) Suppose tht the set S is given in n rry The nondeterministic lgorithm in the following slide solves the prolem in linertime 73

Nondeterministic Algorithms (cont ed) Nondet-Sum-of-Suset (int S[ ], int n, int M) // S is n integer rry of size n { } int i, sum = 0; oolen selected; for ( i = 0; i < n; i++) { selected = nondet_choose(true, flse); } if (selected) sum += S[i]; if (sum = = M) return yes ; else return no ; Notice tht in the lgorithm ove, y selected = nondet_choose(true, flse) for ech element S[i], we re considering oth cses of dding nd not dding it to the sum Thus the lgorithm exmines ll possile sums of susets If there is n output yes, then we cn sy the nswer is yes, ignoring ll other no nswers 74