Nondeterminism. September 7, Nondeterminism

Similar documents
Computer Sciences Department

September 7, Formal Definition of a Nondeterministic Finite Automaton

Chap. 1.2 NonDeterministic Finite Automata (NFA)

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

COM364 Automata Theory Lecture Note 2 - Nondeterminism

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

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

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

Closure under the Regular Operations

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

CS 154, Lecture 3: DFA NFA, Regular Expressions

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata

Nondeterministic Finite Automata

Introduction to Languages and Computation

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

CS 154. Finite Automata, Nondeterminism, Regular Expressions

Nondeterministic Finite Automata

UNIT-III REGULAR LANGUAGES

Chapter Five: Nondeterministic Finite Automata

Decision, Computation and Language

Finite Automata. Mahesh Viswanathan

Automata: a short introduction

Chapter 5. Finite Automata

Theory of Languages and Automata

CS 154. Finite Automata vs Regular Expressions, Non-Regular Languages

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

Lecture 3: Nondeterministic Finite Automata

Two-Way Automata and Descriptional Complexity

Finite Automata. Seungjin Choi

CS243, Logic and Computation Nondeterministic finite automata

Theory of Computation (I) Yijia Chen Fudan University

Finite Automata Part Two

Intro to Theory of Computation

CS 455/555: Finite automata

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

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

Nondeterministic finite automata

CSE 105 THEORY OF COMPUTATION

Nondeterminism and Epsilon Transitions

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

(Refer Slide Time: 0:21)

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

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

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

CPS 220 Theory of Computation REGULAR LANGUAGES

Non-deterministic Finite Automata (NFAs)

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

Formal Definition of Computation. August 28, 2013

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

PS2 - Comments. University of Virginia - cs3102: Theory of Computation Spring 2010

Finite Automata. Finite Automata

Closure under the Regular Operations

Nondeterministic Finite Automata

Context-Free Languages

Inf2A: Converting from NFAs to DFAs and Closure Properties

Extended transition function of a DFA

Part I: Definitions and Properties

Finite Automata Part Two

CSE 105 THEORY OF COMPUTATION

CSC173 Workshop: 13 Sept. Notes

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

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

CSE 105 THEORY OF COMPUTATION

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

CISC 4090 Theory of Computation

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

V Honors Theory of Computation

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 4: More on Regexps, Non-Regular Languages

Automata and Languages

Please give details of your answer. A direct answer without explanation is not counted.

Finite Automata (contd)

front pad rear pad door

Deterministic Finite Automaton (DFA)

CSC236 Week 11. Larry Zhang

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

CSE 105 Theory of Computation Professor Jeanne Ferrante

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

Formal Definition of a Finite Automaton. August 26, 2013

Constructions on Finite Automata

Introduction to Theory of Computing

Course 4 Finite Automata/Finite State Machines

Lecture 17: Language Recognition

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

CSE 105 THEORY OF COMPUTATION

Constructions on Finite Automata

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Theory of Computation (II) Yijia Chen Fudan University

Nondeterministic Finite Automata. Nondeterminism Subset Construction

Theory of Computation

Nondeterministic Finite Automata

CSE 105 THEORY OF COMPUTATION

Automata and Computability. Solutions to Exercises

Regular expressions and Kleene s theorem

Deterministic finite Automata

CISC4090: Theory of Computation

Takeaway Notes: Finite State Automata

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

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

Transcription:

September 7, 204

Introduction is a useful concept that has a great impact on the theory of computation

Introduction is a useful concept that has a great impact on the theory of computation So far in our discussion, every step of an Finite Automaton computation follows in a unique way from the preceding step: when the machine is in a given state and reads next input symbol we know what the next state will be

Introduction is a useful concept that has a great impact on the theory of computation So far in our discussion, every step of an Finite Automaton computation follows in a unique way from the preceding step: when the machine is in a given state and reads next input symbol we know what the next state will be We call this a deterministic computation. In a nondeterministic computation, choices may exist for the next state at any point

How does it occur? is a generalization of determinism; hence, every DFA is a nondeterministic finite automaton, NFA. However, an NFA may have additional features, as N in Figure shows q q ɛ,0 2 q 3 q 4 Figure : Nondeterministic Finite Automaton N

DFA versus NFA The difference between a deterministic finite automaton, DFA, and a nondeterministic finite automaton, NFA, is immediately apparent: Every state of DFA always has exactly one exiting transition arrow for each symbol in the alphabet; NFA violates this rule Example: state q in Figure.

DFA versus NFA The difference between a deterministic finite automaton, DFA, and a nondeterministic finite automaton, NFA, is immediately apparent: Every state of DFA always has exactly one exiting transition arrow for each symbol in the alphabet; NFA violates this rule Example: state q in Figure. In an NFA a state may have zero, one, or many exiting arrows for each symbol of the alphabet.

More differences In a DFA, labels on the transition arrows are symbols of the alphabet; An NFA may have its arrows labeled with symbols of the alphabet or ɛ.

More differences In a DFA, labels on the transition arrows are symbols of the alphabet; An NFA may have its arrows labeled with symbols of the alphabet or ɛ. Zero, one, or many arrows may exit from each state with the label ɛ.

How does an NFA compute? Look at NFA N acting on an input: q q ɛ,0 2 q 3 q 4 If N is in state q and the input symbol is the machine split into multiple copies of itself and follows all the possibilities in parallel

How does an NFA compute? Look at NFA N acting on an input: q q ɛ,0 2 q 3 q 4 If N is in state q and the input symbol is the machine split into multiple copies of itself and follows all the possibilities in parallel Each copy of the machine takes one of the possible ways to proceed and continues as before

How does an NFA compute? Look at NFA N acting on an input: q q ɛ,0 2 q 3 q 4 If N is in state q and the input symbol is the machine split into multiple copies of itself and follows all the possibilities in parallel Each copy of the machine takes one of the possible ways to proceed and continues as before If there are subsequent choices, the machine splits again

How does an NFA compute? Look at NFA N acting on an input: q q ɛ,0 2 q 3 q 4 If N is in state q and the input symbol is the machine split into multiple copies of itself and follows all the possibilities in parallel Each copy of the machine takes one of the possible ways to proceed and continues as before If there are subsequent choices, the machine splits again If the next input symbol does not appear on any of the arrows exiting the state occupied by a copy of the machine, that copy dies along with the branch of computation associated with it

How does an NFA compute? Look at NFA N acting on an input: q q ɛ,0 2 q 3 q 4 If N is in state q and the input symbol is the machine split into multiple copies of itself and follows all the possibilities in parallel Each copy of the machine takes one of the possible ways to proceed and continues as before If there are subsequent choices, the machine splits again If the next input symbol does not appear on any of the arrows exiting the state occupied by a copy of the machine, that copy dies along with the branch of computation associated with it If any one of these copies of the machine is in an accept state at the end of the input, the NFA accepts the input; otherwise it rejects the input

How does an NFA compute? Look at NFA N acting on an input: q q ɛ,0 2 q 3 q 4 If N is in state q and the input symbol is the machine split into multiple copies of itself and follows all the possibilities in parallel Each copy of the machine takes one of the possible ways to proceed and continues as before If there are subsequent choices, the machine splits again If the next input symbol does not appear on any of the arrows exiting the state occupied by a copy of the machine, that copy dies along with the branch of computation associated with it If any one of these copies of the machine is in an accept state at the end of the input, the NFA accepts the input; otherwise it rejects the input If a state with an ɛ symbol on some exiting arrow is encountered, the machine split into multiple copies without reading any input.

Note on ɛ-transitions The behavior of an NFA on an ɛ-trasition differs from its behavior on non-ɛ transitions because it performs a transtion without reading the input. Hence, when an ɛ-transition is encountered the machine must split. Each copy follows the exiting ɛ labeled arrow, as the one staying to the current state. Then the machine proceeds nondeterministically as before

Observations Hence, nondeterminism may be seen as a kind of parallel computation wherein several processes can run concurrently If at least one of these processes accepts then the entire computation accepts.

Tree computation Another way to think of a nondeterministic computation is as a tree of possibilities The root of the tree corresponds to the start of the computation Every branching point in the tree corresponds to a point in the computation at which the machine has multiple choices The machine accepts if at least one of the computation branches ends in an accept state as shown in Figure 2

Comparison of DFA and NFA Figure 2 : DFA computation NFA computation start start... reject...... accept or reject accept Deterministic and nondeterministic computations

Example run of N q q ɛ,0 2 q 3 q 4 On input 000 start in q and read 0 There is only one place to go on 0: back to q Next, read the symbol. There are two choices: either stay in q or move to q 2. Keep track of possibilities by placing a token on each state where machine can be, i.e., tokens are on q and q 2 An ɛ arrow exits q 2, so the machine splits again: keep on token on q 2 and move the other to q 3

Example run, continuation When the third symbol, 0, is read take each token in turn: keep token on q in place, move the token from q 2 to q 3, and remove the previous token from q 3. The last token had no 0 arrow to follow and the corresponding process dies. When the fourth symbol,, is read there are tokens on q and q 3. Thus, split the token on q keeping it on q and q 2 and move the token on q 3 on q 4 ; since there is an ɛ arrow leaving q 2 split the token on q 2 to q 3 too. Now there are tokens on each state. When fifth symbol,, is read the tokens on q and q 3 result in tokens on q, q 2 q 3 and q 4. The previous token on q 2 is removed and the token previously on q 4 stays on q 4

Eliminate token duplication There are two valid tokens on q 4. Remove one of them because we only need to remember that q 4 is a possible state at this point, not that it is possible to reach this state for multiple reasons.

Example run, continuation When the sixth symbol, 0 is read, keep the token on q in place, move the token from q 2 to q 3, remove previous token from q 3, and leave the token on q 4 on q 4 Now the end of the input is detected, since q 4 has a token and it is final, the input is accepted.

Example Consider the NFA N and the string 0 0 0 q q ɛ,0 2 q 3 q 4 The itrees in T N w are in Figure 3

An NFA tree computation 0 0 q q 3 q q q q 2 ɛ q 3 q2 ɛ q q 3 q 4 0 q q 3 q 4 q 2 ɛ q 3 q 3 q 4 q 4 q 4 Figure 3 : Tree computation performed by N

Note N rejects the string 00, as can be seen on Figure 3 By performing other similar experiments we can see that N accepts all strings that contain either 0 or as substrings

Why nondeterministic automata Every NFA can be converted into an equivalent DFA

Why nondeterministic automata Every NFA can be converted into an equivalent DFA Constructing NFA is sometimes easier than constructing DFA

Why nondeterministic automata Every NFA can be converted into an equivalent DFA Constructing NFA is sometimes easier than constructing DFA An NFA may be much smaller than a DFA that performs the same task

Why nondeterministic automata Every NFA can be converted into an equivalent DFA Constructing NFA is sometimes easier than constructing DFA An NFA may be much smaller than a DFA that performs the same task NFA provides good introduction to nondeterminism in more powerful computational models

Example.30 Let A be the language consisting of all strings over {0, } containing a in the third position from the end, i.e. A = {x {0, } x = s s 2, s 2 = 2} Example: 00000 A but 00 A The NFA N 2 in Figure 4 recognizes this language q q 2 q 3 q 4 Figure 4 : The NFA N 2 recognizing A

Note N 2 stays in q until it guess that it is three places from the end When it is three places from the end, if it reads a symbol, it branches to q 2 and then uses q 3 and q 4 to check if its guess was correct.

A DFA equivalent to N2 As we mentioned earlier, every NFA can be converted into an equivalent DFA Sometimes that DFA may have many more states. The smallest DFA, D 2, equivalent to N 2, in Figure 5, contains 8 states. Note: while understanding the functionality of N 2 is easy, the functionality of D 2 is more difficult to understand

The DFA D 2 0 q 000 0 q 00 0 q 00 q 0 0 0 0 0 q 00 q 0 q 0 q Figure 5 : DFA D 2 equivalent to NFA N 2 0

Problem q q 2,ɛ q 3,ɛ q 4 Figure 6 : The NFA N 2 recognizing A Suppose that we added ɛ to the labels on the arrows going from q 2 to q 3 and from q 3 to q 4 in machine N 2, Figure 4, getting the machine in Figure 6. What language would the new N 2 recognize?

Problem q q 2,ɛ q 3,ɛ q 4 Figure 6 : The NFA N 2 recognizing A Suppose that we added ɛ to the labels on the arrows going from q 2 to q 3 and from q 3 to q 4 in machine N 2, Figure 4, getting the machine in Figure 6. What language would the new N 2 recognize? L(N 3 ) = {x {0, } x = s s 2, s 2 2}

Problem q q 2,ɛ q 3,ɛ q 4 Figure 6 : The NFA N 2 recognizing A Suppose that we added ɛ to the labels on the arrows going from q 2 to q 3 and from q 3 to q 4 in machine N 2, Figure 4, getting the machine in Figure 6. What language would the new N 2 recognize? L(N 3 ) = {x {0, } x = s s 2, s 2 2} 2. How to modify DFA D 2 in Figure 5 to recognize the same language?

Problem q q 2,ɛ q 3,ɛ q 4 Figure 6 : The NFA N 2 recognizing A Suppose that we added ɛ to the labels on the arrows going from q 2 to q 3 and from q 3 to q 4 in machine N 2, Figure 4, getting the machine in Figure 6. What language would the new N 2 recognize? L(N 3 ) = {x {0, } x = s s 2, s 2 2} 2. How to modify DFA D 2 in Figure 5 to recognize the same language? not so easy

The use ɛ transitions Consider the NFA N 3 in Figure 7 ɛ ɛ 0 0 0 0 0 Figure 7 : The NFA N 3

The use ɛ transitions Consider the NFA N 3 in Figure 7 ɛ ɛ 0 0 0 0 0 Figure 7 : The NFA N 3 The NFA N 3 in Figure 7 has a unary input alphabet, {0}

The use ɛ transitions Consider the NFA N 3 in Figure 7 ɛ ɛ 0 0 0 0 0 Figure 7 : The NFA N 3 The NFA N 3 in Figure 7 has a unary input alphabet, {0} N 3 demonstrates the use of ɛ transition for the construction of an NFA that accepts all strings of the form 0 k where k is a multiple of 2 or 3.

The use ɛ transitions Consider the NFA N 3 in Figure 7 ɛ ɛ 0 0 0 0 0 Figure 7 : The NFA N 3 The NFA N 3 in Figure 7 has a unary input alphabet, {0} N 3 demonstrates the use of ɛ transition for the construction of an NFA that accepts all strings of the form 0 k where k is a multiple of 2 or 3. Example: ɛ, 00, 000, 000000 are accepted by N 3 but 0, 00000 are rejected

Note N 3 illustrates a machine operating by initially guessing whether to test one case or another (multiple of 2 or multiple of 3) by branching into either one loop or another and then checking whether it was correct If incorrect the machine reject, if one or both cases are correct, the machine accepts We may try to construct a DFA for this job, but the N 3 is much simpler to understand

A working example a q b ɛ a a,b q 2 q 3 Figure 8 : The NFA N 4 This example will be used to illustrate the procedure for the conversion NFA DFA The NFA N 4 to be used to illustrate this procedure is in Figure 8. N 4 accepts strings ɛ, a, baba, baa, etc., but does not accept strings b, bb, babba, etc.