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

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

lec3:nondeterministic finite state automata

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

CT32 COMPUTER NETWORKS DEC 2015

CSE 105 THEORY OF COMPUTATION

Formal Languages and Automata

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

(a) R=01[((10)*+111)*+0]*1 (b) ((01+10)*00)*. [8+8] 4. (a) Find the left most and right most derivations for the word abba in the grammar

Multiple Choice Questions

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

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

6 NFA and Regular Expressions

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

Theory of Computation

ECS 120 Lesson 7 Regular Expressions, Pt. 1

Languages and Compilers

Theory of Computation Dr. Weiss Extra Practice Exam Solutions

JNTUWORLD. Code No: R

Ambiguous Grammars and Compactification

Complexity Theory. Compiled By : Hari Prasad Pokhrel Page 1 of 20. ioenotes.edu.np

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

UNIT I PART A PART B

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

Skyup's Media. PART-B 2) Construct a Mealy machine which is equivalent to the Moore machine given in table.

DVA337 HT17 - LECTURE 4. Languages and regular expressions

Interpreter. Scanner. Parser. Tree Walker. read. request token. send token. send AST I/O. Console

Automating Construction of Lexers

T.E. (Computer Engineering) (Semester I) Examination, 2013 THEORY OF COMPUTATION (2008 Course)

(Refer Slide Time: 0:19)

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design

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

Introduction to Automata Theory. BİL405 - Automata Theory and Formal Languages 1

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

Dr. D.M. Akbar Hussain

ECS 120 Lesson 16 Turing Machines, Pt. 2


Formal Languages and Compilers Lecture VI: Lexical Analysis

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

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

QUESTION BANK. Formal Languages and Automata Theory(10CS56)

Regular Languages and Regular Expressions

R10 SET a) Construct a DFA that accepts an identifier of a C programming language. b) Differentiate between NFA and DFA?

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

2010: Compilers REVIEW: REGULAR EXPRESSIONS HOW TO USE REGULAR EXPRESSIONS

Lexical Analysis. Dragon Book Chapter 3 Formal Languages Regular Expressions Finite Automata Theory Lexical Analysis using Automata

CS402 - Theory of Automata Glossary By

Lexical Analysis - 2

Introduction to Computers & Programming

Learn Smart and Grow with world


Compiler Construction

Theory of Programming Languages COMP360

CMPSCI 250: Introduction to Computation. Lecture #36: State Elimination David Mix Barrington 23 April 2014

TOPIC PAGE NO. UNIT-I FINITE AUTOMATA

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

Lexical Analysis. Chapter 2

Theory of Computations Spring 2016 Practice Final Exam Solutions

Implementation of Lexical Analysis

Finite Automata Part Three

MIT Specifying Languages with Regular Expressions and Context-Free Grammars

Regular Expressions. Agenda for Today. Grammar for a Tiny Language. Programming Language Specifications

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

Zhizheng Zhang. Southeast University

Compiler Construction

A Characterization of the Chomsky Hierarchy by String Turing Machines

Lecture 2 Finite Automata

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

CS402 - Theory of Automata FAQs By

Converting a DFA to a Regular Expression JP

CS2 Language Processing note 3

Theory and Compiling COMP360

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2016

Lexical Error Recovery

Finite Automata Part Three

Front End: Lexical Analysis. The Structure of a Compiler

14.1 Encoding for different models of computation

Limited Automata and Unary Languages

Formal languages and computation models

Final Course Review. Reading: Chapters 1-9

1. Draw the state graphs for the finite automata which accept sets of strings composed of zeros and ones which:

CSE 105 THEORY OF COMPUTATION

Context Free Grammars. CS154 Chris Pollett Mar 1, 2006.

2. Lexical Analysis! Prof. O. Nierstrasz!

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

Implementation of Lexical Analysis

CSE 105 THEORY OF COMPUTATION

Chapter Seven: Regular Expressions. Formal Language, chapter 7, slide 1

Lexical Analysis. Lecture 2-4

CSEP 501 Compilers. Languages, Automata, Regular Expressions & Scanners Hal Perkins Winter /8/ Hal Perkins & UW CSE B-1

Theory of Languages and Automata

Actually talking about Turing machines this time

Theory of Computations Spring 2016 Practice Final

Introduction to Lexical Analysis

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

Theory of Computation, Homework 3 Sample Solution

Solutions to Homework 10

Theory Bridge Exam Example Questions Version of June 6, 2008

UNIT -2 LEXICAL ANALYSIS

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Finite Automata Part Three

Transcription:

Finite Automata Dr. Nadeem Akhtar Assistant Professor Department of Computer Science & IT The Islamia University of Bahawalpur PhD Laboratory IRISA-UBS University of South Brittany European University of Brittany, Bretagne - France http://www.univ-ubs.fr 1

Automata Theory Automata theory is the study of abstract computing devices, or machines. (Computational model idealized computer) A manageable mathematical theory can be set up directly on a Computational model. The simplest computational model is called the finite state machine or finite automaton. 2

Automata Theory In 1930 s A. Turing studied an abstract machine that had all the capabilities of today s computers. Turing goal was to describe precisely the boundary between what a computing machine could do and what it could not do; his conclusions apply not only to his abstract Turing machines, but to today s real machines. 3

Automata Theory In the 1940 s and 1950 s, simpler kinds of machines, which we today call finite automata were studied by a number of researchers. 4

Automata Theory In the late 1950 s, N. Chomsky began the study of formal grammars These grammars have close relationships to abstract automata and serve today as the basis of some important software components, including parts of compilers. 5

Automata Theory In 1969, S. Cook extended Turing s study of what could and what could not be computed. Cook was able to separate those problems that can be solved efficiently by computer from those problems that can in principle be solved, but in practice take so much time that computers are useless for all but very small instances of the problem. These class of problems is called intractable or NP-hard. 6

Automata Theory It is highly unlikely that the exponential improvement in computing speed that computer hardware has been following ( Moore s Law ) will have significant impact on our ability to solve large instances of intractable problems. 7

Automata Theory What computer scientists do today depend on the theoretical developments. Finite automata and certain kinds of formal grammars, are used in the design and construction of important kinds of software. Turing machine help us understand what we can expect from our software. 8

Finite Automata 1- Software for designing and checking the behavior of digital circuits. 2- The lexical analyzer of a compiler, that is compiler component that breaks the input text into logical units, such as identifiers, keywords and punctuation. 3- Software for scanning large bodies of text, such as collection of Web pages, to find occurrences of words, phrases, or other patterns. 4- Software for verifying systems of all types that have finite number of distinct states, such as communications protocols or protocols for secure exchange of information. 9

Formal definition of a Finite Automaton A finite automaton is a 5-tuple (Q, Σ, δ, q o, F) where 1. Q is a finite set called the states, 2. Σ is a finite set called the alphabet, 3. δ: Qx Σ Q is the transition function, 4. q o Є Q is the start state, and 5. F Q is the set of accept states. 10

The finite automaton M 1 (1/2) 11

The finite automaton M 1 (2/2) A = { w wcontains at least one 1 and an even number of 0s follow the last 1}. Then L(M 1 ) = A, or equivalently, M 1 recognizes A. 12

The finite automaton M 2 13

The finite automaton M 2 14

The finite automaton M 3 15

The finite automaton M 3 16

The finite automaton M 4 17

The finite automaton M 4 Machine M 4 has two accept states q 1 and r 1. Alphabet Σ = {a, b} Accept strings are a, b, aa, bb, abs, bab M 4 accepts all strings that start or end with a or that start or end with b. M 4 accepts all strings that start or end with the same symbol. 18

The finite automaton M 5 Alphabet Σ = {0, 1, 2, <RESET>} Machine M 5 keeps a running count of the sum of the numerical input symbols it reads, modulo 3. Every time it receives <RESET> symbol it resets the count to 0. It accepts if the sum is 0, modulo 3, or in other words if the sum is a multiple of 3. 19

Designing Finite Automata (1) Reader as Automaton method You are given some language and want to design a finite automaton that recognizes it. Pretending to be the automaton, you receive an input string and must determine whether it isamemberofthelanguagetheautomaton is supposed to recognize. 20

Designing Finite Automata (2) Yougettoseethesymbolsinthestringoneby one. After each symbol you must decide whether the string seen so far is in the language. The reason is that you, like the machine, don t know when the end of the string is coming so you must always be ready with the answer. 21

Designing Finite Automata (3) Finite automaton is a type of machine having only finite number of states, which means a finite memory. 22

Designing Finite Automata (4) Example: Alphabetis{0,1}and The language consists of all strings with an odd number of 1s. Construct a finite automaton E 1 to recognize this language 23

Designing Finite Automata (5) Example: Alphabetis{0,1}and Thelanguageconsistsofallstringswithanoddnumberof 1s. ConstructafiniteautomatonE 1 torecognizethislanguage 24

Designing Finite Automata (6) Example: Design a finite automaton E 2 to recognize the regular language of all strings that contain the string 001 as a substring. For example, 0010, 1001, 001, and 11111110011111 are all language, but11and0000arenot. So there are four possibilities: 1. haven't just seen any symbols of the pattern, 2. havejustseena0, 3. havejustseen00,or 4. have seen the entire pattern 001. Assignthestatesq,q 0,q 00,andq 001 tothesepossibilities. 25

Designing Finite Automata (7) Accepts strings containing 001 26

Nondeterministic Finite Automaton N 1 27

Deterministic and NonDeterministicComputations with an accepting branch 28

The computation of N 1 on input 010110 29

Nondeterministic Finite Automaton N 2 30

Nondeterministic Finite Automaton N 2 Let A be the language consisting of all strings over {0, 1} containing a 1 in the third position from the end e.g. 000100, 00111, 00101 31

NFA N 3 NFA N 3 that has an input alphabet {0} consisting of a single symbol. An alphabet containing only one symbol is called a unary alphabet. 32

NFA N 3 This machine N 3 accepts all strings of the form 0 k where kis a multiple of 2 or 3. (Note: Superscript denotes repetition, not numerical exponentiation) N 3 accepts the strings, 00, 000, 0000, and 000000, but not 0 or 00000. 33

NFA N 4 34

NFA N 4 This machine N 4 accepts the strings ε, a, baba, and baa, It does not accept the strings b, bb, and babba. 35

Formal definition of a Nondeterministic Finite Automaton (NFA) A nondeterministic finite automaton is a 5-tuple (Q, Σ, δ, q o, F) where 1. Q is a finite set called the states, 2. Σ is a finite set called the alphabet, 3. δ: Qx Σ ε P(Q) is the transition function, 4. q o Є Q is the start state, and 5. F Q is the set of accept states. Note: Σ ε =ΣU{ε} 36

NFA N 1 37

NFA N 1 38

Formal definition of computation for an NFA 39

Equivalence of NFAS and DFAS Deterministic and nondeterministic finite automata recognize the same class of languages. (Regular languages) Equivalence of NFAs and DFAs is useful because describing an NFA for a given language sometimes is much easier than describing a DFA for that language. Two machines are equivalent if they recognize the same language. 40

PROOF (1) Theorem-1 Every nondeterministic finite automaton has an equivalent deterministic finite automaton. PROOF IDEA: If a language is recognized by an NFA, then we must show the existence of a DFA that also recognizes it. The idea is to convert the NFA into an equivalent DFA that simulates the NFA. 41

PROOF (2) If k is the number of states of the NFA, it has 2 k subsets of states. Each subset corresponds to one of the possibilities that the DFA must remember, so the DFA simulating the NFA will have2 k states. Now we need to figure out which will be the start state and accept states of the DFA, and what will be its transition function. 42

PROOF (3) 43

PROOF (4) 44

PROOF (5) 45

PROOF (6) 46

47

PROOF Example (1) NFA N 4 Thus in the formal description of N 4 = (Q, {a,b}, δ, 1, {1}), the set of states Q is {I, 2, 3} as shown in the following figure. 48

PROOF Example -(2) 49

PROOF Example -(3) 50

PROOF Example -(4) 51

PROOF Example -(5) 52

PROOF Example -(6) 53

PROOF Example -(7) 54

Regular language A language is called a regular language if some finite automaton recognizes it. 55

Regular Language Formal definition The collection of regular languages over an alphabet Σ is defined recursively as follows: The empty language Ø, and the empty string language {ε} are regular languages. For each a Σ (a belongs to Σ), the singleton language {a} is a regular language. If A and B are regular languages, then A B (union), A B (concatenation), and A*(Kleene star) are regular languages. No other languages over Σ are regular. 56

Regular Operations (1) In arithmetic, the basic objects are numbers and the tools are operations for manipulating them,suchas+andx. In the theory of computation the objects are languages and the tools include operations specifically designed for manipulating them. 57

Regular Operations (2) 58

Regular Operations (3) The star operation applies to a single language rather than to two different languages. That is, the star operation is a unary operation instead of a binary operation. It works by attaching any number of strings in A together to get a string in the new language. Because "any number" includes 0 as a possibility, the empty stringεis always a member of A*, no matterwhatais. 59

Regular Operations (4) Example: 60

Regular Operations (5) Let N = {I, 2, 3,... } be the set of natural numbers. When we say that N is closed under multiplication we mean that, for any x and y in N, the product x x y also is in N. In contrast N is not closed under division, as 1 and 2 are in N but 1/2 is not. Generally speaking, a collection of objects is closed under some operation if applying that operation to members of the collection returns an object still in the collection. The collection of regular languages is closed under all three of the regular operations. 61

Closure under the Regular Operations The class of regular languages is closed under the union operation. And The class of regular languages is closed under the concatenation operation. 62

Theorem-A (1) The class of regular languages is closed under the union operation. PROOF IDEA: We have regular languages A 1 and A 2 and want toprovethata 1 UA 2 isregular. The idea is to take two NFAs, N 1 and N 2 for A 1 and A 2, and combine them into one new NFA, N. 63

Theorem-A (2) Machine N must accept its input ifeither N 1 and N 2 acceptsthisinput. The new machine has a new start state that branches to the start states of the old machines with ε arrows. In this way the new machine nondeterministically guesses which of the two machines accepts the input. If one of them acceptstheinput,nwillacceptit,too. 64

Theorem-A (3) Construction of an NFA N to recognize A 1 U A 2 65

Theorem-A (4) 66

Theorem-A (5) 67

Theorem-B (1) The class of regular languages is closed under the concatenation operation. PROOF IDEA: We have regular languages A 1 and A 2 and want to provethata 1 oa 2 isregular. The idea is to take two NFAs, N 1 and N 2 for A 1 and A 2, and combine them into a new NFA N as shown in Figure. 68

Theorem-B (2) Construction of N to recognize A 1 oa 2 69

Theorem-B (3) 70

Theorem-B (4) 71

Theorem-C (1) The class of regular languages is closed under the star operation. PROOF IDEA: We have a regular language A 1 and want to prove that A 1 * alsoisregular. We take an NFA N 1 for A 1 and modify it to recognize A 1 *, as shown in the following figure. The resulting NFA N will accept its input whenever it can be broken into several pieces and N 1 accepts each piece. 72

Theorem-C (2) ConstructionofNtorecognizeA 1 * 73

Theorem-C (3) 74

Theorem-C (3) 75

Exercise 76

Exercise 77

Exercise 78

Exercise 79