Worked out examples Finite Automata

Similar documents
AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

Let's start with an example:

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

Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Kleene-*

Deterministic Finite Automata

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

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

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

Finite Automata-cont d

Lecture 08: Feb. 08, 2019

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

Some Theory of Computation Exercises Week 1

Non-Deterministic Finite Automata. Fall 2018 Costas Busch - RPI 1

Languages & Automata

Non Deterministic Automata. Linz: Nondeterministic Finite Accepters, page 51

a,b a 1 a 2 a 3 a,b 1 a,b a,b 2 3 a,b a,b a 2 a,b CS Determinisitic Finite Automata 1

Homework 3 Solutions

Java II Finite Automata I

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

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

input tape head moves current state

First Midterm Examination

Theory of Computation Regular Languages

Minimal DFA. minimal DFA for L starting from any other

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

Designing finite automata II

Non-deterministic Finite Automata

CS375: Logic and Theory of Computing

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

First Midterm Examination

80 CHAPTER 2. DFA S, NFA S, REGULAR LANGUAGES. 2.6 Finite State Automata With Output: Transducers

Non-Deterministic Finite Automata

CMSC 330: Organization of Programming Languages

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

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

Formal Languages and Automata

Non-deterministic Finite Automata

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

Lexical Analysis Finite Automate

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.

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

Harvard University Computer Science 121 Midterm October 23, 2012

Nondeterminism. Nondeterministic Finite Automata. Example: Moves on a Chessboard. Nondeterminism (2) Example: Chessboard (2) Formal NFA

CISC 4090 Theory of Computation

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

1 From NFA to regular expression

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

Fundamentals of Computer Science

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

Chapter 2 Finite Automata

CSCI 340: Computational Models. Transition Graphs. Department of Computer Science

Nondeterminism and Nodeterministic Automata

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

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

Convert the NFA into DFA

GNFA GNFA GNFA GNFA GNFA

Non Deterministic Automata. Formal Languages and Automata - Yonsei CS 1

Normal Forms for Context-free Grammars

Formal Language and Automata Theory (CS21004)

Thoery of Automata CS402

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

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

Finite-State Automata: Recap

3 Regular expressions

Finite Automata. Informatics 2A: Lecture 3. Mary Cryan. 21 September School of Informatics University of Edinburgh

Formal languages, automata, and theory of computation

Section: Other Models of Turing Machines. Definition: Two automata are equivalent if they accept the same language.

State Minimization for DFAs

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

Anatomy of a Deterministic Finite Automaton. Deterministic Finite Automata. A machine so simple that you can understand it in less than one minute

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

Exercises Chapter 1. Exercise 1.1. Let Σ be an alphabet. Prove wv = w + v for all strings w and v.

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

CHAPTER 1 Regular Languages. Contents

CS:4330 Theory of Computation Spring Regular Languages. Equivalences between Finite automata and REs. Haniel Barbosa

FABER Formal Languages, Automata and Models of Computation

CS 330 Formal Methods and Models

Lexical Analysis Part III

Myhill-Nerode Theorem

CS375: Logic and Theory of Computing

Coalgebra, Lecture 15: Equations for Deterministic Automata

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

Homework 4. 0 ε 0. (00) ε 0 ε 0 (00) (11) CS 341: Foundations of Computer Science II Prof. Marvin Nakayama

CS 330 Formal Methods and Models

1 Nondeterministic Finite Automata

Automata Theory 101. Introduction. Outline. Introduction Finite Automata Regular Expressions ω-automata. Ralf Huuck.

NON-DETERMINISTIC FSA

Deterministic Finite-State Automata

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.

Today s Topics Automata and Languages

Automata and Languages

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.

12.1 Nondeterminism Nondeterministic Finite Automata. a a b ε. CS125 Lecture 12 Fall 2016

Speech Recognition Lecture 2: Finite Automata and Finite-State Transducers

Name Ima Sample ASU ID

In-depth introduction to main models, concepts of theory of computation:

Midterm 1 Practice. CS 350 Fall 2018 gilray.org/classes/fall2018/cs350/

Closure Properties of Regular Languages

Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem 2/16/15

NFAs and Regular Expressions. NFA-ε, continued. Recall. Last class: Today: Fun:

Transcription:

Worked out exmples Finite Automt Exmple Design Finite Stte Automton which reds inry string nd ccepts only those tht end with. Since we re in the topic of Non Deterministic Finite Automt (NFA), we will drw one. Q Q Q2 Stte Trnsition Tle From Stte Input Symol To Stte Q {Q, Q} Q {Q} Q {Q2} Initil Stte = Q Finl Stte = Q2 Alphet = {.} Note: There is no entry where From Stte = Q nd Input Symol = i.e., δ (Q, ) = {}; It is null stte Note: In the lst two entries, though the next stte or to stte is single nd not set, the convention is to represent is set contining one element. Exmple 2 Convert the ove NFA to DFA We tke up the trnsition tle nd replce ech set of sttes y single new stte. In the exmple, we comine replce {Q,Q} y Q. From Stte Input Symol To Stte Q Q Q Q Q Q2 Now we need to define trnsition rules for this new stte Q.

δ (Q, ) = δ (Q, ) + δ (Q, ) = Q + Φ = Q δ (Q, ) = δ (Q, ) + δ (Q, ) = Q + Q2 = Q2 (gin new stte) Define trnsition rules for this new stte Q2. δ (Q2, ) = δ (Q, ) + δ (Q2, ) = Q + Φ = Q δ (Q2, ) = δ (Q, ) + δ (Q2, ) = Q + Φ = Q Incorporting the ove entries, the trnsition tle for the resultnt DFA is: From Stte Input Symol To Stte Q Q Q Q Q Q2 Q Q Q Q2 Q2 Q Q2 Q Some ction is still remining.. We hve to identify the finl stte. The finl stte in the NFA ws Q2. Therefore, the finl stte in the equivlent DFA will e Q2 s it contins Q2. 2. There is no trnsition from the stte Q2. Hence, Q2 ecomes redundnt. So, the finl trnsition tle ecomes: From Stte Input Symol To Stte Q Q Q Q Q Q Q Q2 Q2 Q Q2 Q

Drwing the digrm: Q Q Q2 Exmple 3 All strings over {,} tht contin t lest two s., Q Q Q2 The Regulr Expression for the mchine = **(+)* Alterntively, (+)*(+)*(+)*

Exmple 4 All strings over {,} tht do not end with. Hint: first drw the DFA for strings tht end with nd then tke complement. Refer Exmple. Then convert ech non finl stte to finl stte nd ech finl stte to non finl stte. Q Q Q2 Alterntive: Directly. This wy the numer of sttes is reduced. Q Q Exmple 5 Even numer of s nd s Hint: We give some nmes to the sttes which will reflect the nture of input rech there. Stte: e-e (mening even s, even s) This stte is reched with even numer of s even numer of s. e-e e-o o-e o-o to nd Stte: o-e (mening odd s, even s) This stte is reched with odd numer of s nd even numer of s.

Stte: o-o (mening odd s, odd s); This stte is reched with odd numer of s nd odd numer of s. Stte: e-o (mening even s, odd s); This stte is reched with even numer of s nd odd numer of s Exmple 6 n :n>=,, Trp stte Exmple 7 All strings of {,} with prefix,, Trp stte

Exmple 8 Automton over {,} ccepting ll strings not contining, Trp stte Exmple 9 Finite utomton over lphet {,} tht strt with nd ends with {w : w {,}*}, Trp stte

Exmple DFA for integers divisile y 3. Answer: Since the DFA reds integers, they will consist of digit -9. i.e., Σ = {,,2,3,4,5,6,7,8,9} Now we drw the trnsition digrm.,3,6,9,4,7,3,6,9 I,4,7 2,5,8 II,4,7,3,6,9 III 2,5,8 Note: Stte I is reched when reminder = Stte II is reched when reminder = Stte III is reched when reminder = 2

Exmple Design Mely mchine which reds nd ccepts strings over {,} nd outputs when doule occurrence of is found. Else, outputs. Answer: Σ = {,} Δ = {,} Exmple Input: Output produced: / / / / / / Exmple 2 Drw Mely mchine which ccepts {,} nd outputs for first occurrence of nd then for ech susequent nd. Answer: / / / q q2 / / / q Current Stte Input Next Stte Output q q q q2 q q q q2 q2 q q2 q2

Convert the ove to Moore mchine q/ε q/ q3/ q2/

Exmple 3 Drw NFA for (+)*((+)* + (+)*)(+)*,,,,

Exmple 4 Find deterministic finite utomton equivlent to the NFA M=({q,q,q2},{,},δ, qo,{q}) Where δ is given y Stte \ Input => q q,q q q q2 q2 q2 - q2 Answer: Consider [q,q] s new stte nd define trnsitions from the sme. You get new comined sttes [q,q,q2] nd [q,q2]. So, define trnsitions for them s well to rrive t the following: Stte \ Input q [q,q] q q q2 q2 q2 - q2 [q,q] [q,q,q2] [q,q2] [q,q2] [q2] [q2] [q,q,q2] [q,q,q2] [q,q2] Finl sttes: q, [q, q], [q, q2] nd [q, q, q2] ecuse they ll contin the previous finl stte q. Initil stte remins s q.

Exmple 5 Construct DFA equivlent to the following NFA: c q q c, q3 c q4 q2 c The trnsition tle: Stte / Input c q q,q4 q4 q2,q3 q - q4 - q2 - - q2, q3 q3 - q4 - q4 - - - Derive the trnsition functions for the new sttes [q, q4] nd [q2, q3] Stte / Input c q q,q4 q4 q2,q3 q - q4 - q2 - - q2, q3 q3 - q4 - q4 - - - q2,q3 - q4 q2,q3 q,q4 - q4 -

Note tht q2 nd q3 s seprte sttes re unrechle. So, they re removed, though present in comintion with others, viz., [q2,q3]. Therefore, the finl stte tle ecomes: Stte / Input c q q,q4 q4 q2,q3 q - q4 - q4 - - - q2,q3 - q4 q2,q3 q,q4 - q4 - Exmple 6 Otin n NFA which should ccept lnguge L, given y L = {x {, }* x >=3 nd third symol of x from the right is Answer: The conditions re () () Third symol from the right is. Symol in ny other position cn e or.,,, q q q2 q3