Chap. 1.2 NonDeterministic Finite Automata (NFA)

Similar documents
Nondeterminism. September 7, Nondeterminism

Chapter Five: Nondeterministic Finite Automata

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

Nondeterministic Finite Automata

Intro to Theory of Computation

Theory of Computation (I) Yijia Chen Fudan University

COM364 Automata Theory Lecture Note 2 - Nondeterminism

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

September 7, Formal Definition of a Nondeterministic Finite Automaton

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

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata

Nondeterministic Finite Automata. Nondeterminism Subset Construction

Lecture 3: Nondeterministic Finite Automata

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

Theory of Languages and Automata

Automata and Languages

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

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

Nondeterminism and Epsilon Transitions

CSE 105 Theory of Computation Professor Jeanne Ferrante

CS 154, Lecture 3: DFA NFA, Regular Expressions

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CS 154. Finite Automata, Nondeterminism, Regular Expressions

CSC236 Week 11. Larry Zhang

Fooling Sets and. Lecture 5

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

Introduction to Languages and Computation

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

Chapter 6: NFA Applications

Finite Automata and Regular languages

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

CS21 Decidability and Tractability

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

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

Lecture 4 Nondeterministic Finite Accepters

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

Nondeterministic finite automata

Nondeterministic Finite Automata

Inf2A: Converting from NFAs to DFAs and Closure Properties

Nondeterministic Finite Automata

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

CS 154 Formal Languages and Computability Assignment #2 Solutions

Finite Automata Part Two

Finite Automata Part Two

UNIT-III REGULAR LANGUAGES

Non-deterministic Finite Automata (NFAs)

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

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 )

Non-Deterministic Finite Automata

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

Closure under the Regular Operations

Extended transition function of a DFA

CS243, Logic and Computation Nondeterministic finite automata

CPS 220 Theory of Computation REGULAR LANGUAGES

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

Lecture 1: Finite State Automaton

CS 455/555: Finite automata

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

Automata: a short introduction

Theory of Computation (II) Yijia Chen Fudan University

Computational Models Lecture 2 1

Context-Free Languages

Computational Models Lecture 2 1

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

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,

CMSC 330: Organization of Programming Languages

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

Finite Automata. Finite Automata

front pad rear pad door

Finite Automata - Deterministic Finite Automata. Deterministic Finite Automaton (DFA) (or Finite State Machine)

Takeaway Notes: Finite State Automata

Nondeterministic Finite Automata

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

Finite Automata. Mahesh Viswanathan

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

Languages, regular languages, finite automata

Theory of Computation

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

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

CSE 105 THEORY OF COMPUTATION

CS 322 D: Formal languages and automata theory

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

Theory of Computation (IV) Yijia Chen Fudan University

Decision, Computation and Language

Uses of finite automata

Algorithms for NLP

Sri vidya college of engineering and technology

Finite Automata. Seungjin Choi

Constructions on Finite Automata

3515ICT: Theory of Computation. Regular languages

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CSC236 Week 10. Larry Zhang

C2.1 Regular Grammars

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

CISC 4090 Theory of Computation

Theory of Computation

C2.1 Regular Grammars

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

Nondeterministic Finite Automata and Regular Expressions

CSE 105 THEORY OF COMPUTATION

Transcription:

Chap. 1.2 NonDeterministic Finite Automata (NFA) DFAs: exactly 1 new state for any state & next char NFA: machine may not work same each time More than 1 transition rule for same state & input Any one is valid Choice is made with crystal ball which one will lead to an accepting state if possible Also ε (the empty string) is allowed on an edge: State transition can be made without reading any input characters See page 48 Fig. 1.27. two 1s from q 1 & ε on q 2 ->q 3 Accepts all strings from {0,1}* containing 101 or 11 How does computation proceed? Assume at a step where multiple options are possible a separate copy of the NFA is started up for each, and run in parallel All with the same starting state and remaining input Each takes a different edge Acceptance if any end up in an accepting state See Fig. 1.28 note a 1 from q1 can go to q2 or (because of ε leaving q2) go to q3 1

Ways to think of nondeterminism Parallel threads checking different paths Tree of possibilities NFA always guesses correctly (crystal ball) Examples (p.51) Ex. 1.30 N 2 : a 1 in third position from end Nondeterminism is knowing when we are 3 symbols from end (p.52) Ex. 1.33 N 3 : 0 k, where k is multiple of 2 or 3 ε edges lead to two different DFAs One that accepts strings of two 0s One that accepts strings of 3 0s At start, crystal ball knows which it is (p.53) Ex. 1.35 N 4 : { ε, a, bb, babba, } 2

(p.53) NFA Formal Definition: N = (Q,, δ, q0, F) Q, Σ, q0, and F are all as before δ: Q x Σ ε -> P(Q) Σ ε = Σ U {ε} epsilon-extended alphabet P(Q) = power set of Q set of all subsets of Q Thus each member of P(Q) is a subset of Q N accepts w (w a string from Σ*) if w = y 1 y 2 y m where y i ε Σ ε (i.e. some may be ε ) there exists a sequence of states r 0, r 1, r m where r 0 = q0, r m ε F r i+1 ε δ(r i, y i+1 ) p. 54: e.g. N 1 accepts all strings containing 101 or 11 Look at transition table each transition is to a set of states Remember φ is empty set 3

(p.55) Theorem Every NFA has an equivalent DFA. Proof by construction: given NFA, build matching DFA Basic idea: matching DFA has one state for every possible set of states that NFA can be in at any time Assume given NFA N = (Q,, δ, q0, F) Build DFA M = (Q,, δ, q0, F ) Simple case first, if no ε rules in N Q = P(Q) q0 = {q0} F = {R R in Q, R contains an accept state from F) for each R in Q, and a in Σ: δ (R, a) = {q q in Q, for some r in R, δ(r,a)=q} Note: δ (R, a) can return empty set ɸ If there are ε rules in N: i.e. some δ(q, ε) -> q Define for any RεQ, E(R) = {q q ε Q, q can be reached from some q in R via 0 or more ε edges} E(R) = ε reachable states from R in 0 or more ε Now δ (R, a) = {q q in Q, for some r in R, q in E(δ(r,a))} Also q0 = E({q0}) If NFA has Q states, DFA has up to 2 Q states KEY RESULT: NFAs are no more powerful than DFAs! Just easier to design 4

Example 1.41: p. 56 convert NFA N 4 to DFA D Q = {1,2,3} states of N 4 P(Q) = {{},{1}, {2}, {3}, {1,2}, {1,3}, {2,3}, {1,2,3}} Each represents a possible state of D Compute E - states reachable by ε - of each state of Q E({1}) = {1,3} 3 because of ε from 1 to 3 E({2}) = {2} no ε from 2 E({3}) = {3} E({1,2}) = {1,2,3} E{{1,3}) = {1,3} E({2,3}) = {2,3} E({1,2,3}) = {1,2,3} Start state is E of N 4 s start state 1 = E({1}) = {1,3} Accept states are those containing any of N 4 s F states ({1}) {{1}, {1,2}, {1,3}, {1,2,3}} See Fig. 1.43 p. 58 Note no edges into {1} or {1,2} so could eliminate See Fig. 1.44 for reduced graph (no way to get to {1} or {1,2} 5

Details of Transitions in Fig. 1.43 {2} in D input a: {2,3} because N has a edge from 2 to 2 & 3 input b: {3} {1} in D input a: ɸ because no a s leave 1 in N input b: {2} because b edge from 1 to 2 in N {3} in D input a: {1,3} because in N a edge from 3 to 1 but also from 1 there s an ε edge back to 3 input b: ɸ because no a s leave 3 in N {1,2} in D input a: {2,3} while 1 has no a edges, 2 does to {2,3} input b: {2,3} N has a b edge from 1 to 2 and a b edge from 2 to 3 {1,3} in D input a: {1, 3} while 1 has no a edges, from 3 there is a edge to 1, with an ε back to 3 input b: {2} N has a b edge from 1 to 2 but no b edges from 3 {2,3} in D input a: {1, 2, 3} a edge from 2 to 2, from 3 there is a edge to 1, with an ε back to 3 input b: {3} N has a b edge from 2 to 3 but no b edges from 3 {1,2,3} in D input a: {1, 2, 3} no a edges from 1 but a edge from 2 to 2 and 3 from 3 there is a edge to 1, with an ε back to 3 input b: {2,3} N has a b edge from 1 to 2 and b edge from 2 to 3 6

Alternative from transition table N s original transition table: State a b ε E(state) 1 {} {2} {3} {1,3} 2 {2,3} {3} {} {2} 3 {1} {} {} {3} D s Transition Table State a b {1} E({}) = {} E(2) = {2} {2} E(2)UE(3) = {2}U{3}={2,3} E(3) = {3} {3} E(1) = {1,3} E({}) = {} {1,2} E({}) U E(2) U E(3) = {2,3} E(2) U E(3) = {2,3} ->{1,3} E(1) = {1,3} E(2) U E({}) = {2} {2,3} E(1) U E(2) U E(3) = {1,2,3} E(3) = {3} {1,2,3} E(1) U E(2) U E(3) = {1,2,3} E(2) U E(3) = {2,3} {} E({}) = {} E({}) = {} To E s that contain 1 in state, add 3 because of ε 1->3 Each cell δ (q,x) is Union of E(δ(q,x)) where q is in set q Red states are in D s final set {1,3} is D s start state because its E(1) where 1 is N s state 7