= state, a = reading and q j

Similar documents
CS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6

NON-DETERMINISTIC FSA

CS 573 Automata Theory and Formal Languages

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER MACHINES AND THEIR LANGUAGES ANSWERS

Technische Universität München Winter term 2009/10 I7 Prof. J. Esparza / J. Křetínský / M. Luttenberger 11. Februar Solution

Minimal DFA. minimal DFA for L starting from any other

Nondeterministic Automata vs Deterministic Automata

Nondeterministic Finite Automata

Regular expressions, Finite Automata, transition graphs are all the same!!

Finite State Automata and Determinisation

Worked out examples Finite Automata

Homework 3 Solutions

CMPSCI 250: Introduction to Computation. Lecture #31: What DFA s Can and Can t Do David Mix Barrington 9 April 2014

Regular languages refresher

1 Nondeterministic Finite Automata

Let's start with an example:

Formal Languages and Automata

Assignment 1 Automata, Languages, and Computability. 1 Finite State Automata and Regular Languages

Lecture 08: Feb. 08, 2019

First Midterm Examination

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true.

Compiler Design. Spring Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz

Prefix-Free Regular-Expression Matching

Project 6: Minigoals Towards Simplifying and Rewriting Expressions

First Midterm Examination

2.4 Theoretical Foundations

Coalgebra, Lecture 15: Equations for Deterministic Automata

Grammar. Languages. Content 5/10/16. Automata and Languages. Regular Languages. Regular Languages

Finite Automata-cont d

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

CMSC 330: Organization of Programming Languages

CHAPTER 1 Regular Languages. Contents. definitions, examples, designing, regular operations. Non-deterministic Finite Automata (NFA)

Convert the NFA into DFA

State Minimization for DFAs

Descriptional Complexity of Non-Unary Self-Verifying Symmetric Difference Automata

CS 373, Spring Solutions to Mock midterm 1 (Based on first midterm in CS 273, Fall 2008.)

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

Discrete Structures, Test 2 Monday, March 28, 2016 SOLUTIONS, VERSION α

Designing finite automata II

CISC 4090 Theory of Computation

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. Comparing DFAs and NFAs (cont.) Finite Automata 2

Intermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. NFA for (a b)*abb.

@#? Text Search ] { "!" Nondeterministic Finite Automata. Transformation NFA to DFA and Simulation of NFA. Text Search Using Automata

CS 301. Lecture 04 Regular Expressions. Stephen Checkoway. January 29, 2018

Nondeterminism and Nodeterministic Automata

Counting Paths Between Vertices. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs

CSE 401 Compilers. Today s Agenda

Deterministic Finite Automata

CSCI 340: Computational Models. Kleene s Theorem. Department of Computer Science

Thoery of Automata CS402

1 PYTHAGORAS THEOREM 1. Given a right angled triangle, the square of the hypotenuse is equal to the sum of the squares of the other two sides.

CS 330 Formal Methods and Models

Myhill-Nerode Theorem

Java II Finite Automata I

5. (±±) Λ = fw j w is string of even lengthg [ 00 = f11,00g 7. (11 [ 00)± Λ = fw j w egins with either 11 or 00g 8. (0 [ ffl)1 Λ = 01 Λ [ 1 Λ 9.

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true.

Talen en Automaten Test 1, Mon 7 th Dec, h45 17h30

CS415 Compilers. Lexical Analysis and. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

NFA DFA Example 3 CMSC 330: Organization of Programming Languages. Equivalence of DFAs and NFAs. Equivalence of DFAs and NFAs (cont.

Table of contents: Lecture N Summary... 3 What does automata mean?... 3 Introduction to languages... 3 Alphabets... 3 Strings...

Running an NFA & the subset algorithm (NFA->DFA) CS 350 Fall 2018 gilray.org/classes/fall2018/cs350/

CHAPTER 1 Regular Languages. Contents

Automata and Regular Languages

CS 330 Formal Methods and Models Dana Richards, George Mason University, Spring 2016 Quiz Solutions

Chapter 2 Finite Automata

Lecture 09: Myhill-Nerode Theorem

Harvard University Computer Science 121 Midterm October 23, 2012

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

Compiler Design. Fall Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

More on automata. Michael George. March 24 April 7, 2014

Activities. 4.1 Pythagoras' Theorem 4.2 Spirals 4.3 Clinometers 4.4 Radar 4.5 Posting Parcels 4.6 Interlocking Pipes 4.7 Sine Rule Notes and Solutions

Some Theory of Computation Exercises Week 1

Finite Automata. Informatics 2A: Lecture 3. John Longley. 22 September School of Informatics University of Edinburgh

Intermediate Math Circles Wednesday 17 October 2012 Geometry II: Side Lengths

Closure Properties of Regular Languages

CS 311 Homework 3 due 16:30, Thursday, 14 th October 2010

Finite-State Automata: Recap

Section 1.3 Triangles

GNFA GNFA GNFA GNFA GNFA

Formal languages, automata, and theory of computation

Solutions for HW9. Bipartite: put the red vertices in V 1 and the black in V 2. Not bipartite!

System Validation (IN4387) November 2, 2012, 14:00-17:00

Theory of Computation Regular Languages. (NTU EE) Regular Languages Fall / 38

CS241 Week 6 Tutorial Solutions

Petri Nets. Rebecca Albrecht. Seminar: Automata Theory Chair of Software Engeneering

State Complexity of Union and Intersection of Binary Suffix-Free Languages

CS 310 (sec 20) - Winter Final Exam (solutions) SOLUTIONS

PYTHAGORAS THEOREM WHAT S IN CHAPTER 1? IN THIS CHAPTER YOU WILL:

3 Regular expressions

1 From NFA to regular expression

Theory of Computation Regular Languages

CS 491G Combinatorial Optimization Lecture Notes

Languages & Automata

THEORY OF FORMAL LANGUAGES EXERCISE BOOK. A Suite of Exercises with Solutions DRAFT COPY

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER LANGUAGES AND COMPUTATION ANSWERS

Data Structures and Algorithm. Xiaoqing Zheng

Chapter 1, Part 1. Regular Languages. CSC527, Chapter 1, Part 1 c 2012 Mitsunori Ogihara 1

Transcription:

4 Finite Automt CHAPTER 2 Finite Automt (FA) (i) Derterministi Finite Automt (DFA) A DFA, M Q, q,, F, Where, Q = set of sttes (finite) q Q = the strt/initil stte = input lphet (finite) (use only those symols whih rete prtiulr string) F Q = the set of finl stte (Finl stte n e (no finl stte) or more thn or it n hve ll sttes s finl sttes. = trnsition funtion (responsile for mking the trnsition/movement from one stte to other stte If mhine hlt t ny finl stte tht mens it is epting tht string nd if it hlts t ny other stte it simply rejets the string. Note: Behviour of the mhine is ontrolled y responsle for swithing of stte from one to other stte. : Q Q where, Q = input stte, = input lphet e.g. q i, q j where, q i = stte, = reding nd q j = move to other stte Note: Deterministi (extly www.reerendevour.om one hoie) (If you re t stte of red the input then fter tht you hve to do the movement) Totl : On every stte we need to define the trnsition for every symol of input lphet i.e. we need to explin expliitly tht where you wnt go fter reding input. Nottions: (i) Stte : q i (ii) Initil stte : q (iii) Finl stte : q s whenever, initil stte eomes finl stte, null string is epted. Note: (i) * q * 2 3,,,,... (ii) q i Therefore, totl q Therefore,, 2, 3,... (iii) q,, *,,, 2, 2,,... (universl lnguge)

Finite Automt 5 (iv) q, q i, 2 2,,,,,,... (v) q (not finl, so n t ept ()) q i (vi) q q (vii) 2 n L n n L n is even # n L n mod 2 q q i All the lnguge re sme 2 4 6 8 L,,,,... 2n L n n 3 5 7 L n is odd # L,,,,... n L n mod 2 Although given FA orresponds to only one lnguge, given lnguge n hve mny FAs tht ept it. Note tht you must lwys e reful out the empty string: should the FA ept or not. In the preeding exmple, the empty string is epted euse the strt stte is lso n ept stte. Another useful tehnique is rememering speifi symols. In the next exmple you must forever rememer the first symol; so the FA splits into two piees fter the first symol. www.reerendevour.om

6 Finite Automt SOLVED PROBLEMS. Construt the DFA for the following m n * * (i) L m, n n (ii) L n nd n 4 n (iii) L n mod 5 2 (iv) L w * w mod 7 (i) q 2 3,,,... Therefore, q 2 3,,,..., 2, 2 2, 2... q i Therefore, q q i (Totl onept follow, we need to define eh nd every stte expliity in DFA). n (ii) L n nd n 4 2 3 5 6,,,,,,... q q q q 4 q 5 Therefore, 5 finl stte, non-finl stte n (iii) mod 5 2 L n,, 2,3, 4 Therefore, totl 5 sttes., www.reerendevour.om q q (iv) L w * w mod 7 m w n mod 7 q 4 w n,, 2,3, 4,5,6 Totl 7 sttes

Finite Automt q q q 4 q 5 7 2. L2 m n p m, n, p q 6 q q,, 3. Design DFA for the following lnguge: (Set of ll inry strings whih strts with ) w w, * Temp,, q q q 4,, 4. Design DFA tht ends with www.reerendevour.om q q q 5 q 4 5. Design DFA for the following over, (i) The set of ll strings ontining extly 3 s. q q Trp (,)

8 (ii) Atlest 3 s: (iii) Atmost 3 s:, q q, q q (,) Finite Automt Trp (4th ) Trnsition tle/tulr : It is mtrix tht lists the new stte given the urrent stte nd the symol red. Exmple : Trnsition tle for the FA tht epts ll inry strings tht egin nd end with the sme symol. Input S A C A A B B A B Stte C D D D C C q q q q q q q q 2 3 q q q 2 4 q q q 3 2 q q q 4 3 4 q 4 Exmple: The smllest DFA epts the lnguge L = * q, q, x,, length of n is multiple of 3. www.reerendevour.om, () 2 () 3 () 4 (d) 5 () Exmple: Consider the mhine M [GATE-22] [GATE-25] The lnguge reognized y ove mhine is: () * w, / every in w, is followed y extly two 's () * w, every in w, is followed y t lest two 's () * w, w ontins the sustring '',

Finite Automt (d) * w, w does not ontin '' s sustring () Comining the mhines: 9 M M 2 L omplement of FSM I = the mhine of lnguge L is given O = the mhine of lnguge L Steps: L L 2 (i) Mke the finl sttes to non-finl sttes nd (ii) Non-finl sttes to finl sttes (Finl non-finl) Prolem: Design DFA whih epts the set of ll inry string whih does not strts with. q q q 4 (, ) Temp, q q q 4 (, ) www.reerendevour.om q 5, * Prolem: Design DFA for L w N w w, is even AND N is even A B C D L L L L2 m n A B ; C C. Therefore, BC Here, first we will hek tht on A stte, s we red we move to B on C stte, s we red we move to C. Therefore, AC stte omplex move to BC stte.

2 Finite Automt A A ; C D B B B A D C C C B B B A D C D D AC AD BC BD A A A B D C D B If L mhine hve m stte nd L 2 mhine hve n stte, then the omined mhine L m n stte. If the OR opertion is pplied then * L w, N w is even OR N w is even L 2 h v e A L B C L 2 Therefore, the numer of finl sttes will hnge. As here, A nd C re finl stte, so where the A nd C ome, it will eome finl stte D AC AD BC L L w w L nd w L 2 2 BD www.reerendevour.om So, L is finl nd L 2 is non finl > L nd L 2 L L BC will e finl. If 2 L L L L L L 2 2 2 L L = AD nd BC oth will e finl sttes. 2 Non-Deterministi Finite Automt (NFA) A mhine, M Q, q,, F, Where, q Q = the set of sttes (finite) Q = initil/strting stte = input lphet (finite)

Finite Automt F Q = finl stte is the suset of Q = trnsition funtion responsile for moving the movement from one stte to nother stte. DFA Q Q totl in this null trnsition is not llowed. Q 2 Q power set of Q NFA Q Power of set Q, 2 PQ, q, q, q, q Q q,q In NFA we hve zero () hoie, one hoie, or more thn one hoie depending upon the sttes, so it is lled non-deterministi. Trnsition in NFA : 2 q j q j q i q k q i q k e.g. q q For * * e.g. q q Also for * * Note: If in DFA, ll the sttes re finl sttes, then lnguge is onsidered s universl lnguge. *, lnguge (like **). *. But, in NFA, if ll the sttes re finl sttes then it is not neessry tht it is universl Design NFA for ***: () q q q (2) OR q q q www.reerendevour.om q q q In NFA, trp stte is not onsidered euse if trnsition is not defined for prtiulr I/P symol or stte, then given string is rejeted utomtilly through the mhine i.e. hek for. e.g. q q f The mhine rejets. or q q f Prolem: Design n NFA over, epting the set of ll inry strings ending with., q q q f Here, we need not to think out other trnsitions. q k

22 e.g. Finite Automt, Strt with q q q f, Contining s sustrings, q q q f 4th symol from the eginning is., q q, q f,,, Minimum numer of sttes y NFA is n 4th symol from the ending is. (Minimum sttes), q q q, 2 q q f, 3, Prolem: Design NFA over, epting the set of ll inry strings whih strt nd end with different symol., q q q 4, www.reerendevour.om Note: We n onstrut the sme NFA through more thn one mhine, ut we pply the shortest sttes NFA. Prolem: Define NFA tht epts ll inry strings where the lst symol is or whih ontin only s? Here is one: A B C D, * Prolem: Define NFA for *,

Finite Automt 23 Conversion of NFA to DFA:. Eh stte is given y set of sttes from the originl. 2. Strt stte is leled{q } where q ws originl strt stte. 3. While (some stte of DFA is missing trnsition) do: Compute the trnsition y omining the possiilities for eh symol in the set. 4. Mke into ept stte ny set tht ontins t lest one originl ept stte. The following DFA is the result of pplying the preeding lgorithm to the NFA in figure elow. B A D,, C For exmple, onsider the stte {A, B, D}. On, the NFA, if in stte A, n go to sttes A or C, if in stte B dies, nd if in stte D stys in stte D. Thus, on the DFA goes from {A, B, D} to {A, C, D}. Both of these re ept sttes euse they ontin D. AB ABD A www.reerendevour.om AC If there re -trnsitions, then you hve to djust the proess slightly. Do the following: (i) The strt stte eomes the old strt stte nd every stte rehle from there y -trnsitions. (ii) When one lultes the sttes rehle from stte, one inludes ll sttes rehle y -trnsitions fter the destintion stte. This is the result of pplying the preeding lgorithm to the NFA given in figure elow. ACD A B C D, The strt stte onsists of A nd the two sttes you n reh y trnsitions, the stte is thus {A, B, C}

24 Finite Automt ABC CD AC C Finite Automt with Output pility: There re two mhine doesn t hve finl sttus. These oth mhines hve the output pity. Mely Mhine: A mely mhine, M is 6 tuple system M Q,q,,,, ' Where, Q = the set of sttes (finite) q Q = initil/strt stte = input lphet, = output lphet, = trnsition funtion responsile for mking the movement/trnsition from one stte to nother stte. ' = output funtion resonsile for produing n output orresponding to every trnsition. Note: In mely mhine for eh is trnsition the output will e generted. Q Q totl orresponding the every trnsition, there is n output ' Q Prolem: Design mely mhine whih find the omplement of inry string. If input is the output/input is nd vie vers. / q / Prolem: Design mely mhine whih inrements the given inry numer y Assume, reding of symols should e from right to left. (/) www.reerendevour.om / q q (, ) / / / OR q q / (/)

Finite Automt 25 Prolem: Design mely mhine to dd two inry numer A B Ssum Crry Moore Mhine: A moore mhine, / / / / / No / rry rry / M Q,q,,,, ' Output pility Different from mely mhine in only wy tht they produe the output All omponents re similr like mely mhine Input = string Output = string Contin those set of terminls from whih the output string n e mde So, it my e possile tht (input string is sme s output string) In se of mely mhine, there is n output orresponding to every trnsition ' Q But in se of Moore mhine, there is n output orresponding to every stte ': Q Prolem: Design Moore mhine tht ount the ourene of in inry string. (Numer of times is ville in the string). (It will not ounted seond time) / So, now we will ount the numer of s Therefore, 2(2 times ome) www.reerendevour.om q/ q/ q/ 2 q/ 3 Mely Mhine: Input string w w n then output string = n Moore Mine: Input string w w n then output string n Prolem: Design Moore mhine whih finds the reminder of deiml representtion of inry numer when divided y 3. Reminder,, 2,... inry

26 Finite Automt q/ q/ q/2 2 Note: Mely mhine nd Moore mhines re eqully powerful. Moore to Mely mhine (Conversion): (Moore) (Mely) / q / / 2 2 2/ q 2 Note: We need to tth the prtiulr stte output to every trnsitin whih is oming to it. Exmple: q / q / / / (Moore) / / / / q / q / q 2/ q 3/ / / / (Mely) / Mely to Moore (Conversion): www.reerendevour.om / (Mely mhine) (Mely mhine) / q i / q i/ / / When there re two different output, we need to split the stte into two, s there re two output. When ll the inoming trnsition output re sme then we need not to split the stte, we just simply put tht trnsition output into the stte output. q / i /

Finite Automt Exmple: 27 / q i / (Mely) q i/ / / / (Need to onnet oth the sttes) Exmple: q / (Mely) / q q / i / / Deision Properties: () Finiteness/Infiniteness (2) Emptyness/non-emptyness (3) Equlness / www.reerendevour.om q/ (Mely). Finiteness / Infiniteness: The steps to hek the ondition re s follows: () Selet the stte whih n t e rehed y the initil stte nd delete them. () Selet those sttes from whih we n t reh to finl stte nd delete them. () If the resulting mhine is free from yles nd self loops then the mhine epts finite lnguge else the mhine epts infinite lnguge. Exmple: q q, q 4 ontins yle so epts infinite lnguge. Exmple: q/ q/ q q, q q q q q 4 No yle or self loop so ept finite lnguge

28 Finite Automt 2. Emptyness/non-emptyness: The steps to hek the ondition is given elow () Selet the stte whih n t e rehed from the initil stte nd delete them. () If the resulting mhine is free from finl stte then it will ept empty lnguge otherwise non-empty lnguge Exmple: q q, The mhine doesn t ontin finl stte so epts empty lnguge. Exmple: q q q q q q,,, The mhine ontins finl stte so epts non-empty lnguge. 3. Equlness: Two finite stte mhines M nd M 2 re sid to e equl if oth mhines epts sme set of strings i.e. M M2 L M L M2 Equl mhines need not to ontin sme set of sttes Two mhines M nd M 2 re sid to e isomorphi to eh other if oth of them epts sme lnguge ontins sme numer of sttes hve the sme properties. Steps to hek the equlness of two mhine is given elow: () Construt the trnsition tle tht ontins pir of initil sttes (P, Q) where, P is from mhine M nd Q is from mhine M 2. () Construt the trnsition tle () In the onstrution proess, we get ny pir of the form (finl, non-finl) or (non-finl, finl), stop onstruting the tle nd delres tht the mhines re not equl else fter ompletion of the tle if no suh ondition generted the mhines re equl. Exmple: if www.reerendevour.om M : A B 2 P Q R M : C D A, P A, P C,Q C,Q D, R A, P D,R B, R D, R B,R D,Q A,R Stte (A, R) is (finl, non-finl) so oth the mhines re not equl.

Finite Automt Minimiztion of Finite Automt: The proess of deletion nd elimintion of sttes whose presene or sene will not effet the lnguge of the mhine is lled minimiztion/optimiztion of FA. We strt with two exmples. Consider the utomton on the left: 29 2 We n see tht it is not possile to ever visit stte 2. Sttes like this re lled unrehle. We n simply remove them from the utomton without hnging its ehviour. (This will e, indeed, the first step in our minimiztion lgorithm.) In our se, fter removing stte 2, we get the utomton on the right. As it turns out, however, removing unrehle sttes is not suffiient. The next exmple is it more sutle (see the utomton on the left)., 2 2 We now formlize the ove ide. Let A e finite utomton. We will sy tht * w distinguishes etween two sttes p,q Q if either p, wf & q, w F, or p, w F & q, w F. Two sttes p,q Q re lled distinguishle iff there is word tht distinguishes etween them. Sttes tht re indistinguishle will lso e sometimes lled equivlent. Lemm-: Suppose tht B is DFA without unrehle sttes. Then B is minimum if nd only if ll pirs of sttes re distinguishle. Lemm-2: Stte indistinguishility is n equivlene reltion. Lemm-3: Let www.reerendevour.om p, p' nd q, q '. Then, if p ',q ' distinguishle then so re p, q. To minimize A, fter removing unrehle sttes, we will find the equivlene lsses of the indistinguishility reltion nd join ll sttes in eh lss into one stte of the new utomton A. To determine trnsitions, if X is n equivlene lss, we pik ny q X nd define X, Y where Y is the equivlene lss tht ontins q,. To determine whih sttes re equivlent, we will use the following method. Insted of trying to figure out whih sttes re indistinguishle, we will try to figure out whih sttes re distinguishle. Clerly, if p F nd q F then p, q re distinguishle, sine they n e distinguished y. Then we itertively exmine ll pirs of sttes. For eh pir p, q we do this. If we find symol, suh tht p,q nd q, re distinguishle, then we mrk p, q s distinguishle s well. We iterte this untill no more pirs re mrked. When we re done, the non-mrked pirs re equivlent. The omplete lgorithm is given elow.

3 Finite Automt Minimizing the Numer of Sttes of DFA: The following three sttements re equivlent:. The set L * is epted y some finite utomton. 2. L is the union of some of the equivlene lsses of right invrint equivlene reltion of finite index. 3. Let equivlene reltion R L e defined y: xr L y if nd only if for ll z in *, xz is in L extly when yz is in L. Then R L is of finite index. Myhill Nerode Theorem: Let A e ny lnguge over * we sy tht string x nd y in * re indistinguishle y A if for every string * z either oth xz nd yz re in A or oth : xz nd yz re not in A. If the numer of suffix of lnguges is finite (x) then Lnguge L is regulr The minimum DFA of L needs tlest k sttes. Exmple: Let L e the lnguge **. L is peted y the DFA. Consider the reltion RM defined y M. As ll sttes re rehle from the strt stte, R M hs six equivlene lsses, whih re * C, C *, C *, C ** C *, C ** * L is the union of three of these lsses, C, C d nd C e. The reltion R L for L hs xr L y, if nd only if either (i) x nd y eh hve no s. d e f Strt e d f, www.reerendevour.om M DFA M epting L. C C C C 2 C d C C =C 3 f C e Digrm showing R is refinement of R. L (ii) x nd y eh hve one, or (iii) x nd y eh hve more thn one. For exmple, if x = nd y =, then xz is in L if nd only if z is n *. But yz is in L under extly the sme onditions. As nother exmple, if x = nd y =, then we might hoose z = to show tht xr L y is flse. Tht is, xz = is in L, ut yz = is not. We my denote the three equivlene lsses of R L y C = *, C 2 = **, nd C 3 = **(+)*. L is the lnguge onsisting of only one of these lsses, C 2. The reltionship of C,..., C f to C, C 2, nd C 3 * is illustrted, in figure. For exmple C C * * C. From RL we my onstrut DFA s follows. Pik representtives for C, C 2 nd C 3, sy, nd. Then let M ' e the DFA shown in figure. For exmple, ', [] is C ), sy i j, then w is i j, whih is lso in C = **., sine if w is ny string in () (note

Finite Automt Minimiztion Algorithm: Step-I: Remove unrehle sttes. Step-II: Mrk the distinguishle pirs of sttes. To hieve this tsk, we first mrk ll pirs p, q where p F nd q F s distinguishle. Then, we proeed s follows. repet for ll non-mrked pirs p, q do for eh letter do then mrk p, q untill no new pirs re mrked. if the pir p,, q, is mrked. Step-III: Construt the redued utomton Â. We first determine the equivlene lsses of the indistinguishility reltion. For eh stte q, the equivlene lss of q onsists of ll sttes p for whih the pir p, q is not mrked in Step-II. The sttes of  re the equivlene lsses. The initil stte ˆq is this equivlene lss tht ontins q. The finl sttes ˆF re these equivlene lsses tht onsist of finl sttes of A. The trnsition funtion ˆ is defined s follows. To determine ˆ X,, for some equivlene lss X, pik ny q X Y is the equivlene lss tht ontins q,. Exmple of minimiztion of DFA: nd set ˆ X, 3 Y, B,, AE, A C, AD www.reerendevour.om Step-: Unrehle sttes in ove digrm: F nd G re unrehle sttes, So, we will remove them. So, now the DFA will look like F G B,, A C, AD, AE Step-2: Now, we will proeed to TABLE FILLING PROCESS Note: Vertilly we will red B, C, D, E (not A (first element) Horizontlly we will red A, B, C, D (not E element) So, in this tle we will fill those sttes with x (ross-mrks) whih re distinguishle

32 Finite Automt B C D E A B C D (Here, E nd A re distinguishle, so, we hve to put x ross-mrk in there ommon ox). Similrly, in others. Now, the trnsition funtion is onsidered to find out nother wy of distinguishle stte nd it helps to fill the remining prtiulr stte in the tle. So, A, C, B Distinguishle stte D A, C Distinguishle stte C, D A, B Distinguishle stte B, D A, B Distinguishle stte B, D B C D Non-distinguishle stte B, D Distinguishle stte C, D E A B C D D, E Distinguishle stte E, E D, E Distinguishle stte E, E www.reerendevour.om As in the ove tle, we will merge B nd C nd D nd E euse they oth re the non-distinguishle stte. A BC D,E,, (Minimised DFA) Lnguge epting this : e.g. 2 2 2 2,, -NFA NFA with moves :, L / * The NFA whih hs trnsition even for empty string is lled NFA. It is 5 tuple system Q,q,,, F everything is similr to NFA exept the trnsition funtion whih is given s : Q 2 Q

Finite Automt Cpility of NFA is sme s NFA nd DFA. NFA provide progrmming onviniene. 33 e.g. q q Convert NFA with λ trnsition into its equivlent DFA: -lousere q : q q (NFA) The set of ll sttes rehle from q y tking trnsitions inluding q -losure q q,q,q 2 -losure q q,q -losure q 2 q 2 2 Firstly: We will onsider q s the initil stte of n equivlent DFA i.e. q,q,q 2 Now, we need to tell ll the trnsitions,, with respet to initil stte of -losure q If we red t q : q,q,q, -losure q, -losure q, -louser q, 2 2 If we red t q then -losure q -losure -losure q, q, q 2 q,q,q, -louser q, -louser q, -louser q, 2 2 -louser -louser q -louser q, q If we red then t -louser q 2 www.reerendevour.om q,q,q, -louser q q 2 2 2 Now, we red for q,q -louser q, trp stte 2 Red for q,q red 2 2 q,q, -louser q q,q 2 2 q,q, losureq q 2 2 2 Red t -louser red red q, trp stte 2 q, trp stte 2 initil stte.

34 q, -losuer q q 2 2 2 Finite Automt,, q, q, q 2 q, q2 trp, [Equivlent DFA with trnsitions] www.reerendevour.om

Finite Automt SOLVED PROBLEMS 35. Stte True or Flse with one line explntion. A FSM (Finite Stte Mhine) n e designed to dd two integers of ny ritrry length (ritrry numer of digits). [GATE-994] FALSE, A FSM (Finite Stte Mhine) n t e desgined to dd two integers of ny ritrry length euse FSM hve finite memory nd n t store integer of ny ritrry length. 2. A finite stte mhine with the follows stte tle hs single input X nd single output Z. Ans. present stte next stte, z next stte, z x x A D, B, B B, C, C B, D, D B, C, It the initil stte is unknown, then the shortest input sequene to reh the finl stte C is () () () (d) () The stte digrm whih represents the given stte tle is [GATE-995] / / A B / / / / / D C / From stte A to reh C, the shortest sequene is A B C A D C From B to reh C B C B B C From C to reh C C D C C B C From D to reh C D C D B C www.reerendevour.om So is the shortest input sequene to reh the finl stte C, whtever e the initil stte.

36 3. Whih of the following set n e reognized y Deterministi Finite stte Automton? () The numers, 2, 4, 8,... 2 n,... written in inry () The numers, 2, 4,... 2 n,... written in unry () The set of inry string in whih the numer of zeros is the sme s the numer of ones (d) The set {,,,,...} Ans. () The numers, 2, 4, 8,..., 2 n... re represented y,,,,... The pttern in the regulr expression is followed y s. The regulr expression for ove is * The DFA for ove lnguge is q q Finite Automt [GATE-998], So the numers, 2, 4, 8,..., 2 n... written in inry n e reognized y deterministi finite stte utomton. 4. Let L e the set of ll inry strings whose lst two symols re the sme. The numer of sttes in the minimum stte deterministi finite stte utomton epting L is () 2 () 5 () 8 (d) 3 [GATE-998] Ans. () The numer of sttes in the minimum stte deterministi finite stte utomton epting ll inry strings whose lst two symols re the sme is 5. B C A www.reerendevour.om D 5. Consider the regulr expression ( + ) ( + )...n times. The minimum stte finite utomton tht reognizes the lnguge represented y this regulr expression ontins () n sttes () n + sttes () n + 2 sttes (d) None of these [GATE-999] Ans. () The minimum stte finite utomton tht reognizes the lnguge represent y regulr expression ( + ) ( + )... n times is n +. The lnguge ontins strings with extly length n. (n + ) sttes re required to ount length upto n. No trp stte is required sine we re mking miniml FA, not miniml DFA. For exmple, for n = 2 the design is shown elow. q, q, E

Finite Automt 37 6. Given n ritrry non-deterministi finite utomton (NFA) with N sttes, the mximum numer of sttes in n equivlent minimized DFA is t lest [GATE-2] () N 2 () 2 N () 2N (d) N! Ans. () For n ritrry NFA with N sttes, the mximum numer of sttes in n equivlent minimized DFA is 2 N. 7. Consider DFA over {, } epting ll strings whih hve numer of s divisile y 6 nd numer of s divisile y 8. Wht is the mximum numer of sttes tht the DFA will hve? [GATE-2] () 8 () 4 () 5 (d) 48 Ans. (d) A DFA over = {, } epting ll strings whih hve numer of s divisile y 6 nd numer of s divisile y 8 is grid mhine (produt utomt) hving 6 8 = 48 sttes. 8. The finite stte mhine desried y the following stte digrm with A s strting stte, where n r lel is x/y nd x stnds for -it input nd y stnds for 2-it output / A B C / / / / / Ans. () Outputs the sum of the present nd the previous its of the input () Outputs whenever the input sequene ontins () Outputs whenever the input sequene ontins (d) None of the ove [GATE-22] () The stte digrm represents the FSM whih outputs the sum of the present nd previous its of the input. Stte A represents lst it nd B nd C represents lst it is. 9. The smllest finite utomton whih epts the lnguge L = {x length of x is divisile y 3} hs () 2 sttes () 3 sttes () 4 sttes (d) 5 sttes [GATE-22] Ans. () The miniml finite utomton www.reerendevour.om with 3 sttes whih epts the lnguge L = {x length of x is divisile y 3} is s follows: q,, q,. Consider the following deterministi finite stte utomton M., Let S denote the set of seven it inry strings in whih the first, the fourth, nd the lst its re. The numer of strings in S tht re epted y M is () () 5 () 7 (d) 8 [GATE-23]

38 Ans. () The given it pttern n e represented s: Finite Automt The four lnks n e filled in 2 4 = 6 wys. Therefore there re 6 suh strings in this pttern. Not ll of these re epted y the mhine. The strings nd its eptne is given elow: epted Only these seven strings given ove re epted. The other strings (9 of them) in this pttern re rejeted, sine they dont rehed the finl stte.. Consider the NFA M shown elow: q, Ans., Let the lnguge epted y M e L. Let L e the lnguge epted y the NFA M, otined y hnging the epting stte of M to non-epting stte nd y hnging the non epting stte of M to epting sttes. Whih of the following sttements is true? [GATE-23] () L {,}* L () L {,}* () L L (d) L L () The given mhine M is www.reerendevour.om q, q, Now the omplementry mhine M is q,, q

Finite Automt In the se of DFA, L(M) L(M) ut in the se of NFA this is not true. In ft L(M) nd L(M) hve no onnetion. To find L L(M) we hve to look t M nd diretly find its lnguges. L L(M) ( ) ( )*... ( )*... ( )*. 2. Let M (K,,, s, F) e finite stte utomton, where K {A, B}, {, }, s A, F {B}, (A, ) A, (A, ) B, (B, ) B nd (B, ) A nd (B, ) A A grmmr to generte the lnguge epted y M n e speified s G (V,, R, S), where V K, nd S A. Whih one of the following set of rules will mke L(G) () {A B, A A, B A, B A, B ) () {A A, A B, B B, B A, B ) () {A B, A B, B A, B A, B ) (d) {A A, A A, B B, B A, A ) Ans. () (A, ) A, A A (A, ) B, A B (B, ) B, B B (B, ) A, B A B is finl stte, so B. L(M)? 39 [GATE-24] 3. The following finite stte mhine epts ll those inry strings in whih the numer of s nd s re respetively. www.reerendevour.om () divisile y 3 nd 2 () odd nd even () even nd odd (d) divisile y 2 nd 3 [GATE-24] Ans. () The given finite stte mhine epts ny string w (, )* in whih the numer of s is multiple of 3 nd the numer of s is multiple of 2. 4. Consider the non-deterministi finite utomton (NFA) shown in the figure. Y X Z

4 Ans. Finite Automt Stte X is the strting stte of the utomton. Let the lnguge epted y the NFA with Y s the only epting stte e L. Similrly, let the lnguge epted y the NFA with Z s the only epting stte e L2. Whih of the following sttements out L nd L2 is TRUE? () L L2 () L L2 () L2 L (d) None of these [IT-25] () Writing Y nd Z interms of inoming rrows (Arden s method), we get Y X Y Z Z X Z Y Clerly, Y = Z. 5. Consider the mhine M Ans., The lnguge reognized y M is () {w {, }* every in w is followed y extly two s} () {w {, }* every in w is followed y t lest two s} () {w {, }* w ontins the sustring (d) {w {, }* w does not ontin s sustring} [GATE-25] () () is flse, sine M is epting. () is true () is flse, sine ontins s sustring, ut is eing rejeted y the mhine. (d) is flse, sine does not ontin s sustring, ut is eing rejeted y M. 6. The following digrm represents finite stte mhine whih tkes s input inry numer from the lest signifint it www.reerendevour.om / / / / Ans. Q Q Whih one of the following is TRUE? () It omputes s omplement of the input numer () It omputes 2 s omplement of the input numer () It inrements the input numer (d) It derements the input numer () / / / / Q Q The given mhine, exeutes the lgorithm for 2 s omplement when input is given from LSB. [GATE-25]

Finite Automt 7. In the utomton elow, s is the strt stte nd t is the only finl stte. 4 s t Ans. Consider the strings u =, v = nd w =. Whih of the following sttements is true? () The utomton epts u nd v ut not w () The utomton epts eh of u, v, nd w () The utomton rejets eh of u, v, nd w (d) The utomton epts u ut rejets v nd w [IT-26] (d) u = : Aepted y utomt. v = : Not epted y utomt w = : Not epted y utomt. 8. A minimum stte determinsiti finite utomton epting the lnguge L {w w (, )*, numer of s nd s in w re divisile y 3 nd 5, respetively} hs [GATE-27] () 5 sttes () sttes () sttes (d) 9 sttes Ans. () L {w s {,} * numer if s nd s in w re divisile y 3 nd 5 respetively}. The minimum stte deterministi finite utomton epting the lnguge L hs 3 5 5 sttes. q q 4 q 5 q 6 q 7 www.reerendevour.om q 8 q 9 X q X q X 2 q X 3 q 4 Common Dt for Q. 9 nd Q. 2: Consider the following Finite Stte Automton q X q 5 q q q 2 9. The lnguge epted y this utomton is given y the regulr expression () **** () ( )* () * ( )* (d) *** [GATE-27]

42 Ans. () Finite Automt q q q 2 is unrehle from strting stte nd hene n e deleted to give the following digrm: q q q is the initil stte. From q to q the regulr expression is *. After tht, every omintion of nd is epted y q or. So q nd together n e ollpsed into permnent ept stte nd now the digrm eomes., r * ( )* q q 2. The minimum stte utomton equivlent to the ove FSA hs the following numer of sttes () () 2 () 3 (d) 4 [GATE-27] Ans. () The minimum stte FSA is given elow for the regulr expression *( + )* So FSA ontins minimum two sttes q nd q. 2. Consider the following DFA in whih s is the stte nd s, s 3 nd the finl sttes. www.reerendevour.om x x S S S 2 y y x y y x S 3 Wht lnguge does this DFA reognize? () All strings of x nd y () All strings of x nd y whih hve either even numer of x nd even numer of x nd odd numer of y () All strings of x nd y whih hve equl numer of x nd y (d) All strings of x nd y with either even numer of x nd odd numer of y or odd numer of x nd even numer of y [IT-27]

Finite Automt 43 Ans. (d) Given DFA n e redesigned s S s q, S s q, S2 s q, S3 s q. Eh stte is q [ = n mod2, = n mod2]. q s n mod 2 =, n mod 2 = [numer of x is even, numer of y is even]. x q x q y y y y x q q x q is finl stte men where numer of x is even nd numer of y is odd. q is finl stte men where numer of x is odd nd numer of y is even. 22. Consider the following finite utomt P nd Q over the lphet {,, }. The strt sttes re indited y doule rrow nd finl sttes re indited y doule irle. Let the lnguges reognized y them e denoted y L(P) nd L(Q) respetively. P p p p 2 p 3 Q q q The utomton whih reognizes the lnguges L(P) L(Q) is: () www.reerendevour.om r r r 2 r 3 () r r r 2 r 3 () r r r 2 r 3

44 Finite Automt (d) r r r 2 r 3 (e) None of the ove [IT-27] Ans. () L(P) L(Q) must ontin ll strings ommon to P nd Q. Note tht is ommon to oth P nd Q nd hene must e epted y ny FA epting L(P) L(Q). However, ll of the given mhine rejet. Therefore option (e) i.e. none of these is the right nswer. Common Dt for Q. 23, Q.24 nd Q. 25: Consider the regulr expression: R ( )* ( ) ( )* 23. Whih of the following non-deterministi finite utomt reognizes the lnguge defined y the regulr expression R? Edges leled denote trnsitions on the empty string., S, S () S S 2 S 3, () S S 2, S 3,, S S Ans. () S S 2 S 3 www.reerendevour.om, (d) [IT-27] () The lnguge of the given regulr expression R is ontining the sustring or. Option () is the orret mhine for this lnguge. 24. Whih deterministi finite utomton epts the lnguge represented y the regulr expression R? S S 2, S 3 S S 3 () S S 2 S 4

Finite Automt 45 () S S S 2 S 3 S 4 S S S S 3, S S 3, () (d) S 2 S 2 Ans. [IT-27] () In option () S3 nd S4 together t s permnent ept nd n therefore e ollpsed into single permnent ept stte s shown elow: S, S S 3, S 2 This mhine lerly epts ll strings ontining the sustrings or, whih is sme s regulr expression R. 25. Whih one of the regulr expressions given elow defines the sme lnguge s defined y the regulr expression R? Ans. + () (()* ()*) ( ) () (()* ()*)*( )* www.reerendevour.om () (()*( ) ()*( )) ( )* + (d) (()*( ) ()*( )) ( ) () R = ( + )*( + ) ( + )* hs following equivlent DFA q, [IT-27] q q3 q2