Chapter 6: NFA Applications

Similar documents
Nondeterministic Finite Automata

Chapter Five: Nondeterministic Finite Automata

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

CSE 105 Theory of Computation Professor Jeanne Ferrante

Regular Language Equivalence and DFA Minimization. Equivalence of Two Regular Languages DFA Minimization

Lecture 3: Nondeterministic Finite Automata

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

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

Chapter Two: Finite Automata

Automata and Languages

Extended transition function of a DFA

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

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

Nondeterministic finite automata

CSE 311 Lecture 25: Relating NFAs, DFAs, and Regular Expressions. Emina Torlak and Kevin Zatloukal

Inf2A: Converting from NFAs to DFAs and Closure Properties

Lecture 1: Finite State Automaton

Finite Automata. Seungjin Choi

Uses of finite automata

Chap. 1.2 NonDeterministic Finite Automata (NFA)

Nondeterministic Finite Automata

CSC236 Week 11. Larry Zhang

CS 154, Lecture 3: DFA NFA, Regular Expressions

Theory of Computation (I) Yijia Chen Fudan University

Finite Automata and Regular languages

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

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

Lecture 4 Nondeterministic Finite Accepters

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

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

Nondeterministic Finite Automata. Nondeterminism Subset Construction

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

September 7, Formal Definition of a Nondeterministic Finite Automaton

V Honors Theory of Computation

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CS 154 Formal Languages and Computability Assignment #2 Solutions

CS 154. Finite Automata, Nondeterminism, Regular Expressions

Incorrect reasoning about RL. Equivalence of NFA, DFA. Epsilon Closure. Proving equivalence. One direction is easy:

CS243, Logic and Computation Nondeterministic finite automata

Nondeterministic Finite Automata

Non-deterministic Finite Automata (NFAs)

CS 455/555: Finite automata

Theory of Computation (IX) Yijia Chen Fudan University

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

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,

Theory of Computation

FINITE STATE MACHINES (AUTOMATA)

CSE 105 THEORY OF COMPUTATION

Computability Theory

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

Closure under the Regular Operations

Intro to Theory of Computation

Equivalence of DFAs and NFAs

Further discussion of Turing machines

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

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

Fooling Sets and. Lecture 5

CSE 105 THEORY OF COMPUTATION

Intro to Theory of Computation

CS 322 D: Formal languages and automata theory

Automata and Languages

CSCE 551 Final Exam, April 28, 2016 Answer Key

COM364 Automata Theory Lecture Note 2 - Nondeterminism

1 Showing Recognizability

Deterministic Finite Automaton (DFA)

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

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

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

Decision, Computation and Language

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

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Constructions on Finite Automata

Theory of Computation (II) Yijia Chen Fudan University

3515ICT: Theory of Computation. Regular languages

C2.1 Regular Grammars

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

Course 4 Finite Automata/Finite State Machines

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

COMP-330 Theory of Computation. Fall Prof. Claude Crépeau. Lec. 9 : Myhill-Nerode Theorem and applications

C2.1 Regular Grammars

Most General computer?

Constructions on Finite Automata

Languages, regular languages, finite automata

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

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

Java II Finite Automata I

Theory of Computation (IV) Yijia Chen Fudan University

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

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

DFA to Regular Expressions

Chapter 2: Finite Automata

CSCE 551: Chin-Tser Huang. University of South Carolina

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 )

Nondeterminism. September 7, Nondeterminism

Introduction to Languages and Computation

Theory of Languages and Automata

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

CS21 Decidability and Tractability

Transcription:

Chapter 6: NFA Applications

Implementing NFAs The problem with implementing NFAs is that, being nondeterministic, they define a more complex computational procedure for testing language membership. To implement an NFA we must give a computational procedure that can look at a string and decide whether the NFA has at least one sequence of legal transitions on that string leading to an accepting state. This seems to require searching through all legal sequences for the given input string but how?

Implementing NFAs One approach is to convert the NFA into a DFA and implement that instead. This NFA/DFA conversion is both useful and theoretically interesting: the fact that it is always possible shows that in spite of their extra flexibility, NFAs have exactly the same power as DFAs. They can define exactly the regular languages.

Outline 6. NFA Implemented With Backtracking Search 6.2 NFA Implemented With Bit-Mapped Parallel Search 6.3 The Subset Construction 6.4 NFAs Are Exactly As Powerful As DFAs 6.5 DFA Or NFA?

From NFA To DFA For any NFA, there is a DFA that recognizes the same language Proof is by construction: a DFA that keeps track of the set of states the NFA might be in This is called the subset construction First, an example starting from this NFA:, q, q q 2

, q, q q 2 Initially, the set of states the NFA could be in is just {q } So our DFA will keep track of that using a start state labeled {q }:... {q }...

q q, q 2, Now suppose the set of states the NFA could be in is {q }, and it reads a The set of possible states after reading the is {q }, so we can show that transition: {q }...

q q, q 2, Suppose the set of states the NFA could be in is {q }, and it reads a The set of possible states after reading the is {q,q }, so we need another state: {q } {q,q }......

q q, q 2, From {q,q } on a, the next set of possible states is δ(q,) δ(q,) = {q,q 2 } From {q,q } on a, the next set of possible states is δ(q,) δ(q,) = {q,q,q 2 } Adding these transitions and states, we get

q q, q 2, {q } {q,q }...... {q,q 2 } {q,q,q 2 }......

And So On The DFA construction continues Eventually, we find that no further states are generated That's because there are only finitely many possible sets of states: P(Q) In our example, we have already found all sets of states reachable from {q }

q q, q 2, {q } {q,q } {q,q 2 } {q,q,q 2 }

Accepting States It only remains to choose the accepting states An NFA accepts x if its set of possible states after reading x includes at least one accepting state So our DFA should accept in all sets that contain at least one NFA accepting state

q q, q 2, {q } {q,q } {q,q 2 } {q,q,q 2 }

Some Exercises Convert the following NFAs into DFAs. a) b) c)

Implementation Note The subset construction defined the DFA transition function by R,a δ D ( ) = δ N * r R for some set of states R. ( r,a)

Start State Note In the subset construction, the start state for the new DFA is q D = δ N * ( q N,ε) Often this is the same as q D = {q N }, as in our earlier example But the difference is important if there are ε-transitions from the NFA's start state

Empty-Set State Note The empty set is a subset of every set So the full subset construction always produces a DFA state for {} This is reachable from the start state if there is some string x for which the NFA has no legal sequence of moves: δ N *(q N,x) = {} For example, this NFA, with L(N) = {ε} q

P({q }) = { {}, {q } } A 2-state DFA q δ D { q }, ( ) = δ N * δ D { q }, r { q } ( ) = δ N * ( r,) = { } r { q } ( ) = δ N * δ D { }, ( r,) = { } r { } ( ) = δ N * δ D { }, ( r,) = { } ( r,) = { } r { } {q }, {},

Trap State Provided The subset construction always provides a state for {} And it is always the case that ( ) = δ N * δ D { },a ( r,a) = { } r { } so the {} state always has transitions back to itself for every symbol a in the alphabet It is a non-accepting trap state

Outline 6. NFA Implemented With Backtracking Search 6.2 NFA Implemented With Bit-Mapped Parallel Search 6.3 The Subset Construction 6.4 NFAs Are Exactly As Powerful As DFAs 6.5 DFA Or NFA?

NFAs Are Exactly As Powerful As DFAs We want to show that NFAs and DFAs are equivalent. This means we want to show that for any NFA there is a DFA and for any DFA there is an NFA.

Lemma 6.3 If L(N) for some NFA N, then L(N) is a regular language. Proof: Every NFA N gives rise to an equivalent DFA D via the subset construction with L(N) = L(D). Therefore L(N) is regular.

Lemma 6.4 If L is any regular language, there is some NFA N for which L(N) = L. Proof: DFAs are just special NFAs that have never have a choice. To turn a DFA into an NFA all we have to do is modify the transition function from returning single states to sets of states: Let L be any regular language By definition there must be some DFA M = (Q, Σ, δ, q, F) with L(M) = L Define a new NFA N = (Q, Σ, δ', q, F), where δ'(q,a) = {δ(q,a)} for all q Q and a Σ, and δ'(q,ε) = {} for all q Q Now δ'*(q,x) = {δ*(q,x)}, for all q Q and x Σ* Thus L(N) = L(M) = L

Theorem 6.4 A language L is L(N) for some NFA N if and only if L is a regular language. Proof: Follows immediately from the previous lemmas