Homework 02 Solution updated

Similar documents
CS375 Midterm Exam Solution Set (Fall 2017)

CS 154, Lecture 3: DFA NFA, Regular Expressions

Author: Vivek Kulkarni ( )

CSE 105 THEORY OF COMPUTATION

CS 154 Formal Languages and Computability Assignment #2 Solutions

CSC236 Week 11. Larry Zhang

CpSc 421 Homework 1 Solutions

CS 322 D: Formal languages and automata theory

Sri vidya college of engineering and technology

CS 581: Introduction to the Theory of Computation! Lecture 1!

Chapter 6: NFA Applications

Chap. 1.2 NonDeterministic Finite Automata (NFA)

The One-Quarter Fraction

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata (cont )

CMSC 330: Organization of Programming Languages

CS 154. Finite Automata, Nondeterminism, Regular Expressions

Closure under the Regular Operations

PS2 - Comments. University of Virginia - cs3102: Theory of Computation Spring 2010

Lecture 3: Nondeterministic Finite Automata

Deterministic Finite Automata. Non deterministic finite automata. Non-Deterministic Finite Automata (NFA) Non-Deterministic Finite Automata (NFA)

CS243, Logic and Computation Nondeterministic finite automata

September 7, Formal Definition of a Nondeterministic Finite Automaton

Closure Properties of Regular Languages. Union, Intersection, Difference, Concatenation, Kleene Closure, Reversal, Homomorphism, Inverse Homomorphism

Fooling Sets and. Lecture 5

Nondeterminism. September 7, Nondeterminism

Non-deterministic Finite Automata (NFAs)

Regular Language Equivalence and DFA Minimization. Equivalence of Two Regular Languages DFA Minimization

Finite Automata and Regular languages

CSE 105 Theory of Computation Professor Jeanne Ferrante

Nondeterministic Finite Automata

CSCE 551 Final Exam, April 28, 2016 Answer Key

Before we show how languages can be proven not regular, first, how would we show a language is regular?

CS 455/555: Finite automata

highlights CSE 311: Foundations of Computing highlights 1 in third position from end Fall 2013 Lecture 25: Non-regularity and limits of FSMs

Nondeterminism and Epsilon Transitions

CS 530: Theory of Computation Based on Sipser (second edition): Notes on regular languages(version 1.1)

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Clarifications from last time. This Lecture. Last Lecture. CMSC 330: Organization of Programming Languages. Finite Automata.

CS 301. Lecture 18 Decidable languages. Stephen Checkoway. April 2, 2018

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata

Comment: The induction is always on some parameter, and the basis case is always an integer or set of integers.

CMSC 330: Organization of Programming Languages. Theory of Regular Expressions Finite Automata

Exam 1 CSU 390 Theory of Computation Fall 2007

Formal Definition of Computation. August 28, 2013

CSE 105 THEORY OF COMPUTATION

Fractional Replications

Nondeterministic finite automata

Theory of Computation Lecture 1. Dr. Nahla Belal

CISC 4090: Theory of Computation Chapter 1 Regular Languages. Section 1.1: Finite Automata. What is a computer? Finite automata

CS 482 Problem Set 2 Solutions Dan FitzGerald, dpf7

Geometry Chapter 3 3-6: PROVE THEOREMS ABOUT PERPENDICULAR LINES

Nondeterministic Finite Automata. Nondeterminism Subset Construction

September 11, Second Part of Regular Expressions Equivalence with Finite Aut

Nondeterministic Finite Automata

CS 121, Section 2. Week of September 16, 2013

Finite Automata. Wen-Guey Tzeng Computer Science Department National Chiao Tung University

Automata and Computability. Solutions to Exercises

CSE 311: Foundations of Computing. Lecture 23: Finite State Machine Minimization & NFAs

TAFL 1 (ECS-403) Unit- II. 2.1 Regular Expression: The Operators of Regular Expressions: Building Regular Expressions

Nondeterministic Finite Automata

Languages, regular languages, finite automata

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

(Refer Slide Time: 0:21)

CSE 105 THEORY OF COMPUTATION

Intro to Theory of Computation

Equivalence. See section 4.4 of the text

Automata & languages. A primer on the Theory of Computation. Laurent Vanbever. ETH Zürich (D-ITET) September,

Subset construction. We have defined for a DFA L(A) = {x Σ ˆδ(q 0, x) F } and for A NFA. For any NFA A we can build a DFA A D such that L(A) = L(A D )

NFA and regex. the Boolean algebra of languages. regular expressions. Informatics 1 School of Informatics, University of Edinburgh

Languages. Non deterministic finite automata with ε transitions. First there was the DFA. Finite Automata. Non-Deterministic Finite Automata (NFA)

Introduction to Language Theory and Compilation: Exercises. Session 2: Regular expressions

Let us first give some intuitive idea about a state of a system and state transitions before describing finite automata.

Introduction to the Theory of Computation. Automata 1VO + 1PS. Lecturer: Dr. Ana Sokolova.

Regular Expressions. Definitions Equivalence to Finite Automata

Extended transition function of a DFA

CS 154, Lecture 2: Finite Automata, Closure Properties Nondeterminism,

Finite Automata Part Two

Lecture 1: Finite State Automaton

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

Unit 6. Non Regular Languages The Pumping Lemma. Reading: Sipser, chapter 1

1 Showing Recognizability

Automata and Computability. Solutions to Exercises

CSE 311 Lecture 25: Relating NFAs, DFAs, and Regular Expressions. Emina Torlak and Kevin Zatloukal

Classes and conversions

T (s, xa) = T (T (s, x), a). The language recognized by M, denoted L(M), is the set of strings accepted by M. That is,

Proving languages to be nonregular

Author: Vivek Kulkarni ( )

Optimizing Finite Automata

Inf2A: Converting from NFAs to DFAs and Closure Properties

Finite-State Machines (Automata) lecture 12

Deterministic Finite Automata (DFAs)

Topics COSC Administrivia. Topics Today. Administrivia (II) Acknowledgements. Slides presented May 9th and 16th,

Finite Automata. Warren McCulloch ( ) and Walter Pitts ( )

CSE 105 THEORY OF COMPUTATION

Recap DFA,NFA, DTM. Slides by Prof. Debasis Mitra, FIT.

TDDD65 Introduction to the Theory of Computation

CISC 4090 Theory of Computation

Name: Student ID: Instructions:

Pushdown Automata. We have seen examples of context-free languages that are not regular, and hence can not be recognized by finite automata.

CSE 355 Homework One Sample Solutions

Transcription:

CS3-Automata and Complexity Theory Homework 2 Solution updated Due On: 5hrs Wednesday, December 2, 25 Max Points: 25 Problem [5+5+5+ points] Give DFA for the following languages, over the alphabet {,} a) Set of all strings containing the substring b) Set of all strings that do not contain the substring c) Set of all strings that are exactly of length 5,,,,, d) Set of all strings that are at least of length 4 and contains even number of s Note: the previous solution was also correct, except for a minor typo,,,,

Problem 2 [++2 points] Ex 2.2.5 Give DFA s accepting following languages a) Set of strings such that each block of five consecutive symbols contains at least 2 s Solution (or something like it) The complement of this language is set of all strings in which some block of 5 consecutive strings contains at most one zero. So just make an easy NFA for this, which has a start state with, loop, and then paths leading towards a final state with transition labels,,,,,. This will ensure that you reach the final state if some block of 5 doesnot contains at least two s. Now to get the DFA we want, you just need to convert the NFA into a DFA (easy) and then take its complement by changing final states into non-final states (and the order of NFA-DFA conversion and reversing is important) c) Set of strings that either begin or end (or both) with A first path starting with and then ending in sigma*(covers the case which both being and end), and then the strings that do not start with must end with., d) Set of all strings with number of s in multiples of 5 and number of s in multiple of 3 There are fifteen states, each remembers the no of s and seen. The final state is reached when we have seen 5 zeros(or multiple of 5 zeros, considering to be a multiple of every number) AND multiple of 3 s.

Problem 3 [+ points] Construct the min-nfa (an NFA with the minimum number of states) for the following languages, over the alphabet {,}. Prove that your solution is the best possible a) { n s.t. n } U { n s.t. n }, using at most 6 states There was a typo in the assignment. Instead of n= we should have n >=; (credit will be given in case of correct ans for either case. Here we give solution for non-typo version. You can make an easy NFA with two paths, one for n and another for n ; and see that you can easily combine the first two states on each path, to get a 6 state NFA(shown below). You cannot further reduce this, because, after having seen the you need to make a distinction between the that would lead you towards accepting only * or *. If you don t then your NFA may end up accepting strings like, which do not belong to the language. a b c d e f There have to be two distinct final states, one reached by and then accepts all zeros and the other reachable by and then we accept all s. So we need to distinguish between these two final states i.e. the one reached with, and. In order to distinguish between two strings of length 5 we need at least 6 states. Therefore the NFA is min. b) set of all strings s.t there are two s separated by a number of positions that is a multiple of 3 The diagram shows that five states are sufficient. The reason they are necessary is that from the start state, after seeing a, we can start counting in multiples of 3, for which we need 3 states, and then on seeing a we can move to a final state. The min acceptable string is xxx; which requires 5 states.,, a b, c, d, e f,

Problem 4 [5+5 points] Convert the NFAs of problem 3 to corresponding DFAs using Subset Construction a) start state ; + - final state {a} Φ {b} {b} {c} Φ {c} Φ {d,f} +{d,f} {e,f} Φ +{e} Φ {e} +{e,f} {f} {e} +{f} {f} Φ b) Here it is interesting to note, as was pointed out by amirali in the discussion forum, that once we reach a subset with f in it, i.e. the final state, we will never go to a non-final state. So for all subsets that contain f, we can replace this by a single sink final state. Therefore there is no need to check, transitions leaving a set that contains f. All of these are final sink states. {a} {a} {a,b} {a,b} {a,c} {a,b,c} {a,c} {a,d} {a,b,d} {a,d} {a,e} {a,b,e} {a,e} {a,c} {a,b,c,f} {a,b,c} {a,c,d} {a,b,c,d} {a,b,d} {a,c,e} {a,b,c,e} {a,b,e} {a,c} {a,b,c,f} {a,c,d} {a,d,e} {a,b,d,e} {a,c,e} {a,c,d} {a,b,e,d,f} {a,d,e} {a,c,e} {a,b,c,e,f} {a,b,c,d} {a,c,d,e} {a,b,c,d,e} {a,b,c,e} {a,c,d} {a,b,c,d,f} {a,b,d,e} {a,c,e} {a,b,c,e,f} {a,c,d,e} {a,c,d,e} {a,b,c,d,e,f} {a,b,c,d,e} {a,c,d,e} {a,b,c,d,e,f} Rest all final

Problem 5 [5 points] Ex 2.3.3 : Convert the following NFA to a DFA and informally describe the language it accepts. p {p,q} {p} q {r,s} {t} r {p,r} {t} + s Φ Φ + t Φ Φ Solution: p {p,q} {p} {p,q} {p,q,r,s} {p,t} +{p,t} {p,q} {p} +{p,q,r,s} {p,q,r,s} {p,t} This gives a language of all strings that end in either or *, i.e. it cannot end with or at the end. Problem 6 [5 points] Prove or disprove that NFAs and DFAs can be used to remember in multiples. In other words, it is possible to use these models of computation to do modulo counting for a specific mod k. We have to show that given a parameter k, we can do modulo counting. We only need a finite number of states to implement a modulo/remainder counter (we need exactly k states to count from to k- times any symbol has appeared and on the k th time we go back to count ). For a given alphabet of size say n, the number of k sized patterns can n k, which is a finite number for a given n and k. Since DFA and NFA can have a finite number of states and thus can distinguish between any pattern.