Chapter Five: Nondeterministic Finite Automata

Similar documents
Nondeterministic Finite Automata

Chapter 6: NFA Applications

Chapter Two: Finite Automata

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

Theory of Computation (I) Yijia Chen Fudan University

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

COM364 Automata Theory Lecture Note 2 - Nondeterminism

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

Chap. 1.2 NonDeterministic Finite Automata (NFA)

Lecture 3: Nondeterministic Finite Automata

Automata and Languages

Nondeterministic Finite Automata. Nondeterminism Subset Construction

Intro to Theory of Computation

Closure under the Regular Operations

Inf2A: Converting from NFAs to DFAs and Closure Properties

CS 154. Finite Automata, Nondeterminism, Regular Expressions

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

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata

CS 154, Lecture 3: DFA NFA, Regular Expressions

CS21 Decidability and Tractability

Lecture 4 Nondeterministic Finite Accepters

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,

Fooling Sets and. Lecture 5

CS 455/555: Finite automata

Nondeterminism and Epsilon Transitions

Nondeterministic Finite Automata

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

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

CSE 105 THEORY OF COMPUTATION

Equivalence of DFAs and NFAs

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

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

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

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

Finite Automata. Seungjin Choi

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

Nondeterministic finite automata

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

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

Lecture 1: Finite State Automaton

CSE 105 Theory of Computation Professor Jeanne Ferrante

Finite Automata. Finite Automata

Theory of Computation (II) Yijia Chen Fudan University

Finite Automata and Regular languages

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

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

Theory of Languages and Automata

Nondeterminism. September 7, Nondeterminism

Decision, Computation and Language

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

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

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

CPS 220 Theory of Computation REGULAR LANGUAGES

CS243, Logic and Computation Nondeterministic finite automata

Computational Models Lecture 2 1

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

September 7, Formal Definition of a Nondeterministic Finite Automaton

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

Nondeterministic Finite Automata

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

Chapter 2: Finite Automata

Computational Models Lecture 2 1

Regular Expressions and Language Properties

CMSC 330: Organization of Programming Languages

Takeaway Notes: Finite State Automata

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

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Closure under the Regular Operations

Automata: a short introduction

Course 4 Finite Automata/Finite State Machines

Theory of Computation

Nondeterministic Finite Automata

Computer Sciences Department

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

Computational Models - Lecture 1 1

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

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

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

Non-deterministic Finite Automata (NFAs)

CSC236 Week 11. Larry Zhang

CSE 105 THEORY OF COMPUTATION

CSCI 2670 Introduction to Theory of Computing

Uses of finite automata

CSE 105 THEORY OF COMPUTATION

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

INF Introduction and Regular Languages. Daniel Lupp. 18th January University of Oslo. Department of Informatics. Universitetet i Oslo

HKN CS/ECE 374 Midterm 1 Review. Nathan Bleier and Mahir Morshed

Pushdown automata. Twan van Laarhoven. Institute for Computing and Information Sciences Intelligent Systems Radboud University Nijmegen

CS21 Decidability and Tractability

Lecture 2: Regular Expression

Finite Automata. Mahesh Viswanathan

Theory of Computation (IV) Yijia Chen Fudan University

Computational Theory

Formal Definition of Computation. August 28, 2013

UNIT-VI PUSHDOWN AUTOMATA

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

CSE 105 THEORY OF COMPUTATION

CSC236 Week 10. Larry Zhang

Transcription:

Chapter Five: Nondeterministic Finite Automata

From DFA to NFA A DFA has exactly one transition from every state on every symbol in the alphabet. By relaxing this requirement we get a related but more flexible kind of automaton: the nondeterministic finite automaton or NFA.

Outline 5.1 Relaxing a Requirement 5.2 Spontaneous Transitions 5.3 Nondeterminism 5.4 The 5-Tuple for an NFA 5.5 The Language Accepted by an NFA

Not A DFA q 0 a q 1 a,b Does not have exactly one transition from every state on every symbol: Two transitions from q 0 on a No transition from q 1 (on either a or b) Though not a DFA, this can be taken as defining a language, in a slightly different way

Possible Sequences of Moves q 0 a q 1 a,b We'll consider all possible sequences of moves the machine might make for a given string For example, on the string aa there are three: From q 0 to q 0 to q 0, rejecting From q 0 to q 0 to q 1, accepting From q 0 to q 1, getting stuck on the last a Our convention for this new kind of machine: a string is in L(M) if there is at least one accepting sequence

Nondeterministic Finite Automaton (NFA) q 0 a q 1 a,b L(M) = the set of strings that have at least one accepting sequence In the example above, L(M) = {xa x {a,b}*} A DFA is a special case of an NFA: An NFA that happens to be deterministic: there is exactly one transition from every state on every symbol So there is exactly one possible sequence for every string

Nondeterminism The essence of nondeterminism: For a given input there can be more than one legal sequence of steps The input is in the language if at least one of the legal sequences says so We can achieve the same result by computing all legal sequences in parallel and then deterministically search the legal sequences that accept the input, but...this nondeterminism does not directly correspond to anything in physical computer systems In spite of that, NFAs have many practical applications

NFA Example This NFA accepts only those strings that end in 01 0,1 0 1 Start q 0 q 1 q 2 Running in parallel threads for string 1100101 0 1 1 q0 q0 q0 q0 q1 - stuck 0 1 q0 q1 0 q0 q2 - stuck 1 q0 q0 q1 q2 - accept

Nondeterminism 0 DFA: q0 1 q1 0 0 1 1 q2 0 q3 1 NFA: 0,1 Now consider string: 0110 1 0,1 q0 q1 q2

DFAs and NFAs DFAs and NFAs both define languages DFAs do it by giving a simple computational procedure for deciding language membership: Start in the start state Make one transition on each symbol in the string See if the final state is accepting NFAs do it by considering all possible transitions in parallel.

NFA Advantage An NFA for a language can be smaller and easier to construct than a DFA Let L={x {0,1}* where x is a string whose next-to-last symbol is 1} Construct both a DFA and NFA for recognizing L. DFA: 0 NFA: 1 0,1 0 0 1 1 1 0,1 0 1

Outline 5.1 Relaxing a Requirement 5.2 Spontaneous Transitions 5.3 Nondeterminism 5.4 The 5-Tuple for an NFA 5.5 The Language Accepted by an NFA

Spontaneous Transitions An NFA can make a state transition spontaneously, without consuming an input symbol Shown as an arrow labeled with ε For example, {a}* {b}*: ε q 1 a q 0 ε q 2 b

ε-transitions To Accepting States ε q 1 a q 0 ε q 2 b An ε-transition can be made at any time For example, there are three sequences on the empty string No moves, ending in q 0, rejecting From q 0 to q 1, accepting From q 0 to q 2, accepting Any state with an ε-transition to an accepting state ends up working like an accepting state too

ε-transitions For NFA Combining ε q 1 a q 0 ε-transitions are useful for combining smaller automata into larger ones This machine is combines a machine for {a}* and a machine for {b}* It uses an ε-transition at the start to achieve the union of the two languages ε q 2 b

Revisiting Union a A = {a n n is odd} a b b B = {b n n is odd} ε ε a a b b A B

Concatenation a A = {a n n is odd} a b b B = {b n n is odd} a a ε b b {xy x A and y B}

Some Exercises What is the language accepted by the following NFAs? a) b) c)

More Exercises Let Σ = {a, b, c}. Give an NFA M that accepts: L = {x x is in Σ * and x contains ab}

One More Exercise Let Σ = {a, b}. Give an NFA M that accepts: L = {x x is in Σ * and the third to the last symbol in x is b}

NFA Exercise Construct an NFA that will accept strings over alphabet {1, 2, 3} such that the last symbol appears at least twice, but without any intervening higher symbol, in between: e.g., 11, 2112, 123113, 3212113, etc. Trick: use start state to mean I guess I haven't seen the symbol that matches the ending symbol yet. Use three other states to represent a guess that the matching symbol has been seen, and remembers what that symbol is. Spoiler Alert: answer on the next slide!

NFA Exercise (answer)

Outline 5.1 Relaxing a Requirement 5.2 Spontaneous Transitions 5.3 Nondeterminism 5.4 The 5-Tuple for an NFA 5.5 The Language Accepted by an NFA

Powerset If S is a set, the powerset of S is the set of all subsets of S: P(S) = {R R S} This always includes the empty set and S itself For example, P({1,2,3}) = {{}, {1}, {2}, {3}, {1,2}, {1,3}, {2,3}, {1,2,3}}

The 5-Tuple An NFA M is a 5-tuple M = (Q, Σ, δ, q 0, F), where: Q is the finite set of states Σ is the alphabet (that is, a finite set of symbols) δ (Q (Σ {ε}) P(Q) is the transition function q 0 Q is the start state F Q is the set of accepting states The only change from a DFA is the transition function δ δ takes two inputs: A state from Q (the current state) A symbol from Σ {ε} (the next input, or ε for an ε-transition) δ produces one output: A subset of Q (the set of possible next states - since multiple transitions can happen in parallel!)

Example: a,b a q 0 q 1 ε b q 2 Formally, M = (Q, Σ, δ, q 0, F), where Q = {q 0,q 1,q 2 } Σ = {a,b} (we assume: it must contain at least a and b) F = {q 2 } δ(q 0,a) = {q 0,q 1 }, δ(q 0,b) = {q 0 }, δ(q 0,ε) = {q 2 }, δ(q 1,a) = {}, δ(q 1,b) = {q 2 }, δ(q 1,ε) = {} δ(q 2,a) = {}, δ(q 2,b) = {}, δ(q 2,ε) = {} The language defined is {a,b}*

Outline 5.1 Relaxing a Requirement 5.2 Spontaneous Transitions 5.3 Nondeterminism 5.4 The 5-Tuple for an NFA 5.5 The Language Accepted by an NFA

The δ* Function The δ function gives 1-symbol moves We'll define δ* so it gives whole-string results (by applying zero or more δ moves) For DFAs, we used this recursive definition δ*(q,ε) = q δ*(q,xa) = δ(δ*(q,x),a) The intuition is similar for NFAs taking parallel transitions into account, but the ε-transitions add some technical difficulties

NFA IDs An instantaneous description (ID) is a description of a point in an NFA's execution It is a pair (q,x) where q Q is the current state x Σ* is the unread part of the input Initially, an NFA processing a string x has the ID (q 0,x) An accepting sequence of moves ends in an ID (f,ε) for some accepting state f F

The One-Move Relation On IDs We write I J if I is an ID and J is an ID that could follow from I after one move of the NFA That is, for any string x Σ* and any a Σ or a = ε, q,ax ( ) r,x ( ) if and only if r δ q,a ( )

The Zero-Or-More-Move Relation We write I J if there is a sequence of zero or more moves that starts with I and ends with J: I J Because it allows zero moves, it is a reflexive relation: for all IDs I, I I

The δ* Function Now we can define the δ* function for NFAs: ( ) = r ( q, x) ( r,ε) δ q,x { } Intuitively, δ*(q,x) is the set of all states the NFA might be in after starting in state q and reading x

M Accepts x Now δ*(q,x) is the set of states M may end in, starting from state q and reading all of string x So δ*(q 0,x) tells us whether M accepts x by computing all possible states by executing all possible transitions in parallel on the string x: A string x Σ* is accepted by an NFA M = (Q, Σ, δ, q 0, F) if and only if the set δ*(q 0, x) contains at least one element of F.

The Language An NFA Defines For any NFA M = (Q, Σ, δ, q 0, F), L(M) denotes the language accepted by M, which is L(M) = {x Σ* δ*(q 0, x) F {}}.

Exercise Compute the results of the following transitions: δ*(q1,ε) δ*(q1,0110)

Assignment Assignment #3 see website