CS525 Winter 2012 \ Class Assignment #2 Preparation

Similar documents
Non-context-Free Languages. CS215, Lecture 5 c

Theory of Computation, Homework 3 Sample Solution

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

Ambiguous Grammars and Compactification

Computer Science 236 Fall Nov. 11, 2010

Properties of red-black trees

Context-Free Grammars and Languages (2015/11)

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Context Free Grammars. CS154 Chris Pollett Mar 1, 2006.

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

Math 485, Graph Theory: Homework #3

Context-Free Languages and Parse Trees

Context-Free Grammars

MA513: Formal Languages and Automata Theory Topic: Context-free Grammars (CFG) Lecture Number 18 Date: September 12, 2011

Yet More CFLs; Turing Machines. CS154 Chris Pollett Mar 8, 2006.

COT 3100 Spring 2010 Midterm 2

Homework. Context Free Languages. Before We Start. Announcements. Plan for today. Languages. Any questions? Recall. 1st half. 2nd half.

Multiple Choice Questions

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

UNIT I PART A PART B

CHAPTER 10 GRAPHS AND TREES. Alessandro Artale UniBZ - artale/

Problem Set 2 Solutions

Algorithms. Red-Black Trees

2 The Fractional Chromatic Gap

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

DO NOT RE-DISTRIBUTE THIS SOLUTION FILE

COUNTING THE NUMBER OF WINNING BINARY STRINGS IN THE 1-DIMENSIONAL SAME GAME. Department of Mathematics Oberlin College Oberlin OH 44074

TAFL 1 (ECS-403) Unit- V. 5.1 Turing Machine. 5.2 TM as computer of Integer Function

Principles of Programming Languages COMP251: Syntax and Grammars

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

Lecture 1. 1 Notation

CT32 COMPUTER NETWORKS DEC 2015

Theory of Computation

COL351: Analysis and Design of Algorithms (CSE, IITD, Semester-I ) Name: Entry number:


AXIOMS FOR THE INTEGERS

ELEC-270 Solutions to Assignment 5

Lecture 22 Tuesday, April 10

Generell Topologi. Richard Williamson. May 6, 2013

JNTUWORLD. Code No: R

Lecture 19 Thursday, March 29. Examples of isomorphic, and non-isomorphic graphs will be given in class.

THEORY OF COMPUTATION

Adjacent: Two distinct vertices u, v are adjacent if there is an edge with ends u, v. In this case we let uv denote such an edge.

Recursion and Structural Induction

Mathematical Induction

CS402 - Theory of Automata Glossary By

Chapter 11: Graphs and Trees. March 23, 2008

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

Solution to Graded Problem Set 4

Space vs Time, Cache vs Main Memory

Treewidth and graph minors

MAT 145: PROBLEM SET 4

Trees (Part 1, Theoretical) CSE 2320 Algorithms and Data Structures University of Texas at Arlington

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

Trees. 3. (Minimally Connected) G is connected and deleting any of its edges gives rise to a disconnected graph.

Intro to semantics; Small-step semantics Lecture 1 Tuesday, January 29, 2013

CMSC Theory of Algorithms Second Midterm

CpSc 421 Final Solutions

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

EDAA40 At home exercises 1

Reflection in the Chomsky Hierarchy

Context-Free Grammars

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

IEEE TRANSACTIONS ON INFORMATION THEORY, VOL. 52, NO. 4, APRIL

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

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

Digital Logic Design: a rigorous approach c

1. Suppose you are given a magic black box that somehow answers the following decision problem in polynomial time:

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

Treaps. 1 Binary Search Trees (BSTs) CSE341T/CSE549T 11/05/2014. Lecture 19

Definition: two derivations are similar if one of them precedes the other.

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

1KOd17RMoURxjn2 CSE 20 DISCRETE MATH Fall

CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics

Paths, Flowers and Vertex Cover

4 Basics of Trees. Petr Hliněný, FI MU Brno 1 FI: MA010: Trees and Forests

A Simple Syntax-Directed Translator

Module 7. Independent sets, coverings. and matchings. Contents

arxiv: v2 [math.co] 13 Aug 2013

II (Sorting and) Order Statistics

Syntax Analysis Check syntax and construct abstract syntax tree

We assume uniform hashing (UH):

Slides for Faculty Oxford University Press All rights reserved.

CS473-Algorithms I. Lecture 13-A. Graphs. Cevdet Aykanat - Bilkent University Computer Engineering Department

T consists of finding an efficient implementation of access,

Chapter 3: CONTEXT-FREE GRAMMARS AND PARSING Part2 3.3 Parse Trees and Abstract Syntax Trees

In this lecture, we ll look at applications of duality to three problems:

CS152: Programming Languages. Lecture 2 Syntax. Dan Grossman Spring 2011

Exercise 1: Balanced Parentheses

Edge Colorings of Complete Multipartite Graphs Forbidding Rainbow Cycles

14.1 Encoding for different models of computation

Rigidity, connectivity and graph decompositions

Solution Set 8 Date: 1 December, 1992

(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

Decision Properties for Context-free Languages

These notes present some properties of chordal graphs, a set of undirected graphs that are important for undirected graphical models.

Chapter 3. Describing Syntax and Semantics

Compiler Construction

MAT 145: PROBLEM SET 6

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

Transcription:

1 CS525 Winter 2012 \ Class Assignment #2 Preparation Ariel Stolerman 2.26) Let be a CFG in Chomsky Normal Form. Following is a proof that for any ( ) of length exactly steps are required for any derivation of. We prove by induction on the length of,. Since is a CFG in Chomsky Normal Form, then any rule is of the form: (where the variables and is the start symbol), (where the terminal ) and it may contain. First, for any such that, it must be derived by a rule, where is the start symbol and is a terminal different than. It cannot be that, otherwise. Also, it cannot be derived starting at a rule, since neither nor can derive, therefore any derivation starting at derives a string with length. Therefore the derivation must be by the sequence of rules (where ), which contains only one step, and satisfies the required rules in any derivation of of size. Now assume that any string of size strictly less than in satisfies the claim, and let be a string in of size. The case in which is a single terminal is handled in the base case of the induction. Therefore for any of size greater than 1 the first step in the derivation has to be of the form, where is the start symbol and are variables. Moreover, since cannot be, they cannot derive a string of size 0 ( ), thus we can say that and where are nonempty strings, and (the concatenation of and ). Denote and, so (and ). Therefore according to the induction assumption is derived in steps and is derived in steps. Since is derived by the step followed by the derivations of and (in some order), the total derivation steps for are: ( ) ( ) ( ) Thus proving the claim. 2.27) a. Following is an example for an ambiguous string in ( ) for the given grammar if condition then if condition then else with 2 different derivations: STMT if condition then STMT STMT if condition then STMT else STMT if condition then STMT else STMT if condition then STMT

2 b. Following is an unambiguous grammar for the same language: <STMT> <> <IF-THEN> <IF-THEN-ELSE> <IF-THEN> if condition then <STMT> if condition then <IF-THEN-ELSE> else <IF-THEN> <IF-THEN-ELSE> if condition then <IF-THEN-ELSE> else <IF-THEN-ELSE> <> <> 2.28) Following are unambiguous grammars for the given languages. a. * + b. * + c. * + 2.29 Let * +. Following is a proof that is inherently ambiguous: Following is an example grammar for the string: This grammar is ambiguous, yet it does not prove that no unambiguous grammar for exists. However, the only way to ensure for the strings where that indeed is with a rule like. For instance, must be derived from any grammar of, for any (representing the number of ), thus it also must have rules that can derive any number of like. Similarly for strings where we need a rule like to ensure. For

3 instance, must be derived from any grammar of, for any (representing the number of ), thus it also must have rules that can derive any number of like. Therefore, any grammar for must be able to derive strings of the form in at least two ways: once using times the derivation of the same number of and followed by times the derivation of, and once using times the derivation of the same number of and followed by times the derivation of. Therefore any grammar for is ambiguous, thus is inherently ambiguous. 2.30 Following are proofs using the pumping lemma that is not a CFL. a. Let * +. Assume that is a CFL, and let where is the pumping length of. Clearly, but any partition of into where and satisfies that : if we denote the first as, first as, second as and second as then since the whole substring crosses at most only two consecutive sectors, i.e. it is all part of. In all of those cases, since then either, or both. Therefore it cannot be that the pumping will change all sectors (at most two will change) thus, in contradiction to the assumption. Therefore is not a CFL. d. Let { * + }. Assume that is a CFL and let where is the pumping length of. Clearly, but any partition of into where and satisfies that : Since this string contains only 2 s, it is sufficient to show that the pumping will make (the substring before the ) and (the substring after the ) different. If is contained completely in (before the ), since at least one of has length, the pumping will alter to be different than with either different number of a s or b s (or both), thus. If is partially contained in and partially in : o If either or contain the, pumping (down) will eliminate it and the pumped string will contain only a single block of and such that the in the language description will be equal to, thus the pumped string will not be in. o If neither nor contain the, since at least one of has length at least 1, the pumping will alter the number of s in or the number of in such that. If is contained completely in, it is similar to the first case. Therefore no partition of into by the conditions of the pumping lemma can derive that will also be in in contradiction to the assumption. Thus is not a CFL.

4 2.31 Let * * + +. Following is a proof that is not a CFL: Assume is a CFL, then it satisfies the conditions of the pumping lemma. Let be the pumping length of and let. Clearly since it is a palindrome ( reflects to ) and has the same number of 0 s and 1 s ( ). But there exists no partition of that satisfies the pumping lemma conditions and for which : since it may be constructed of only 0 s, 0 s followed by 1 s or 1 s followed by 0 s. The cases: If consists only of 0 s, since at least one of has length at least 1, then the pumped string will have more 0 s on the left half than on the right half, and will have more 0 s than 1 s, thus the pumped string will not be in. This case is true for consisting of 0 s only from the right half or only from the left half. If consists only of 1 s, similarly to the previous case, the string will have more 1 s than 0 s thus the pumped string will not be in (although it might still be a palindrome). If consists partially of 0 s and partially of 1 s, i.e. where, since at least one of has length at least 1, the pumping will result with: o If one of spans over both 0 s and 1 s, the pumping will create a non-palindrome string, since it will add some pattern of to the left hand side of the string, which will not be matched on the right hand side. o If is only 0 s and is only 1 s, the pumping will again create a string not in, as either the left hand side will not be matched on the right, or it will violate the equality between the number of 0 s and 1 s. Therefore in any case the pumped string will not be in, in contradiction to the assumption. Therefore is not a CFL. 2.32 Let * * + +. Following is a proof that is not a CFL: Assume is a CFL, then it satisfies the conditions of the pumping lemma. Let be the pumping length of and let. Clearly. But there exists no partition of into such that satisfies the pumping lemma conditions and for which : since it may be constructed of only 1 s, 1 s and 3 s, only 3 s, 3 s and 2 s, only 2 s, 2 s and 4 s or only 4 s. The cases: If contains only 1 s, since at least one of has length at least 1, then in there will be more 1 s than 2 s, thus. A similar violation happens when is consisted of only 2 s, 3 s or 4 s. If contains both 1 s and 3 s, since at least one of has length at least 1: o If one of contains both 1 s and 3 s, then will contain more 1 s than 2 s and more 3 s than 4 s, therefore. o If one of contains only 1 s or only 3 s, then will contain more 1 s than 2 s or more 3 s than 4 s, therefore. A similar violation happens when is consisted of only 3 s and 2 s or only 2 s and 4 s. Therefore in any case the pumped string will not be in, in contradiction to the assumption. Therefore is not a CFL.

5 2.33 Let * + (fixed phrasing from the textbook errata webpage). Following is a proof that is not a CFL: Assume is a CFL, then it satisfies the conditions of the pumping lemma. Let be the pumping length of and let where. Clearly, but for any partition of into such that and there exists a pumping of to such that : If is consisted only of s, since at least one of has length at least 1 and, choosing will remove between s such that will have between ( ), therefore cannot be a multiple of, thus. If is consisted only of s, since at least one of has length at least 1 and, choosing will in any case pump the number of s to be more than the number of s (the least number of s will be in ), so that it cannot be an integer multiplication of the number of s. Thus. If is consisted of both s and s, since at least one of has length at least 1: o If one of contains both s and s, choosing will make contain some s before s so will not be of the form, thus. o If contains only s and contains only s (and otherwise it is one of the previous cases), denote. Note that and for we must show there exists some such that this is not an integer. For we get ; for we get. Since, we get. In the largest range possible, will be in ( ] ( ], which has a finite number of integers. Since all derive distinct s, there must be some for which will not be an integer, thus. Therefore in any case the pumped string will not be in, in contradiction to the assumption. Therefore is not a CFL. 2.34 Let be a grammar of the language ( ) with the following rules: Find the minimum pumping length of that will work in the pumping lemma.

6 2.35 Let be a CFG in Chomsky normal form that contains variables and let be some string generated by with at least steps. Following is a proof that ( ) is infinite: Following the proof of the pumping lemma for CFLs in the book, any binary tree of height has at most leaves (where the root is of height 0), and the number of internal nodes is at most (when the number of leaves is indeed ). Therefore if the number of internal nodes is at least, the height of the tree will be at least. Since the grammar is in Chomsky normal form, the maximum number of symbols on the right hand side of any rule is 2 (2 variables), thus any node in a parse tree of the grammar will have at most 2 children. If there exists a string ( ) such that it is derived with at least steps, it must have at least internal nodes, therefore the height of the parse tree will be at least. Continuing as in the pumping lemma proof, this means any parse tree of would have a path of length, i.e. constructed of at least symbols where the last one (leaf) is a terminal, and the first (or more) are variables. Since there are only variables, following the pigeon-hole principle, at least one variable appears along the path at least twice. Let be a repeating variable among the lowest variables, then we can replace the lower appearance with the higher one as many times as we like, pumping forever, where each pumped string is in ( ) (since we are getting a legal parse tree), thus proving ( ) is infinite.