CS103 Handout 14 Winter February 8, 2013 Problem Set 5

Similar documents
CS103 Handout 13 Fall 2012 May 4, 2012 Problem Set 5

CS103 Handout 16 Winter February 15, 2013 Problem Set 6

CS103 Handout 35 Spring 2017 May 19, 2017 Problem Set 7

CS103 Handout 42 Spring 2017 May 31, 2017 Practice Final Exam 1

CS103 Handout 39 Winter 2018 February 23, 2018 Problem Set 7

Context-Free Grammars

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

CS103 Handout 50 Fall 2018 November 30, 2018 Problem Set 9

Theory of Computation Dr. Weiss Extra Practice Exam Solutions

CS2 Practical 2 CS2Ah

CS/ECE 374 Fall Homework 1. Due Tuesday, September 6, 2016 at 8pm

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

Turing Machines Part Two

Context-Free Grammars

Notebook Assignments

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

14.1 Encoding for different models of computation

CS 3512, Spring Instructor: Doug Dunham. Textbook: James L. Hein, Discrete Structures, Logic, and Computability, 3rd Ed. Jones and Barlett, 2010

CS52 - Assignment 10

CS154 Midterm Examination. May 4, 2010, 2:15-3:30PM

Homework 1 Due Tuesday, January 30, 2018 at 8pm

Midterm I - Solution CS164, Spring 2014

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

Computer Science 236 Fall Nov. 11, 2010

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

Chapter Seven: Regular Expressions

Recursively Enumerable Languages, Turing Machines, and Decidability

Problem One: A Quick Algebra Review

Limitations of Algorithmic Solvability In this Chapter we investigate the power of algorithms to solve problems Some can be solved algorithmically and

Material from Recitation 1

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

Midterm I (Solutions) CS164, Spring 2002

(Refer Slide Time: 0:19)

CS103 Spring 2018 Mathematical Vocabulary

Proofwriting Checklist

Lecture 6,

Introduction to Sets and Logic (MATH 1190)

CS525 Winter 2012 \ Class Assignment #2 Preparation

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

MC 302 GRAPH THEORY 10/1/13 Solutions to HW #2 50 points + 6 XC points

Chapter 18 out of 37 from Discrete Mathematics for Neophytes: Number Theory, Probability, Algorithms, and Other Stuff by J. M. Cargal.

Reflection in the Chomsky Hierarchy

Finite Automata Part Three

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

Notes slides from before lecture. CSE 21, Winter 2017, Section A00. Lecture 9 Notes. Class URL:

1. [5 points each] True or False. If the question is currently open, write O or Open.

Actually talking about Turing machines this time

University of Nevada, Las Vegas Computer Science 456/656 Fall 2016

CS143 Handout 20 Summer 2012 July 18 th, 2012 Practice CS143 Midterm Exam. (signed)

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Formal Methods of Software Design, Eric Hehner, segment 24 page 1 out of 5

LING/C SC/PSYC 438/538. Lecture 18 Sandiway Fong

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

To illustrate what is intended the following are three write ups by students. Diagonalization

Ambiguous Grammars and Compactification

CS70 - Lecture 6. Graphs: Coloring; Special Graphs. 1. Review of L5 2. Planar Five Color Theorem 3. Special Graphs:

Relations I. Margaret M. Fleck. 7 November 2008

Skill 1: Multiplying Polynomials

Theory Bridge Exam Example Questions Version of June 6, 2008

Ramsey s Theorem on Graphs

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

2. CONNECTIVITY Connectivity

6 NFA and Regular Expressions

CSE 21 Spring 2016 Homework 5. Instructions

Computation, Computers, and Programs. Administrivia. Resources. Course texts: Kozen: Introduction to Computability Hickey: Introduction to OCaml

In our first lecture on sets and set theory, we introduced a bunch of new symbols and terminology.

CS103 Handout 29 Winter 2018 February 9, 2018 Inductive Proofwriting Checklist

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

COMP260 Spring 2014 Notes: February 4th

Lexical Analysis. Lecture 3-4

CpSc 421 Final Solutions

Binary Relations Part One

Lecture 2 Finite Automata

To prove something about all Boolean expressions, we will need the following induction principle: Axiom 7.1 (Induction over Boolean expressions):

Chapter 3: Theory of Modular Arithmetic 1. Chapter 3: Theory of Modular Arithmetic

γ(ɛ) (a, b) (a, d) (d, a) (a, b) (c, d) (d, d) (e, e) (e, a) (e, e) (a) Draw a picture of G.

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2016

UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFR08008 INFORMATICS 2A: PROCESSING FORMAL AND NATURAL LANGUAGES

CPSC 121: Models of Computation Assignment #5

Theory of Computations Spring 2016 Practice Final Exam Solutions

3.1 Constructions with sets

1 (15 points) LexicoSort

6.080 / Great Ideas in Theoretical Computer Science Spring 2008

CS311 / MATH352 - AUTOMATA AND COMPLEXITY THEORY

Semantics via Syntax. f (4) = if define f (x) =2 x + 55.

UNCA CSCI 255 Exam 1 Spring February, This is a closed book and closed notes exam. It is to be turned in by 1:45 PM.

Finite Automata Part Three

CMSC330 Fall 2016 Midterm #2 2:00pm/3:30pm

Graph Theory Part Two

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

Algebra of Sets (Mathematics & Logic A)

CS 403 Compiler Construction Lecture 3 Lexical Analysis [Based on Chapter 1, 2, 3 of Aho2]

Sets 1. The things in a set are called the elements of it. If x is an element of the set S, we say

GRAPH THEORY: AN INTRODUCTION

COMP Logic for Computer Scientists. Lecture 25

CSE 105 THEORY OF COMPUTATION

CSE Theory of Computing Fall 2017 Project 2-Finite Automata

Mathematical Logic Part One

CS150 Assignment 7 DNA!

Ling/CSE 472: Introduction to Computational Linguistics. 4/6/15: Morphology & FST 2

Transcription:

CS103 Handout 14 Winter 2012-2013 February 8, 2013 Problem Set 5 This fifth problem set explores the regular languages, their properties, and their limits. This will be your first foray into computability theory, and I hope you find it fun and exciting! In any question that asks for a proof, you must provide a rigorous mathematical proof. You cannot draw a picture or argue by intuition. You should, at the very least, state what type of proof you are using, and (if proceeding by contradiction, contrapositive, or induction) state exactly what it is that you are trying to show. If we specify that a proof must be done a certain way, you must use that particular proof technique; otherwise you may prove the result however you wish. As always, please feel free to drop by office hours or send us emails if you have any questions. We'd be happy to help out. This problem set has 125 possible points. It is weighted at 7% of your total grade. The earlier questions serve as a warm-up for the later problems, so do be aware that the difficulty of the problems does increase over the course of this problem set. Good luck, and have fun! Due Friday, February 15 th at 12:50PM

Problem One: Constructing DFAs (24 Points) For each of the following languages over the indicated alphabets, construct a DFA that accepts precisely those strings that are in the indicated language. Your DFA does not have to have the fewest number of states possible. You should specify your DFA as either a state-transition diagram (the graphical representation we've seen in class) or as a table. We have an online tool you can use to design, test, and submit the DFAs in this problem. To use it, visit https://www.stanford.edu/class/cs103/cgi-bin/nfa/nfa.php. We strongly suggest using this tool, as it makes it easy to design, test, debug, and submit your solutions. If you submit through this system, please make a note of it in your problem set submission so that we know to look online for your answers. i. For the alphabet Σ = {0, 1, 2}, construct a DFA for the language L = { w Σ* w contains exactly two 2s. } ii. For the alphabet Σ = {0, 1}, construct a DFA for the language L = { w Σ* w contains the same number of instances of the substring 01 and the substring 10 }. Note that substrings are allowed to overlap, so 010 L and 10101 L. iii. For the alphabet Σ = {a, b, c,, z}, construct a DFA for the language L = { w Σ* w contains the word cocoa as a substring }. Remember that as a shorthand, you can specify multiple letters in a transition by using set operations on Σ (for example, Σ {a, b}) * iv. Suppose that you are taking a walk with your dog along a straight-line path. Your dog is on a leash that has length two, meaning that the distance between you and your dog can be at most two units. You and your dog start at the same position. Consider the alphabet Σ = {Y, D}. A string in Σ* can be thought of as a series of events in which either you or your dog moves forward one unit. For example, the string YYDD means that you take two steps forward, then your dog takes two steps forward. Let L = { w Σ* w describes a series of steps that ensures that you and your dog are never more than two units apart }. Construct a DFA for L. Problem Two: Constructing NFAs (20 Points) For each of the following languages over the indicated alphabets, construct an NFA that accepts precisely those strings that are in the indicated language. You should specify your NFA as either a statetransition diagram (the graphical representation we've seen in class) or as a table. Your NFA may use ε-transitions if you wish. As in Problem One, we recommend designing, testing, and submitting your automata using our online system. i. For the alphabet Σ = {0, 1, 2}, construct an NFA for the language { w Σ* w ends in 0, 11, or 222. } ii. For the alphabet Σ = {a, b, c, d, e}, construct an NFA for the language { w Σ* the last character of w appears nowhere else in the string, and w 1 } iii. For the alphabet Σ = {0, 1}, construct an NFA for the language { w Σ* w contains at least two 1's with exactly five characters between them. } For example, 1000001 is in the language, as is 00100110100 and 0111110100000001, but 11111 is not, nor are 11101 or 000101. * DFAs are often used to search large blocks of text for specific substrings, and several string searching algorithms are built on top of specially-constructed DFAs. The Knuth-Morris-Pratt and Aho-Corasick algorithms use slightly modified DFAs to find substrings extremely efficiently.

Problem Three: Designing Regular Expressions (20 Points) Below are a list of alphabets and languages over those alphabets. For each language, write a regular expression for that language. We have an online tool you can use to design, test, and submit the regular expressions in this problem. It's available online at https://www.stanford.edu/class/cs103/cgi-bin/simpleregex/edit.php. We strongly suggest using this tool, as it makes it easy to design, test, debug, and submit your solutions. If you submit through this system, please make a note of it in your problem set submission so that we know to look online for your answers. i. Let Σ = {a, b} and let L = { w Σ* w does not contain ba as a substring }. Write a regular expression for L. ii. Let Σ = {a, b} and let L = { w Σ* w contains an even number of a's }. Write a regular expression for L. iii. Suppose that you are taking a walk with your dog on a leash (as in Problem 1.iv). As in that problem, your leash has length two. Let Σ = {Y, D} and let L = { w Σ* w represents a walk with your dog on a leash where you and your dog both end up at the same location }. For example, YYDDDDYY L, because you and your dog are never more than two steps apart and both of you end up four steps ahead of where you started, and similarly DDYDYY L. However, YYYDDD L, since halfway through your walk you are three steps ahead of your dog; DDYD L, because your dog ends up two steps ahead of you; and DDYDDYYY L, because partway through your walk your dog is three steps ahead of you. Write a regular expression for L. iv. Let Σ = {a, b} and let L = { w Σ* w ab }. Write a regular expression for L. Problem Four: Finite and Cofinite Languages (16 Points) A language L is called finite iff L contains finitely many strings. More precisely, a language L is a finite language iff L is a natural number. A language L is called cofinite iff its complement is a finite language; that is, L is cofinite iff L is a natural number. i. Prove that any finite language is regular. (Hint: Use induction.) ii. Prove that any cofinite language is regular.

We will cover the material necessary to solve these next two problems in Monday's lecture. Problem Five: The Complexity of Addition (20 Points) This problem explores the question How hard is it to add two numbers? Suppose that we want to check whether x + y = z, where x, y, and z are all natural numbers. If we want to phrase this as a problem as a question of strings and languages, we will need to find some way to standardize our notation. In this problem, we will be using the unary number system, a number system in which the number n is represented by writing out n 1's. For example, the number 5 would be written as 11111, the number 7 as 1111111, and the number 12 as 111111111111. Given the alphabet Σ = {1, +, =}, we can encode x + y = z by writing out x, y, and z in unary. For example: 4 + 3 = 7 would be encoded as 111+1111=1111111 7 + 1 = 8 would be encoded as 1111111+1=11111111 0 + 1 = 1 would be encoded as +1=1 Consider the language ADD = {1 m +1 n =1 m+n m, n N }. That is, ADD consists of strings encoding two unary numbers and their sum. Prove that ADD is not a regular language. Problem Six: The Complexity of String Searching (20 Points) The problem explores the question How hard is it to search a string for a substring? A common task in computer programming is to search a string to see if some other string appears as a substring. This task arises in computational biology (searching an organism's genome for some particular DNA sequence), information storage (finding all copies of some phrase in the full text of a book), and in spam filtering (searching for some key words in an email). More formally, we can define the substring search problem as follows. The string search problem is given a string to search for (called the pattern) and a string in which the search should be conducted (called the text), to determine whether the pattern appears in the text. To encode this as a language problem, let Σ = {0, 1,?}. We can then encode instances of the string search problem as the string pattern?text. For example: Does 0110 appear in 1110110? would be encoded as 0110?1110110 Does 11 appear in 0001? would be encoded as 11?0001 Does ε appear in 1100? would be encoded as?1100 Let the language SEARCH = { p?t p, t { 0, 1}* and p is a substring of t }. Prove that SEARCH is not regular, which means that no DFA, NFA, or regular expression is powerful enough to describe SEARCH.

Problem Seven: Course Feedback (5 Points) We want this course to be as good as it can be, and we'd really appreciate your feedback on how we're doing. For a free five points, please answer the following questions. We'll give you full credit no matter what you write (as long as you write something!), but we'd appreciate it if you're honest about how we're doing. i. How hard did you find this problem set? How long did it take you to finish? Does that seem unreasonably difficult or time-consuming for a five-unit class? ii. Did you attend the midterm review session? If so, did you find it useful? iii. How is the pace of this course so far? Too slow? Too fast? Just right? iv. Is there anything in particular we could do better? Is there anything in particular that you think we're doing well? Submission instructions There are three ways to submit this assignment: 1. Hand in a physical copy of your answers at the start of class. This is probably the easiest way to submit if you are on campus. 2. Submit a physical copy of your answers in the filing cabinet in the open space near the handout hangout in the Gates building. If you haven't been there before, it's right inside the entrance labeled Stanford Engineering Venture Fund Laboratories. There will be a clearly-labeled filing cabinet where you can submit your solutions. 3. Send an email with an electronic copy of your answers to the submission mailing list (cs103-win1213-submissions@lists.stanford.edu) with the string [PS5] somewhere in the subject line. You should receive automatic confirmation of your submission. If you submit electronically, please submit your assignment as a single PDF if at all possible. Sending multiple files makes it harder to print out and grade your submission. Extra Credit Problem: Splitting Regular Languages (5 Points) Let L be an arbitrary infinite regular language. Prove that there exist languages L 1 and L 2 such that 1. L 1 L 2 = L, 2. L 1 L 2 = Ø, 3. L 1 and L 2 are infinite, and 4. L 1 and L 2 are regular. This shows that it is always possible to split an infinite regular language into two other infinite regular languages. (Hint: Use the pumping lemma, along with the fact that regular languages are closed under subtraction. That is, if L 1 and L 2 are regular, then L 1 L 2 is regular.)