Chapter Five: Nondeterministic Finite Automata

Slides:



Advertisements
Similar presentations
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
Advertisements

1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
YES-NO machines Finite State Automata as language recognizers.
January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.
Chapter Two: Finite Automata
NFAs Sipser 1.2 (pages 47–54). CS 311 Fall Recall… Last time we showed that the class of regular languages is closed under: –Complement –Union.
NFAs Sipser 1.2 (pages 47–54). CS 311 Mount Holyoke College 2 Recall… Last time we showed that the class of regular languages is closed under: –Complement.
Lecture 3UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 3.
CS5371 Theory of Computation
61 Nondeterminism and Nodeterministic Automata. 62 The computational machine models that we learned in the class are deterministic in the sense that the.
Finite Automata Finite-state machine with no output. FA consists of States, Transitions between states FA is a 5-tuple Example! A string x is recognized.
Lecture 3 Goals: Formal definition of NFA, acceptance of a string by an NFA, computation tree associated with a string. Algorithm to convert an NFA to.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Nondeterminism.
Lecture 3 Goals: Formal definition of NFA, acceptance of a string by an NFA, computation tree associated with a string. Algorithm to convert an NFA to.
Fall 2006Costas Busch - RPI1 Non-Deterministic Finite Automata.
CS5371 Theory of Computation Lecture 4: Automata Theory II (DFA = NFA, Regular Language)
Topics Automata Theory Grammars and Languages Complexities
Costas Busch - LSU1 Non-Deterministic Finite Automata.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
1 Non-Deterministic Finite Automata. 2 Alphabet = Nondeterministic Finite Automaton (NFA)
Nondeterminism (Deterministic) FA required for every state q and every symbol  of the alphabet to have exactly one arrow out of q labeled . What happens.
1 Unit 1: Automata Theory and Formal Languages Readings 1, 2.2, 2.3.
Languages Given an alphabet , we can make a word or string by concatenating the letters of . Concatenation of “x” and “y” is “xy” Typical example: 
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
CHAPTER 1 Regular Languages
Copyright © Curt Hill Finite State Automata Again This Time No Output.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
NFA defined. NFA A Non-deterministic Finite-state Automata (NFA) is a language recognizing system similar to a DFA. It supports a level of non-determinism.
Recognising Languages We will tackle the problem of defining languages by considering how we could recognise them. Problem: Is there a method of recognising.
Finite State Machines 1.Finite state machines with output 2.Finite state machines with no output 3.DFA 4.NDFA.
UNIT - I Formal Language and Regular Expressions: Languages Definition regular expressions Regular sets identity rules. Finite Automata: DFA NFA NFA with.
Regular Languages Chapter 1 Giorgi Japaridze Theory of Computability.
Complexity and Computability Theory I Lecture #5 Rina Zviel-Girshin Leah Epstein Winter
1/29/02CSE460 - MSU1 Nondeterminism-NFA Section 4.1 of Martin Textbook CSE460 – Computability & Formal Language Theory Comp. Science & Engineering Michigan.
1 Chapter 2 Finite Automata (part a) Hokkaido, Japan.
Theory of Computation Automata Theory Dr. Ayman Srour.
Theory of Computation Automata Theory Dr. Ayman Srour.
Theory of Languages and Automata By: Mojtaba Khezrian.
Fall 2004COMP 3351 Finite Automata. Fall 2004COMP 3352 Finite Automaton Input String Output String Finite Automaton.
WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Dr. Mohammad Nassef Department of Computer Science, Faculty of Computers and Information, Cairo University.
Lecture Three: Finite Automata Finite Automata, Lecture 3, slide 1 Amjad Ali.
Nondeterminism The Chinese University of Hong Kong Fall 2011
Lexical analysis Finite Automata
Non Deterministic Automata
Chapter 2 Finite Automata
Deterministic Finite Automata
Nondeterministic Finite Automata
Chapter 2 FINITE AUTOMATA.
Deterministic Finite Automata
CSC 4170 Theory of Computation Nondeterminism Section 1.2.
REGULAR LANGUAGES AND REGULAR GRAMMARS
Hierarchy of languages
Chapter Two: Finite Automata
Principles of Computing – UFCFA3-30-1
COSC 3340: Introduction to Theory of Computation
Non-Deterministic Finite Automata
CSE322 Definition and description of finite Automata
Non Deterministic Automata
4b Lexical analysis Finite Automata
Chapter Two: Finite Automata
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
4b Lexical analysis Finite Automata
CS21 Decidability and Tractability
CSC 4170 Theory of Computation Nondeterminism Section 1.2.
Chapter 1 Regular Language
Finite-State Machines with No Output
CSCI 2670 Introduction to Theory of Computing
CHAPTER 1 Regular Languages
Non Deterministic Automata
Nondeterminism The Chinese University of Hong Kong Fall 2010
Presentation transcript:

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

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. NFAs are a bit harder to think about than DFAs, because they do not appear to define simple computational processes. They may seem at first to be unnatural, like puzzles invented by professors for the torment of students. But have patience! NFAs and other kinds of nondeterministic automata arise naturally in many ways, as you will see later in this book, and they too have a variety of practical applications. Formal Language, chapter 5, slide 2

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 Formal Language, chapter 5, slide 3

Not A DFA Does not have exactly one transition from every state on every symbol: Two transitions from q0 on a No transition from q0 (on either a or b) Though not a DFA, this can be taken as defining a language, in a slightly different way Formal Language, chapter 5, slide 4

Possible Sequences of Moves 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 q0 to q0 to q0, rejecting From q0 to q0 to q1, accepting From q0 to q1, 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 Formal Language, chapter 5, slide 5

Nondeterministic Finite Automaton (NFA) 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 NFA is not necessarily deterministic Formal Language, chapter 5, slide 6

NFA Advantage DFA: NFA: An NFA for a language can be smaller and easier to construct than a DFA Strings whose next-to-last symbol is 1: DFA: NFA: Formal Language, chapter 5, slide 7

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 Formal Language, chapter 5, slide 8

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}*: Formal Language, chapter 5, slide 9

ε-Transitions To Accepting States An ε-transition can be made at any time For example, there are three sequences on the empty string No moves, ending in q0, rejecting From q0 to q1, accepting From q0 to q2, accepting Any state with an ε-transition to an accepting state ends up working like an accepting state too Formal Language, chapter 5, slide 10

ε-transitions For NFA Combining ε-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 Formal Language, chapter 5, slide 11

Incorrect Union A = {an | n is odd} B = {bn | n is odd} A ∪ B ? No: this NFA accepts aab Formal Language, chapter 5, slide 12

Correct Union A = {an | n is odd} B = {bn | n is odd} A ∪ B Formal Language, chapter 5, slide 13

Incorrect Concatenation A = {an | n is odd} B = {bn | n is odd} {xy | x ∈ A and y ∈ B} ? No: this NFA accepts abbaab Formal Language, chapter 5, slide 14

Correct Concatenation A = {an | n is odd} B = {bn | n is odd} {xy | x ∈ A and y ∈ B} Formal Language, chapter 5, slide 15

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 Formal Language, chapter 5, slide 16

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 without such a clear-cut procedure: Search all legal sequences of transitions on the input string? How? In what order? Formal Language, chapter 5, slide 17

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 deterministically searching the legal sequences, but… ...this nondeterminism does not directly correspond to anything in physical computer systems In spite of that, NFAs have many practical applications Formal Language, chapter 5, slide 18

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 Formal Language, chapter 5, slide 19

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}} Formal Language, chapter 5, slide 20

The 5-Tuple An NFA M is a 5-tuple M = (Q, Σ, δ, q0, 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 q0 ∈ 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) Formal Language, chapter 5, slide 21

Example: Formally, M = (Q, Σ, δ, q0, F), where Q = {q0,q1,q2} Σ = {a,b} (we assume: it must contain at least a and b) F = {q2} δ(q0,a) = {q0,q1}, δ(q0,b) = {q0}, δ(q0,ε) = {q2}, δ(q1,a) = {}, δ(q1,b) = {q2}, δ(q1,ε) = {} δ(q2,a) = {}, δ(q2,b) = {}, δ(q2,ε) = {} The language defined is {a,b}* Formal Language, chapter 5, slide 22

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 Formal Language, chapter 5, slide 23

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 the similar for NFAs, but the ε-transitions add some technical hair Formal Language, chapter 5, slide 24

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 (q0,x) An accepting sequence of moves ends in an ID (f,ε) for some accepting state f ∈ F Formal Language, chapter 5, slide 25

The One-Move Relation On IDs We write 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 ω ∈ Σ or ω = ε, Formal Language, chapter 5, slide 26

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

The δ* Function Now we can define the δ* function for NFAs: Intuitively, δ*(q,x) is the set of all states the NFA might be in after starting in state q and reading x Our definition allows ε-transitions, including those made before the first symbol of x is read, and those made after the last Formal Language, chapter 5, slide 28

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 δ*(q0,x) tells us whether M accepts x: A string x ∈ Σ* is accepted by an NFA M = (Q, Σ, δ, q0, F) if and only if δ*(q0, x) contains at least one element of F. Formal Language, chapter 5, slide 29

The Language An NFA Defines For any NFA M = (Q, Σ, δ, q0, F), L(M) denotes the language accepted by M, which is L(M) = {x ∈ Σ* | δ*(q0, x) ∩ F ≠ {}}. Formal Language, chapter 5, slide 30