CS103 Handout 16 Winter February 15, 2013 Problem Set 6

Similar documents
CS103 Handout 14 Winter February 8, 2013 Problem Set 5

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

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

Theory of Computation Dr. Weiss Extra Practice Exam Solutions

JNTUWORLD. Code No: R

CS 44 Exam #2 February 14, 2001

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

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

PDA s. and Formal Languages. Automata Theory CS 573. Outline of equivalence of PDA s and CFG s. (see Theorem 5.3)

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

COMP 330 Autumn 2018 McGill University

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

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

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

Context-Free Grammars

Notebook Assignments

CS 320 Week 8 Homework Due W 3/27 11:59pm. incm 5 >>= (\x -> incm x >>= (\y -> incm y) )

CpSc 421 Final Solutions

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

Turing Machines Part Two

14.1 Encoding for different models of computation

Theory Bridge Exam Example Questions Version of June 6, 2008

UNIT I PART A PART B

CS2 Practical 2 CS2Ah

Chapter Seven: Regular Expressions

Automata Theory TEST 1 Answers Max points: 156 Grade basis: 150 Median grade: 81%

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

QUESTION BANK. Unit 1. Introduction to Finite Automata

PS3 - Comments. Describe precisely the language accepted by this nondeterministic PDA.

Models of Computation II: Grammars and Pushdown Automata

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

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

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

Theory of Computations Spring 2016 Practice Final Exam Solutions

1 Parsing (25 pts, 5 each)

Assignment No.4 solution. Pumping Lemma Version I and II. Where m = n! (n-factorial) and n = 1, 2, 3

Recursively Enumerable Languages, Turing Machines, and Decidability

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


CSE 105 THEORY OF COMPUTATION

CSC-461 Exam #2 April 16, 2014

CS525 Winter 2012 \ Class Assignment #2 Preparation

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

CSE 21 Spring 2016 Homework 5. Instructions

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

Announcements. CS243: Discrete Structures. Strong Induction and Recursively Defined Structures. Review. Example (review) Example (review), cont.

Proof Techniques Alphabets, Strings, and Languages. Foundations of Computer Science Theory

Decision Properties for Context-free Languages

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

Problems, Languages, Machines, Computability, Complexity

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Context-Free Grammars

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

Context-Free Languages & Grammars (CFLs & CFGs) Reading: Chapter 5

Turing Machine Languages

CS311 / MATH352 - AUTOMATA AND COMPLEXITY THEORY

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

Finite Automata Part Three

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

Notes for Comp 454 Week 2

Material from Recitation 1

CSE 21 Spring 2016 Homework 5. Instructions

Skill 1: Multiplying Polynomials

CS103 Spring 2018 Mathematical Vocabulary

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

Midterm I (Solutions) CS164, Spring 2002

Actually talking about Turing machines this time

Ambiguous Grammars and Compactification

Normal Forms for CFG s. Eliminating Useless Variables Removing Epsilon Removing Unit Productions Chomsky Normal Form

Algorithms Activity 6: Applications of BFS

1. Which of the following regular expressions over {0, 1} denotes the set of all strings not containing 100 as a sub-string?

Computer Science 236 Fall Nov. 11, 2010

Final Exam 2, CS154. April 25, 2010

Context-Free Languages and Pushdown Automata

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

CS52 - Assignment 10

CS 314 Principles of Programming Languages. Lecture 3

AUBER (Models of Computation, Languages and Automata) EXERCISES

Final Course Review. Reading: Chapters 1-9

Theory of Computations Spring 2016 Practice Final

CS143 Handout 20 Summer 2011 July 15 th, 2011 CS143 Practice Midterm and Solution

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

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

Glynda, the good witch of the North

15-110: Principles of Computing, Spring 2018

CHAPTER TWO LANGUAGES. Dr Zalmiyah Zakaria

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

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

CS402 - Theory of Automata FAQs By

CS161 Handout 07 Summer 2013 July 17, 2013 Guide to Reductions. Thanks to Julie Tibshirani for helping with this handout!

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

Graph Theory Part Two

CS264: Homework #1. Due by midnight on Thursday, January 19, 2017

U.C. Berkeley CS170 : Algorithms Midterm 1 Lecturers: Alessandro Chiesa and Umesh Vazirani February 13, Midterm 1

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

Closure Properties of CFLs; Introducing TMs. CS154 Chris Pollett Apr 9, 2007.

Multiple Choice Questions

(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

MATH10001 Mathematical Workshop. Graphs, Trees and Algorithms Part 2. Trees. From Trees to Prüfer Codes

CS2110 Assignment 2 Lists, Induction, Recursion and Parsing, Summer

Transcription:

CS103 Handout 16 Winter 2012-2013 February 15, 2013 Problem Set 6 How much firepower do context-free languages have? What are their limits? And just how awesome are PDAs? In this problem set, you'll get to find out! 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 Monday, February 25 th at 12:50 PM

Problem One: Designing CFGs (32 Points) Below are a list of alphabets and languages over those alphabets. For each language, design a contextfree grammar that generates that language, then show derivations for the indicated strings. i. For the alphabet Σ = { a, b, c }, write a CFG for the language L = { w Σ* w contains aa as a substring }. Show a derivation of the strings aa, abaabc, and ccaabb using your grammar. ii. For the alphabet Σ = { a, b, c }, write a CFG for the language L = { w Σ* w does not contain both a and b. } Show a derivation of the strings ε, a, caac, and bbb. iii. For the alphabet Σ = { a, b, c }, write a CFG for L = { a i b j c k i, j, k N ( i = j i = k) }. Show a derivation of the strings aabcc, aabbc, and abc. iv. For the alphabet Σ = {a, b}, write a CFG for the language L = { w Σ* w is not a palindrome }. That is, w is not the same when read forwards and backwards. Thus aab L and baabab L, but aba L and bb L. Show a derivation of the string aab and the string abbaba. v. For the alphabet Σ = {a, b}, write a CFG for the language L = { w Σ* w 4 0, and the first quarter of the characters in w contains at least one b } For example, baaa L, bbbb L, abbbbbba L, bbbaaabbbaaa L, ababbbbbbbbb L, but abbb L, ε L, b L, aabbbbaa L, and aaabbbbbbbbb L. (For simplicity, I've underlined the first quarter of the characters in each string). Show a derivation of baaa, abaaaaaa, and baaaaaaa. Problem Two: The Complexity of Addition (16 Points) On the previous problem set, we began addressing the question We will now directly answer that question. How hard is it to add two numbers? Consider the language ADD = {1 m +1 n =1 m + n m, n N} over the alphabet Σ = {1, +, =}. That is, ADD consists of strings encoding two unary numbers and their sum. As you proved on the previous problem set, ADD is not regular. i. Write a context-free grammar for ADD. Show a derivation of 1+1=11 and +111=111 using your grammar. This proves that ADD is context-free. (If you are hand-writing your grammar, please make sure your ones are easily distinguished from the vertical bars used to separate productions. Thanks!) ii. Design a deterministic PDA that recognizes ADD (recall that a DPDA is a PDA in which for any combination of a state, input symbol, and stack symbol there is at most one transition that can be followed, including ε-transitions). This proves that ADD is not only a context-free language, but also a deterministic context-free language.

Problem Three: There and Back Again (Part I) (16 Points) Suppose that you live in a one-dimensional world with your house at position 0, as shown here: 5 4 3 2 1 0 1 2 3 4 5 One day, you decide to go for a walk by taking steps of size ±1 forward and backward. You begin at your house and, after completing your walk, end up back at your house. Consider the alphabet Σ = {L, R}. A string in Σ* describes a possible walk where at each step you either move a step left (L) or a step right (R). For example, the string LRRRLL means that you take a step left, then three steps right, then two steps left. Let L = { w Σ* w describes a series of steps in which you arrive at the same place at which you started }. i. Write a CFG that generates L. Show a derivation of LLRR, RLRL, and LLRRRRLL using your grammar. ii. Design a deterministic PDA that recognizes L (recall that a DPDA is a PDA in which for any combination of a state, input symbol, and stack symbol there is at most one transition that can be followed, including ε-transitions). This proves that L is not only a context-free language, but also a deterministic context-free language. Problem Four: Shrinking PDAs (16 Points) As you saw in lecture, any CFG can be converted into a PDA with just three states, meaning that the full power of the context-free languages can be expressed by three-state PDAs. This question asks you to see just how few states PDAs can have while retaining their expressive power. i. Show how to modify the construction from lecture that turns CFGs into PDAs so that the generated PDA has only two states instead of three. You should briefly describe how your construction works, but you don't need to formally prove that it is correct. ii. Using your result from (i), prove that for any PDA P, there is a PDA P' such that L( P) = L( P') and P' has only two states. iii. Your result from (ii) shows that any PDA can be converted into an equivalent PDA with just two states. However, it is not always possible to convert a PDA into an equivalent PDA with just one state. Find a context-free language that does not have a one-state PDA, prove it is context-free, then prove that it does not have a one-state PDA.

Problem Five: There and Back Again (Part II) (20 Points) Suppose that you live in a two-dimensional world with your house at position (0, 0). One day, you decide to go for a walk by taking steps of size ±1 up, down, left, and right. You begin at your house and, after completing your walk, end up back at your house. Consider the alphabet Σ = {L, R, U, D}. A string in Σ* describes a possible walk where at each step you either move a step left (L), a step right (R), a step up (U), or a step down (D). For example, the string ULULDDRR means that you take a step up, then a step left, then a step up, then a step left, then two steps down, then two steps right. Let L = { w Σ* w describes a series of steps in a two-dimensional grid in which you arrive at the same place at which you started }. Prove that L is not context-free. Problem Six: The Complexity of String Searching (20 Points) On the previous problem set, we began addressing the question How hard is it to search a string for a substring? Given a string to search for (called the pattern) and a string in which the search should be conducted (called the text), we want to determine whether the pattern appears in the text. To encode this as a language problem, we let Σ = {0, 1,?} and encoded questions of the form does pattern string p appear in text t as the string p?t. 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 }. On the last problem set, you proved that SEARCH is not regular using the pumping lemma for regular languages. Now, using the pumping lemma for context-free languages, prove that SEARCH is not context-free either. As a hint, the pattern and text string you show cannot be pumped must use both 0s and 1s. In fact, if you restrict the pattern and text strings to strings consisting solely of 0s, you get the language which is context-free. LE = { 0 n?0 m n, m N n m }

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. 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 a recitation section? 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 [PS6] somewhere in the subject line. If you do submit electronically, please submit your assignment as a single PDF if at all possible. Sending multiple image files makes it hard to print and grade your submission. Extra Credit Problem: Non-Repeating Strings (5 Points Extra Credit) Let Σ = {a, b} and let L = { wx w Σ*, x Σ*, w = x, and w x }. Intuitively, L consists of all strings of even length whose first half is not equal to its second half. For example, aaba L, aaababbb L, ab L, and bbbbba L. Write a CFG for L. Give derivations for ab, aaabaaba, and aabaaabbab.