lec3:nondeterministic finite state automata

Similar documents
Finite Automata. Dr. Nadeem Akhtar. Assistant Professor Department of Computer Science & IT The Islamia University of Bahawalpur

1. (10 points) Draw the state diagram of the DFA that recognizes the language over Σ = {0, 1}

Converting a DFA to a Regular Expression JP

CS2 Language Processing note 3

6 NFA and Regular Expressions

Equivalence of NTMs and TMs

Finite automata. We have looked at using Lex to build a scanner on the basis of regular expressions.

Theory of Computation Dr. Weiss Extra Practice Exam Solutions

CS 310: State Transition Diagrams

Formal Languages and Compilers Lecture IV: Regular Languages and Finite. Finite Automata

Last lecture CMSC330. This lecture. Finite Automata: States. Finite Automata. Implementing Regular Expressions. Languages. Regular expressions

NFAs and Myhill-Nerode. CS154 Chris Pollett Feb. 22, 2006.

Regular Languages and Regular Expressions

CSE450. Translation of Programming Languages. Lecture 20: Automata and Regular Expressions

ECS 120 Lesson 16 Turing Machines, Pt. 2

CMPSCI 250: Introduction to Computation. Lecture 20: Deterministic and Nondeterministic Finite Automata David Mix Barrington 16 April 2013

Regular Expression Constrained Sequence Alignment

Automating Construction of Lexers

Lecture 2 Finite Automata

CS5371 Theory of Computation. Lecture 8: Automata Theory VI (PDA, PDA = CFG)

I have read and understand all of the instructions below, and I will obey the Academic Honor Code.

CSE450. Translation of Programming Languages. Automata, Simple Language Design Principles


Introduction to Computers & Programming

Implementation of Lexical Analysis

Lexical Analysis. Implementation: Finite Automata

Implementation of Lexical Analysis

CSE 105 THEORY OF COMPUTATION

CS402 Theory of Automata Solved Subjective From Midterm Papers. MIDTERM SPRING 2012 CS402 Theory of Automata

CS 181 B&C EXAM #1 NAME. You have 90 minutes to complete this exam. You may assume without proof any statement proved in class.

(Refer Slide Time: 0:19)

Midterm Exam II CIS 341: Foundations of Computer Science II Spring 2006, day section Prof. Marvin K. Nakayama

Limited Automata and Unary Languages

Variants of Turing Machines

CS 181 EXAM #1 NAME. You have 90 minutes to complete this exam. You may state without proof any fact taught in class or assigned as homework.

Ambiguous Grammars and Compactification

Implementation of Lexical Analysis

Lexical Analysis. Chapter 2

Automata & languages. A primer on the Theory of Computation. The imitation game (2014) Benedict Cumberbatch Alan Turing ( ) Laurent Vanbever

CS Lecture 2. The Front End. Lecture 2 Lexical Analysis

Theory of Languages and Automata

CT32 COMPUTER NETWORKS DEC 2015

Lexical Analysis - 2

Turing Machines. A transducer is a finite state machine (FST) whose output is a string and not just accept or reject.

Front End: Lexical Analysis. The Structure of a Compiler

Definition 2.8: A CFG is in Chomsky normal form if every rule. only appear on the left-hand side, we allow the rule S ǫ.

CSE 105 THEORY OF COMPUTATION

Compiler Construction

Formal Definition of Computation. Formal Definition of Computation p.1/28

T Reactive Systems: Kripke Structures and Automata

HKN CS 374 Midterm 1 Review. Tim Klem Noah Mathes Mahir Morshed

CSE 105 THEORY OF COMPUTATION

CS 432 Fall Mike Lam, Professor. Finite Automata Conversions and Lexing

Lexical Analysis. Lecture 2-4

Formal Languages and Automata

Multiple Choice Questions

Introduction to Lexical Analysis

Regular Languages. MACM 300 Formal Languages and Automata. Formal Languages: Recap. Regular Languages

CSE 105 THEORY OF COMPUTATION

Languages and Compilers

CSE 105 THEORY OF COMPUTATION

MIT Specifying Languages with Regular Expressions and Context-Free Grammars

Safra's Büchi determinization algorithm

Timo Latvala. January 28, 2004

Lexical Analysis. Lecture 3-4

Zhizheng Zhang. Southeast University

CSE 431S Scanning. Washington University Spring 2013

Finite Automata Part Three

ECS 120 Lesson 7 Regular Expressions, Pt. 1

CS52 - Assignment 10

JNTUWORLD. Code No: R

A Characterization of the Chomsky Hierarchy by String Turing Machines

Lexical Analysis. Prof. James L. Frankel Harvard University

Theory of Computation

Decidable Problems. We examine the problems for which there is an algorithm.

David Griol Barres Computer Science Department Carlos III University of Madrid Leganés (Spain)

Turing Machines, continued

Finite Automata Part Three

Actually talking about Turing machines this time

for (i=1; i<=100000; i++) { x = sqrt (y); // square root function cout << x+i << endl; }

MIT Specifying Languages with Regular Expressions and Context-Free Grammars. Martin Rinard Massachusetts Institute of Technology

CISC 4090 Theory of Computation

Midterm I review. Reading: Chapters 1-4

UNION-FREE DECOMPOSITION OF REGULAR LANGUAGES

FAdo: Interactive Tools for Learning Formal Computational Models

Computer Sciences Department

UNIT I PART A PART B

Implementation of Lexical Analysis. Lecture 4

Formal Languages and Compilers Lecture VI: Lexical Analysis

Chapter Seven: Regular Expressions

CMPE 4003 Formal Languages & Automata Theory Project Due May 15, 2010.


Compiler Construction

Concepts Introduced in Chapter 3. Lexical Analysis. Lexical Analysis Terms. Attributes for Tokens

CIT3130: Theory of Computation. Regular languages

Computer Science Department Carlos III University of Madrid Leganés (Spain) David Griol Barres

COS 226 Written Exam 2 Fall 2016

UNIT -2 LEXICAL ANALYSIS

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

NONDETERMINISTIC MOORE

Transcription:

lec3:nondeterministic finite state automata 1

1.introduction Nondeterminism is a useful concept that has great impact on the theory of computation. When the machine is in a given state and reads the next input symbol, we know what the next state will be -it is determined this called deterministic computation but in a nondeterministic machine, several choices may exit for the next state at any point. Nondeterminism is a generalization of determinism,so every deterministic finite automaton is automatically a nondeterministic finite automaton. The different between a deterministic finite automation and a nondeterministic finite automaton. 1- every state of always has exactly one exiting transition arrow for each symbol in the alphabet but the nondeterministic violates that rule. 2-In DFA, label on the transition arrow are symbols from the alphabet.this NFA has an arrow with the label ε, an NFA may have arrows labeled with members of alphabet or ε. Zero, one, or many arrows may exit from each state with the label ε we are running an NFA on an input string and come to a state with multiple ways to proceed, the machine splits 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 dose not appear on any of the arrow exiting the state occupied by a copy of the machine,that copy of the machine dies, along with the branch of the computation associated with it. if any one of these copies of the machine is an accept state at the end of the input, the NFA accepts the input string. if state with an ε symbol on an exiting arrow is encountered, something similar happens. without reading any input, the machine splits into multiple copies, one following each of the exiting ε-label arrows and one staying at the current state. Nondeterminism may be viewed as a kind of parallel computation wherein multiple independent "processes" or "thread" can be running concurrently. when the NFA splits to following several choices, that corresponds to a process "forking" into sveral children, each proceeding separately. if at least one of these processes accepts, then te entire computation accepts. Another way to think of a nondeterministic computation is as 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 show below. 2

Example: state q1 has one exiting arrow for 0, but it has two for 1; state q2 has one arrow for 0, but it has none for 1. in an NDF a state may have zero, one, or many exiting arrows for each alphabet symbol.as show in figure below machine N1. 3

the computation of N1 on input 010110 is depicted in the following Example: Consider the nondeterministic finite automaton of Figure below, which accepts all strings that contain one of three possible substrings: 000, 111, or 1100. The computation tree on the input string 01011000 is de-picted in Figure below. (The paths arked with an asterisk denote paths where the automaton is stuck in a state because it had no transition available.) There are two accepting paths out of ten, 4

corresponding to the detection of the substrings 000 and 1100. The nondeterministic finite automaton thus accepts 01011000 because there is at least one way (here two) for it to do so. Example : consider the following NFA below that has an input alphabet {0} consisting of a single symbol. An alphabet containing only symbol is called a unary alphabet. this machine demonstrates the convenience of having ε arrows. It accepts all strings 5

of the from 0 k where k is a multiple of 2 or 3. for example machine accepts the strings ε, 00, 000, 0000, and 000000, but not 0 or 00000. Example: we given of NFA in following figure below, practice with it to satisfy yourself that it accept the string ε, a, baba, and baa, but that it doesn't accept the string b, bb, and babba. 2. Formal Definition of a NFA the formal definition of a nondeterministic finite automaton is similar to that of a deterministic finite automaton. Both have states, an input alphabet, transition function, start state, and a collection of accept states.. 6

Example :... the formal definition of computation for an NFA is similar to that for a DFA. Let N=(Q,, δ,q 0, F) be an NFA and ω a string over the alphabet. then w say that accept ω if we can write ω as r 1,...,r m. ω=y1y2y...y m where each y i is a member of ε and a sequence of state r 0, exists in Q with three conditions: condition 1 says that the machine starts out in the start state. condition 2 says that state r i+1 is one of the allowable next states when N is in state r i and reading y i+1. Observe that δ(r i, y i+1, ) is the set of allowable next states and so we say that r i+1 is a member of that set. 7

3. Equivalence of NFA to DFA Deterministic and nondeterministic finite automata recognize the same class of languages. Such equivalence is both surprising and useful. it is surprising because NFA appear to have more power than DAF, so we might expect that NFA recognize more language. Say that two machine are equivalent if they recognize the same language. every nondeterministic finite automaton has an equivalent deterministic finite automaton. the definition nondeterministic finite automata include deterministic ones as a special case the case where the number of transitions defined for each pair of current state and current input symbol never exceeds one. Thus any language that can be accepted by a deterministic finite automaton can be accepted by a nondeterministic one the same machine. we construct a deterministic one that mimics the behavior of the nondeterministic machine. In particular, the deterministic machine uses its state to keep track of all of the possible states in which the nondeterministic machine could find itself after reading the same string. Theorem : For every nondeterministic finite automaton, there exists an equivalent deterministic finite automaton (i.e., one that accepts the same language). Proof. Let the nondeterministic finite automaton be given by the five- tuple (Q,, δ,q 0, F). We construct an equivalent deterministic automaton (Q ', ', δ ',q 0 ', F ' ) as follows: Example: Consider the nondeterministic finite automaton given by and illustrated in Figure below (a). The corresponding deterministic finite automaton is given by 8

and illustrated in Figure below (b) (note that state is unreachable). Thus the conversion of a nondeterministic automaton to a deterministic one creates a machine, the states of which are all the subsets of the set of states of the nondeterministic automaton. The conversion takes a nondeterministic automaton with n states and creates a deterministic automaton with 2n states, an exponential increase. we saw briefly, many of these states may be useless, because they are unreachable from the start state; in particular, the empty state is always unreachable. In general, the conversion may create any number of unreachable states, Example: convert NFA to DFA for machine below 9

Example: converting NFA to DFA for machine below: a:nfa b:dfa 10

c:dfa after remove unnecessary state When generating a deterministic automaton from a given nondeterministic one, we can avoid generating unreachable states by using an iterative approach based on reachability : begin with the initial state of the nondeterministic automaton and proceed outward to those states reachable by the nondeterministic automaton. This process will generate only useful states states reachable from the start state and so may be considerably more efficient than the brute-force generation of all subsets. 11