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

Similar documents
CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata

Nondeterministic Finite Automata

CSE 135: Introduction to Theory of Computation Equivalence of DFA and NFA

Closure under the Regular Operations

Chapter Five: Nondeterministic Finite Automata

Chap. 1.2 NonDeterministic Finite Automata (NFA)

Nondeterministic Finite Automata

Theory of Computation (I) Yijia Chen Fudan University

Nondeterminism. September 7, Nondeterminism

September 7, Formal Definition of a Nondeterministic Finite Automaton

Inf2A: Converting from NFAs to DFAs and Closure Properties

Lecture 3: Nondeterministic Finite Automata

Finite Automata. Seungjin Choi

Theory of Languages and Automata

CS 154. Finite Automata, Nondeterminism, Regular Expressions

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

CSE 105 Theory of Computation Professor Jeanne Ferrante

Formal Definition of Computation. August 28, 2013

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

Deterministic Finite Automata (DFAs)

Context-Free Languages

CS 455/555: Finite automata

Deterministic Finite Automata (DFAs)

Computer Sciences Department

CS 154, Lecture 3: DFA NFA, Regular Expressions

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

Finite Automata. Mahesh Viswanathan

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

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

Finite Automata and Regular languages

Extended transition function of a DFA

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

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

Automata and Languages

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

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

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

Non-deterministic Finite Automata (NFAs)

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Deterministic Finite Automata (DFAs)

CS243, Logic and Computation Nondeterministic finite automata

Nondeterministic Finite Automata

Finite Automata. Finite Automata

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,

Lecture 1: Finite State Automaton

Deterministic Finite Automata (DFAs)

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

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

CS 154 Formal Languages and Computability Assignment #2 Solutions

CPS 220 Theory of Computation REGULAR LANGUAGES

COM364 Automata Theory Lecture Note 2 - Nondeterminism

Nondeterministic Finite Automata. Nondeterminism Subset Construction

Chapter 6: NFA Applications

CISC 4090 Theory of Computation

Theory of Computation (II) Yijia Chen Fudan University

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

CS21 Decidability and Tractability

CSE 105 THEORY OF COMPUTATION

Takeaway Notes: Finite State Automata

Subset construction. We have defined for a DFA L(A) = {x Σ ˆδ(q 0, x) F } and for A NFA. For any NFA A we can build a DFA A D such that L(A) = L(A D )

Fooling Sets and. Lecture 5

CpSc 421 Homework 1 Solutions

Intro to Theory of Computation

CSE 105 Homework 3 Due: Monday October 23, Instructions. should be on each page of the submission.

Automata: a short introduction

Great Theoretical Ideas in Computer Science. Lecture 4: Deterministic Finite Automaton (DFA), Part 2

CSC236 Week 11. Larry Zhang

Theory of Computation

Finite Automata Part Two

Closure under the Regular Operations

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

Computational Models Lecture 2 1

Computational Models - Lecture 1 1

Theory of Computation p.1/?? Theory of Computation p.2/?? Unknown: Implicitly a Boolean variable: true if a word is

CISC4090: Theory of Computation

Computational Models Lecture 2 1

UNIT-III REGULAR LANGUAGES

Nondeterministic finite automata

Finite Automata. Theorems - Unit I SUSAN ELIAS. Professor Department of Computer Science & Engineering Sri Venkateswara College of Engineering

Classes and conversions

Course 4 Finite Automata/Finite State Machines

Introduction to Languages and Computation

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

CSE 105 THEORY OF COMPUTATION

Lecture 4 Nondeterministic Finite Accepters

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

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

October 6, Equivalence of Pushdown Automata with Context-Free Gramm

Chapter 5. Finite Automata

Finite Automata and Regular Languages

CSE 105 THEORY OF COMPUTATION

Automata & languages. A primer on the Theory of Computation. Laurent Vanbever. ETH Zürich (D-ITET) September,

CSE 105 THEORY OF COMPUTATION

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

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

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

Non Determinism of Finite Automata

Closure Properties of Regular Languages. Union, Intersection, Difference, Concatenation, Kleene Closure, Reversal, Homomorphism, Inverse Homomorphism

Lecture Notes On THEORY OF COMPUTATION MODULE -1 UNIT - 2

Transcription:

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata (cont ) Sungjin Im University of California, Merced 2-3-214

Example II A ɛ B ɛ D F C E

Example II A ɛ B ɛ D F C E NFA accepting strings of s where the length is either a multiple 2 or 3 The NFA guesses at the begining whether it will see a multiple of 2 or 3, and then confirms that the guess was correct.

Example III, 1, 1 q ɛ q q 1 q p

Example III, 1, 1 q ɛ q q 1 q p NFA accepting strings with 1 as substring At some point the NFA guesses that the pattern 1 is starting and then checks to confirm the guess.

Nondeterministic Finite Automata (NFA) Formal Definition Definition A nondeterministic finite automaton (NFA) is M = (Q, Σ, δ, q, F ), where Q is the finite set of states Σ is the finite alphabet δ : q Q initial state F Q final/accepting states

Nondeterministic Finite Automata (NFA) Formal Definition Definition A nondeterministic finite automaton (NFA) is M = (Q, Σ, δ, q, F ), where Q is the finite set of states Σ is the finite alphabet δ : Q (Σ {ɛ}) P(Q), where P(Q) is the powerset of Q q Q initial state F Q final/accepting states

Example of NFA, 1, 1 q ɛ q q 1 q p Transition Diagram of NFA

Example of NFA, 1, 1 q ɛ q q 1 q p Transition Diagram of NFA Formally, the NFA is M 1 = ({q ɛ, q, q, q p }, {, 1}, δ, q ɛ, {q p }) where δ is given by δ(q ɛ, ) = {q ɛ, q } δ(q ɛ, 1) = {q ɛ } δ(q, ) = {q } δ(q, 1) = {q p } δ(q p, ) = {q p } δ(q p, 1) = {q p } δ is in all other cases.

Computation Definition For an NFA M = (Q, Σ, δ, q, F ), string w, and states q 1, q 2 Q, w we say q 1 M q 2 if there is one thread of computation on input w from state q 1 that ends in q 2.

Computation Definition For an NFA M = (Q, Σ, δ, q, F ), string w, and states q 1, q 2 Q, w we say q 1 M q 2 if there is one thread of computation on input w w from state q 1 that ends in q 2. Formally, q 1 M q 2 if there is a sequence of states r, r 1,... r k and a sequence x 1, x 2,... x k, where for each i, x i Σ {ɛ}, such that

Computation Definition For an NFA M = (Q, Σ, δ, q, F ), string w, and states q 1, q 2 Q, w we say q 1 M q 2 if there is one thread of computation on input w w from state q 1 that ends in q 2. Formally, q 1 M q 2 if there is a sequence of states r, r 1,... r k and a sequence x 1, x 2,... x k, where for each i, x i Σ {ɛ}, such that r = q 1,

Computation Definition For an NFA M = (Q, Σ, δ, q, F ), string w, and states q 1, q 2 Q, w we say q 1 M q 2 if there is one thread of computation on input w w from state q 1 that ends in q 2. Formally, q 1 M q 2 if there is a sequence of states r, r 1,... r k and a sequence x 1, x 2,... x k, where for each i, x i Σ {ɛ}, such that r = q 1, for each i, r i+1 δ(r i, x i+1 ),

Computation Definition For an NFA M = (Q, Σ, δ, q, F ), string w, and states q 1, q 2 Q, w we say q 1 M q 2 if there is one thread of computation on input w w from state q 1 that ends in q 2. Formally, q 1 M q 2 if there is a sequence of states r, r 1,... r k and a sequence x 1, x 2,... x k, where for each i, x i Σ {ɛ}, such that r = q 1, for each i, r i+1 δ(r i, x i+1 ), r k = q 2, and

Computation Definition For an NFA M = (Q, Σ, δ, q, F ), string w, and states q 1, q 2 Q, w we say q 1 M q 2 if there is one thread of computation on input w w from state q 1 that ends in q 2. Formally, q 1 M q 2 if there is a sequence of states r, r 1,... r k and a sequence x 1, x 2,... x k, where for each i, x i Σ {ɛ}, such that r = q 1, for each i, r i+1 δ(r i, x i+1 ), r k = q 2, and w = x 1 x 2 x 3 x k

Example Computation, 1, 1 q ɛ q q 1 q p ɛ q ɛ 1 M q p because taking r = q ɛ, r 1 = q, r 2 = q, r 3 = q p, r 4 = q p, r 5 = q p, and x 1 =, x 2 = ɛ, x 3 = 1, x 4 =, x 5 =, we have x 1 x 2 x 5 = ɛ1 = 1 r i+1 δ(r i, x i+1 )

Defining ˆ Definition For an NFA M = (Q, Σ, δ, q, F ), string w, and state q 1 Q, we say ˆ (q 1, w) to denote states of all the active threads of computation on input w from q 1.

Defining ˆ Definition For an NFA M = (Q, Σ, δ, q, F ), string w, and state q 1 Q, we say ˆ (q 1, w) to denote states of all the active threads of computation on input w from q 1. Formally, ˆ (q 1, w) = {q Q q 1 w M q}

Example, 1, 1 q ɛ q q 1 q p ɛ Example NFA

Example, 1, 1 q ɛ q ɛ q 1 q p Example NFA q ɛ q q ɛ q ɛ 1 1 1 q p X q ɛ q p q ɛ q ɛ q q p q q ɛ q X ɛ q Computation on 1

Example, 1, 1 q ɛ q ɛ q 1 q p Example NFA ˆ (q ɛ, 1) = {q, q p, q, q ɛ } q ɛ q q ɛ q ɛ 1 1 1 q p X q ɛ q p q ɛ q ɛ q q p q q ɛ q X ɛ q Computation on 1

Acceptance/Recognition Definition For an NFA M = (Q, Σ, δ, q, F ) and string w Σ, we say M accepts w iff ˆ (q, w) F

Acceptance/Recognition Definition For an NFA M = (Q, Σ, δ, q, F ) and string w Σ, we say M accepts w iff ˆ (q, w) F Definition The language accepted or recognized by NFA M over alphabet Σ is L(M) = {w Σ M accepts w}.

Acceptance/Recognition Definition For an NFA M = (Q, Σ, δ, q, F ) and string w Σ, we say M accepts w iff ˆ (q, w) F Definition The language accepted or recognized by NFA M over alphabet Σ is L(M) = {w Σ M accepts w}. A language L is said to be accepted/recognized by M if L = L(M).

Observations about NFAs Observation 1 For NFA M, string w and state q 1 it could be that

Observations about NFAs Observation 1 For NFA M, string w and state q 1 it could be that ˆ (q 1, w) =

Observations about NFAs Observation 1 For NFA M, string w and state q 1 it could be that ˆ (q 1, w) = ˆ (q 1, w) has more than one element

Observations about NFAs Observation 1 For NFA M, string w and state q 1 it could be that ˆ (q 1, w) = ˆ (q 1, w) has more than one element Observation 2 However, the following proposition about DFAs continues to hold for NFAs

Observations about NFAs Observation 1 For NFA M, string w and state q 1 it could be that ˆ (q 1, w) = ˆ (q 1, w) has more than one element Observation 2 However, the following proposition about DFAs continues to hold for NFAs For NFA M, strings u and v, and state q, ˆ (q, uv) = ˆ (q, v) q ˆ (q,u)

Using Nondeterminism When designing an NFA for a language

Using Nondeterminism When designing an NFA for a language You follow the same methodology as for DFAs, like identifying what needs to be remembered

Using Nondeterminism When designing an NFA for a language You follow the same methodology as for DFAs, like identifying what needs to be remembered But now, the machine can guess at certain steps

Back to the Future Problem For Σ = {, 1, 2, #}, let L = {w#c w {, 1, 2}, c {, 1, 2}, and c occurs in w} So 111# L but 111#2 L. Design an NFA recognizing L.

Back to the Future Problem For Σ = {, 1, 2, #}, let L = {w#c w {, 1, 2}, c {, 1, 2}, and c occurs in w} So 111# L but 111#2 L. Design an NFA recognizing L. Solution Read symbols of w, i.e., portion of input before # is seen Guess at some point that current symbol in w is going to be the same as c ; store this symbol in the state Read the rest of w On reading #, check that the symbol immediately after is the one stored, and that the input ends immediately after that.

Back to the Future The Automaton, 1, 2, 1, 2 q s 2 1 q, 1, 2 q 1, 1, 2 # # q q 1 1 2 q f q 2 # q 2 L(M) = {w#c c occurs in w}

Halving a Language Definition For a language L, define 1 2L as follows. 1 L = {x y. x = y and xy L} 2 In other words, 1 2L consists of the first halves of strings in L

Halving a Language Definition For a language L, define 1 2L as follows. 1 L = {x y. x = y and xy L} 2 In other words, 1 2L consists of the first halves of strings in L Example If L = {1,, 1, 111} then 1 2 L =.

Halving a Language Definition For a language L, define 1 2L as follows. 1 L = {x y. x = y and xy L} 2 In other words, 1 2L consists of the first halves of strings in L Example If L = {1,, 1, 111} then 1 2L = {,, 11}.

Recognizing Halves of Regular Languages Proposition If L is recognized by a DFA M then there is a NFA N such that L(N) = 1 2 L.

Recognizing Halves of Regular Languages Proposition If L is recognized by a DFA M then there is a NFA N such that L(N) = 1 2 L. Proof Idea On input x, need to check if x is the first half of some string w = xy that is accepted by M. Run M on input x; let M be in state q i after reading all of x Guess a string y such that y = x Check if M reaches a final state on reading y from q i

Recognizing Halves of Regular Languages Proposition If L is recognized by a DFA M then there is a NFA N such that L(N) = 1 2 L. Proof Idea On input x, need to check if x is the first half of some string w = xy that is accepted by M. Run M on input x; let M be in state q i after reading all of x Guess a string y such that y = x Check if M reaches a final state on reading y from q i How do you guess a string y of equal length to x using finite memory? Seems to require remembering the length of x!

Fixing the Idea Problem How do you guess a string y of equal length to x using finite memory?

Fixing the Idea Problem and Fix(?) How do you guess a string y of equal length to x using finite memory? Guess one symbol of y as you read one symbol of x!

Fixing the Idea Problem and Fix(?) How do you guess a string y of equal length to x using finite memory? Guess one symbol of y as you read one symbol of x! How do you run M on y from q i, if you cannot store all the symbols of y?

Fixing the Idea Problem and Fix(?) How do you guess a string y of equal length to x using finite memory? Guess one symbol of y as you read one symbol of x! How do you run M on y from q i, if you cannot store all the symbols of y? Run M on y as you guess each symbol, without waiting to finish the execution on x!

Fixing the Idea Problem and Fix(?) How do you guess a string y of equal length to x using finite memory? Guess one symbol of y as you read one symbol of x! How do you run M on y from q i, if you cannot store all the symbols of y? Run M on y as you guess each symbol, without waiting to finish the execution on x! If we don t first execute M on x, how do we know the state q i from which we have to execute y from?

Fixing the Idea Problem and Fix(?) How do you guess a string y of equal length to x using finite memory? Guess one symbol of y as you read one symbol of x! How do you run M on y from q i, if you cannot store all the symbols of y? Run M on y as you guess each symbol, without waiting to finish the execution on x! If we don t first execute M on x, how do we know the state q i from which we have to execute y from? Guess it! And then check that running M on x does indeed end in q i, your guessed state.

New Algorithm On input x, NFA N 1. Guess state q i and place left finger on (initial state of M) q and right finger on q i 2. As characters of x are read, N moves the left finger along transitions dictated by x and simultaneously moves the right finger along nondeterministically chosen transitions labelled by some symbol

New Algorithm On input x, NFA N 1. Guess state q i and place left finger on (initial state of M) q and right finger on q i 2. As characters of x are read, N moves the left finger along transitions dictated by x and simultaneously moves the right finger along nondeterministically chosen transitions labelled by some symbol 3. Accept if after reading x, left finger is at q i (state initially guessed for right finger) and right finger is at an accepting state

New Algorithm On input x, NFA N 1. Guess state q i and place left finger on (initial state of M) q and right finger on q i 2. As characters of x are read, N moves the left finger along transitions dictated by x and simultaneously moves the right finger along nondeterministically chosen transitions labelled by some symbol 3. Accept if after reading x, left finger is at q i (state initially guessed for right finger) and right finger is at an accepting state Things to remember: initial guess for right finger, and positions of left and right finger.

Algorithm on Example 11 L and so x = 1 1 2 L q 1 q 1 1 q 2 1 1 q 3 DFA M

Algorithm on Example q 1 q 1 1 q 2 1 1 q 3 11 L and so x = 1 1 2 L NFA N execution on x = 1 is String Read Left Finger Right Finger ɛ q q 2 1 q 1 q 2 1 q 3 q 1 1 q 2 q 3 DFA M

Algorithm on Example q 1 q 1 1 q 2 1 1 q 3 DFA M 11 L and so x = 1 1 2 L NFA N execution on x = 1 is String Read Left Finger Right Finger ɛ q q 2 1 q 1 q 2 =? 1 q 3 1 q 2 q 1 q 3 accept?

Formal Construction of NFA N States and Initial State Given M = (Q, Σ, δ, q, F ) recognizing L define N = (Q, Σ, δ, q, F ) that recognizes 1 2 L Q = Q Q Q {s}, where s Q s is a new start state Other states are of the form left finger, initial guess, right finger ; initial guess records the initial guess for the right finger q = s

Formal Construction of NFA N Transitions and Final States Transitions δ (s, ɛ) = { q, q i, q i q i Q} Guess the state q i that the input will lead to δ ( q i, q j, q k, a) = { q l, q j, q m δ(q i, a) = q l, b Σ. δ(q k, b) = q m } b is the guess for the next symbol of y and initial guess does not change F = { q i, q i, q j q i Q, q j F }