Decision, Computation and Language

Similar documents
Course 4 Finite Automata/Finite State Machines

Finite Automata. Finite Automata

Nondeterministic Finite Automata

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

COM364 Automata Theory Lecture Note 2 - Nondeterminism

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,

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

Chapter Five: Nondeterministic Finite Automata

Nondeterminism. September 7, Nondeterminism

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

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

Chapter 2: Finite Automata

Theory of Computation

Lecture 4 Nondeterministic Finite Accepters

Deterministic Finite Automaton (DFA)

Lecture 3: Nondeterministic Finite Automata

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CSC173 Workshop: 13 Sept. Notes

Finite Automata. Seungjin Choi

September 7, Formal Definition of a Nondeterministic Finite Automaton

Finite Automata (contd)

CSE 105 THEORY OF COMPUTATION

CSC236 Week 11. Larry Zhang

Chapter 5. Finite Automata

Uses of finite automata

Languages, regular languages, finite automata

CS 154, Lecture 3: DFA NFA, Regular Expressions

Finite Automata Part Two

Constructions on Finite Automata

CSE 105 THEORY OF COMPUTATION

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Takeaway Notes: Finite State Automata

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

Theory of Computation (I) Yijia Chen Fudan University

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

Constructions on Finite Automata

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

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

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

Closure under the Regular Operations

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

CS 154. Finite Automata, Nondeterminism, Regular Expressions

Nondeterministic Finite Automata. Nondeterminism Subset Construction

CS21 Decidability and Tractability

CS243, Logic and Computation Nondeterministic finite automata

Nondeterministic Finite Automata

Intro to Theory of Computation

Closure under the Regular Operations

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

CS 208: Automata Theory and Logic

Theory of Computation

Equivalence of Regular Expressions and FSMs

Automata and Languages

Optimizing Finite Automata

Turing Machines Part III

Lecture 3: Finite Automata. Finite Automata. Deterministic Finite Automata. Summary. Dr Kieran T. Herley

Nondeterministic Finite Automata

Finite Automata. Mahesh Viswanathan

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

Finite Automata and Regular languages

What languages are Turing-decidable? What languages are not Turing-decidable? Is there a language that isn t even Turingrecognizable?

Nondeterministic finite automata

Finite Automata and Languages

Computability Theory

Classes and conversions

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 )

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

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

CS21 Decidability and Tractability

Extended transition function of a DFA

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

Automata: a short introduction

Lecture 1: Finite State Automaton

Announcements. Problem Set Four due Thursday at 7:00PM (right before the midterm).

Nondeterministic Finite Automata

Nondeterminism and Epsilon Transitions

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

Computational Models #1

Sri vidya college of engineering and technology

Finite Automata Part Two

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

CSE 105 THEORY OF COMPUTATION

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

Chapter Two: Finite Automata

(Refer Slide Time: 0:21)

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

Chapter 6: NFA Applications

Inf2A: Converting from NFAs to DFAs and Closure Properties

Part I: Definitions and Properties

Formal Definition of a Finite Automaton. August 26, 2013

Non-Deterministic Finite Automata

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

Non-deterministic Finite Automata (NFAs)

CS 455/555: Finite automata

Finite-state machines (FSMs)

Nondeterministic Finite Automata and Regular Expressions

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

Chap. 1.2 NonDeterministic Finite Automata (NFA)

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

Lecture 3: Finite Automata

Transcription:

Decision, Computation and Language Non-Deterministic Finite Automata (NFA) Dr. Muhammad S Khan (mskhan@liv.ac.uk) Ashton Building, Room G22 http://www.csc.liv.ac.uk/~khan/comp218

Finite State Automata (FSA) Deterministic On each input there is one and only one state to which the automaton can transition from its current state Nondeterministic An automaton can be in several states at once M S Khan (Univ. of Liverpool) COMP218 Decision, Computation and Language 2

Non-Deterministic Finite Automata nondeterministic - an input string does not determine the final state. This is because given a current state and an input letter, we may specify a set of allowable new states, not just one. Then we say that a NFA accepts an input word w if there exists a sequence of transitions labelled by symbols in w, starting from initial state and ending at some accepting state. M S Khan (Univ. of Liverpool) COMP218 Decision, Computation and Language 3

Non-Deterministic Finite Automata A NFA has the power to be in several states at once Each NFA accepts a language that is also accepted by some DFA NFA are often more succinct and easier than DFAs We can always convert an NFA to a DFA, but the latter may have exponentially more states than the NFA. The difference between the DFA and the NFA is the type of transition function δ For a NFA δ is a function that takes a state and input symbol as arguments (like the DFA transition function), but returns a set of zero or more states (rather than returning exactly one state, as the DFA must) M S Khan (Univ. of Liverpool) COMP218 Decision, Computation and Language 4

Non-deterministic Finite Automata (NFA) A Non-deterministic Finite Automaton (NFA) is of course non-deterministic Implying that the machine can exist in more than one state at the same time Transitions could be non-deterministic q i 1 1 q j q k Each transition function therefore maps to a set of states M S Khan (Univ. of Liverpool) COMP218 Decision, Computation and Language 5

Non-deterministic Finite Automata (NFA) A Non-deterministic Finite Automaton (NFA) consists of: Q is a finite set of states is a finite set of input symbols (alphabet) q 0 Q is the start state F F Q is a set of final or accepting states δ, the transition function is a function that takes a state Q and an input symbol in as argument and returns a subset of Q, a mapping between Q S Q. An NFA is also a quintuple: {Q,, q 0,F, δ } The only difference between a NFA and a DFA is in the type of value that δ returns M S Khan (Univ. of Liverpool) COMP218 Decision, Computation and Language 6

The Formal Definition M S Khan (Univ. of Liverpool) COMP218 Decision, Computation and Language 7

How to use an NFA? Input: a word w in * Question: Is w acceptable by the NFA? Steps: Start at the start state q 0 For every input symbol in the sequence w do Determine all possible next states from all current states, given the current input symbol in w and the transition function If after all symbols in w are consumed and if at least one of the current states is a final state then accept w; Otherwise, reject w. M S Khan (Univ. of Liverpool) COMP218 Decision, Computation and Language 8

states NFA for strings containing 0,1 Regular expression: (0+1)*01(0+1)* Why is this non-deterministic? start 0,1 0,1 q 0 0 q 1 1 q 2 Final state What will happen if at state q 1 an input of 0 is received? Q = {q 0,q 1,q 2 } = {0,1} start state = q 0 F = {q 2 } Transition table symbols 0 1 q 0 {q 0,q 1 } {q 0 } q 1 Φ {q 2 } *q 2 {q 2 } {q 2 } M S Khan (Univ. of Liverpool) COMP218 Decision, Computation and Language 9

What is a dead state? Note: Explicitly specifying dead states is just a matter of design convenience, and this feature does not make a machine deterministic or non-deterministic. A DFA for recognizing the key word while q 0 w q 1 h q 2 i q 3 l q 4 e q 5 Any other input symbol An NFA for the same purpose: q dead Any symbol q 0 w q 1 h q 2 i q 3 l q 4 e q 5 Transitions into a dead state are implicit M S Khan (Univ. of Liverpool) COMP218 Decision, Computation and Language 10

Example M S Khan (Univ. of Liverpool) COMP218 Decision, Computation and Language 11

Example M S Khan (Univ. of Liverpool) COMP218 Decision, Computation and Language 12

Example Build an NFA for the following language: L = { w w ends in 01} Other examples Keyword recognizer (e.g., if, then, else, while, for, include, etc.) M S Khan (Univ. of Liverpool) COMP218 Decision, Computation and Language 13

Extension of δ/ø to NFA Paths M S Khan (Univ. of Liverpool) COMP218 Decision, Computation and Language 14

Notation: accepting / rejecting paths M S Khan (Univ. of Liverpool) COMP218 Decision, Computation and Language 15

Example M S Khan (Univ. of Liverpool) COMP218 Decision, Computation and Language 16

Equivalent DFA M S Khan (Univ. of Liverpool) COMP218 Decision, Computation and Language 17

Differences: DFA vs. NFA But, DFAs and NFAs are equivalent in their power to capture languages!! DFA 1. All transitions are deterministic Each transition leads to exactly one state 2. For each state, transition on all possible symbols (alphabet) should be defined 3. Accepts input if the last state is in F 4. Sometimes harder to construct because of the number of states 5. Practical implementation is feasible NFA 1. Some transitions could be nondeterministic A transition could lead to a subset of states 2. Not all symbol transitions need to be defined explicitly (if undefined will go to a dead state this is just a design convenience, not to be confused with non-determinism ) 3. Accepts input if one of the last states is in F 4. Generally easier than a DFA to construct 5. Practical implementation has to be deterministic (convert to DFA) or in the form of parallelism M S Khan (Univ. of Liverpool) COMP218 Decision, Computation and Language 18

A DFA is a NFA......in the sense that a DFA is a restricted form of NFA. In a DFA, the set of all new states that can be reached in a single transition from any given state and any letter in the alphabet, is of size 0 or 1. (In a NFA, we allow the set of new states to be larger.) Hence, any language accepted by a DFA is accepted by an NFA. The DFA in practice has about as many states as the NFA, although it has more transitions. M S Khan (Univ. of Liverpool) COMP218 Decision, Computation and Language 19

A few subtle properties of DFAs and NFAs The machine never really terminates. It is always waiting for the next input symbol or making transitions. The machine decides when to consume the next symbol from the input and when to ignore it. (but the machine can never skip a symbol) => A transition can happen even without really consuming an input symbol (think of consuming as a free token) if this happens, then it becomes an -NFA (see next few slides). A single transition cannot consume more than one (non- ) symbol. M S Khan (Univ. of Liverpool) COMP218 Decision, Computation and Language 20

FA with -Transitions We can allow explicit -transitions in finite automata i.e., a transition from one state to another state without consuming any additional input symbol Makes it easier sometimes to construct NFAs Definition: -NFAs are those NFAs with at least one explicit -transition defined. -NFAs have one more column in their transition table M S Khan (Univ. of Liverpool) COMP218 Decision, Computation and Language 21

Example of an -NFA L = {w w is empty, or if non-empty will end in 01} 0,1 start q 0 0 q 0 q 1 δ E 0 1 *q 0 Ø Ø {q 0,q 0 } 1 q 0 {q 0,q 1 } {q 0 } {q 0 } q 1 Ø {q 2 } {q 1 } q 2 ECLOSE(q 0 ) ECLOSE(q 0 ) ECLOSE(q 1 ) -closure of a state q, ECLOSE(q), is the set of all states (including itself) that can be reached from q by repeatedly making an arbitrary number of - transitions. *q 2 Ø Ø {q 2 } ECLOSE(q 2 ) M S Khan (Univ. of Liverpool) COMP218 Decision, Computation and Language 22

Example of an -NFA L = {w w is empty, or if non-empty will end in 01} 0,1 Simulate for w=101: 0 q 0 q 1 1 q 2 q 0 start q 0 q 0 1 q 0 1 δ E 0 1 *q 0 Ø Ø {q 0,q 0 } ECLOSE(q 0 ) Ø x 0 1 q 0 q 1 q 0 {q 0,q 1 } {q 0 } {q 0 } ECLOSE(q 0 ) q 2 q 1 Ø {q 2 } {q 1 } *q 2 Ø Ø {q 2 } M S Khan (Univ. of Liverpool) COMP218 Decision, Computation and Language 23

Example of another -NFA start q 0 0,1 0 q 0 q 1 q 3 1 1 q 2 δ E 0 1 *q 0 Ø Ø {q 0,q 0,q 3 } q 0 {q 0,q 1 } {q 0 } {q 0, q 3 } q 1 Ø {q 2 } {q 1 } *q 2 Ø Ø {q 2 } q 3 Ø {q 2 } {q 3 } M S Khan (Univ. of Liverpool) COMP218 Decision, Computation and Language 24

Equivalency of DFA, NFA, -NFA Theorem: A language L is accepted by some -NFA if and only if L is accepted by some DFA Implication: DFA NFA -NFA (all accept Regular Languages) M S Khan (Univ. of Liverpool) COMP218 Decision, Computation and Language 25