Solutions for Homework Five, CSE 355

Similar documents
ÖVNINGSUPPGIFTER I SAMMANHANGSFRIA SPRÅK. 15 april Master Edition

Pushdown Automata. place the input head on the leftmost input symbol. while symbol read = b and pile contains discs advance head remove disc from pile

CS103B Handout 17 Winter 2007 February 26, 2007 Languages and Regular Expressions

Fundamentele Informatica II

CMPSCI 250: Introduction to Computation. Lecture #19: Regular Expressions and Their Languages David Mix Barrington 11 April 2013

C H A P T E R Regular Expressions regular expression

Formal Languages and Automata Theory - Regular Expressions and Finite Automata -

Automata and Formal Languages

Automata and Computability. Solutions to Exercises

Theory of Computation Class Notes 1

Estimating Probability Distributions

6.045: Automata, Computability, and Complexity Or, Great Ideas in Theoretical Computer Science Spring, Class 4 Nancy Lynch

Regular Languages and Finite State Machines

Honors Class (Foundations of) Informatics. Tom Verhoeff. Department of Mathematics & Computer Science Software Engineering & Technology

THEORY of COMPUTATION

(IALC, Chapters 8 and 9) Introduction to Turing s life, Turing machines, universal machines, unsolvable problems.

T ( a i x i ) = a i T (x i ).

Turing Machines: An Introduction

On the generation of elliptic curves with 16 rational torsion points by Pythagorean triples

Math 312 Homework 1 Solutions

INCIDENCE-BETWEENNESS GEOMETRY

Automata on Infinite Words and Trees

COMMUTATIVE RINGS. Definition: A domain is a commutative ring R that satisfies the cancellation law for multiplication:

Chapter 7 Uncomputability

3515ICT Theory of Computation Turing Machines

Regular Expressions with Nested Levels of Back Referencing Form a Hierarchy

Local periods and binary partial words: An algorithm

Lecture 18 Regular Expressions

Push-down Automata and Context-free Grammars

The Halting Problem is Undecidable

CSC4510 AUTOMATA 2.1 Finite Automata: Examples and D efinitions Definitions

SYSTEMS OF EQUATIONS AND MATRICES WITH THE TI-89. by Joseph Collison

Pushdown automata. Informatics 2A: Lecture 9. Alex Simpson. 3 October, School of Informatics University of Edinburgh als@inf.ed.ac.

MACM 101 Discrete Mathematics I

CS 103X: Discrete Structures Homework Assignment 3 Solutions

Homework until Test #2

ASSIGNMENT ONE SOLUTIONS MATH 4805 / COMP 4805 / MATH 5605

The Optimum One-Pass Strategy for Juliet

Solution to Homework 2

SOLUTIONS TO ASSIGNMENT 1 MATH 576

4. How many integers between 2004 and 4002 are perfect squares?

Applications of Fermat s Little Theorem and Congruences

Informatique Fondamentale IMA S8

The Prime Numbers. Definition. A prime number is a positive integer with exactly two positive divisors.

LINEAR ALGEBRA. September 23, 2010

Pushdown Automata. International PhD School in Formal Languages and Applications Rovira i Virgili University Tarragona, Spain

Elementary Number Theory and Methods of Proof. CSE 215, Foundations of Computer Science Stony Brook University

a 11 x 1 + a 12 x a 1n x n = b 1 a 21 x 1 + a 22 x a 2n x n = b 2.

PYTHAGOREAN TRIPLES KEITH CONRAD

December 4, 2013 MATH 171 BASIC LINEAR ALGEBRA B. KITCHENS

The common ratio in (ii) is called the scaled-factor. An example of two similar triangles is shown in Figure Figure 47.1

Increasing Interaction and Support in the Formal Languages and Automata Theory Course

1 Introduction to Matrices

Automata, languages, and grammars

6.080/6.089 GITCS Feb 12, Lecture 3

CS154. Turing Machines. Turing Machine. Turing Machines versus DFAs FINITE STATE CONTROL AI N P U T INFINITE TAPE. read write move.

Lempel-Ziv Coding Adaptive Dictionary Compression Algorithm

k, then n = p2α 1 1 pα k

Introduction to Automata Theory. Reading: Chapter 1

FACTORING CERTAIN INFINITE ABELIAN GROUPS BY DISTORTED CYCLIC SUBSETS

Continued Fractions and the Euclidean Algorithm

2004 Solutions Ga lois Contest (Grade 10)

Implementation of Recursively Enumerable Languages using Universal Turing Machine in JFLAP

Extension of measure

Fast nondeterministic recognition of context-free languages using two queues

Chapter 7. Matrices. Definition. An m n matrix is an array of numbers set out in m rows and n columns. Examples. (

Selected practice exam solutions (part 5, item 2) (MAT 360)

Online EFFECTIVE AS OF JANUARY 2013

Matrix Representations of Linear Transformations and Changes of Coordinates

Mathematical Induction

VOCATIONAL NURSING INFORMATION SHEET

Regular Expressions and Automata using Haskell


4. FIRST STEPS IN THE THEORY 4.1. A

Chapter 17. Orthogonal Matrices and Symmetries of Space

Brief Introduction to Vectors and Matrices

Introduction to Turing Machines

Baltic Way Västerås (Sweden), November 12, Problems and solutions

Omega Automata: Minimization and Learning 1

CM2202: Scientific Computing and Multimedia Applications General Maths: 2. Algebra - Factorisation

Left-Handed Completeness

On Winning Conditions of High Borel Complexity in Pushdown Games

MATRIX ALGEBRA AND SYSTEMS OF EQUATIONS

MATH10040 Chapter 2: Prime and relatively prime numbers

Scanner. tokens scanner parser IR. source code. errors

Bottom-Up Parsing. An Introductory Example

SECTION 10-5 Multiplication Principle, Permutations, and Combinations

Algebraic Structures II

Index support for regular expression search. Alexander Korotkov PGCon 2012, Ottawa

Questions and Answers in Computer Science. By Yonas Tesfazghi Weldeselassie weldesel

CONTINUED FRACTIONS AND PELL S EQUATION. Contents 1. Continued Fractions 1 2. Solution to Pell s Equation 9 References 12

IEEE TRANSACTIONS ON INFORMATION THEORY 1. The Smallest Grammar Problem

2 When is a 2-Digit Number the Sum of the Squares of its Digits?

MATRIX ALGEBRA AND SYSTEMS OF EQUATIONS. + + x 2. x n. a 11 a 12 a 1n b 1 a 21 a 22 a 2n b 2 a 31 a 32 a 3n b 3. a m1 a m2 a mn b m

I. GROUPS: BASIC DEFINITIONS AND EXAMPLES

CS5236 Advanced Automata Theory

So let us begin our quest to find the holy grail of real analysis.

Transcription:

Solutions for Homework Five, CSE 355 1. (7.1, 10 points) Let M be the PDA defined by Q = {q 0,q 1,q 2 } Σ = {a,b} Γ = {A} F = {q 1,q 2 } δ(q 0,a,λ) = {[q 0,A]} δ(q 0,λ,λ) = {[q 1,λ]} δ(q 0,b,A) = {[q 2,λ]} δ(q 1,λ,A) = {[q 1,λ]} δ(q 2,b,A) = {[q 2,λ]} δ(q 2,λ,A) = {[q 2,λ]} a) Describe the language accepted by M. b) Give the state diagram of M. c) Trace all computations of the strings aab, abb, aba in M. d) Show that aabb,aaab L(M). Solution: a) The PDA M accepts the language {a i b j 0 j i}. Processing an a pushes A onto the stack. Strings of the form a i are accepted in state q 1. The transitions in q 1 empty the stack after the input has been read. A computation with input a i b j enters state q 2 upon processing the first b. To read the entire input string, the stack must contain at least j A s. The transition δ(q 2,λ,A) = [q 2,λ] will pop any A s remaining on the stack. b) The state diagram of M is aλ/a λa/λ q 2 ba/λ ba/λ, λa/λ c) The computations of aab in M are as follows: q 0 aab λ q 1 aab λ q 0 aab λ q 0 ab A q 1 ab A q 1 b λ 1

q 0 aab λ q 0 ab A q 0 b AA q 1 b AA q 1 b A q 1 b λ The computations of abb in M are as follows: q 1 abb λ q 0 bb A q 1 bb A q 1 bb λ The computations of aba in M are as follows: q 0 aba λ q 1 aba λ q 0 aba λ q 0 ba A q 1 ba A q 1 ba λ q 0 aab λ q 0 ab A q 0 b AA q 2 λ A q 2 λ λ q 0 bb A q 2 b λ q 0 aba λ q 0 ba A q 2 a λ d) To show that the string aabb and aaab are in L(M), we trace a computation of M that accepts these strings. q 0 aabb λ q 0 abb A q 0 bb AA q 2 b A q 2 λ λ q 0 aaab λ q 0 aab A q 0 ab AA q 0 b AAA q 2 λ AA q 2 λ A q 2 λ λ 2. (7.2, 10 points) Let M be the PDA in Example 7.1.3. bλ/b, aλ/a bb/λ, aa/λ a) Give the transition table of M. b) Trace all computations of the strings ab, abb, abbb in M. c) Show that aaaa,baab L(M). d) Show that aaa,ab / L(M). Solution: 2

a) Q = {q 0,q 1 } Σ = {a,b} Γ = {A,B} F = {q 1 } δ(q 0,b,λ) = {[q 0,B]} δ(q 0,a,λ) = {[q 0,A]} δ(q 0,λ,λ) = {[q 1,λ]} δ(q 1,b,B) = {[q 1,λ]} δ(q 1,a,A) = {[q 1,λ]} b) The computations of ab in M are as follows: q 0 ab λ q 1 ab λ q 0 ab λ q 0 b A q 1 b A The computations of abb in M are as follows: q 1 abb λ q 0 bb A q 0 b BA q 1 b BA q 1 λ A The computations of abbb in M are as follows: q 0 abbb λ q 1 abbb λ q 0 abbb λ q 0 bbb A q 0 bb BA q 0 b BBA q 1 b BBA q 1 λ BA q 0 abbb λ q 0 bbb A q 1 bbb A q 0 ab λ q 0 b A q 0 λ BA q 1 λ BA q 0 bb A q 1 bb A q 0 bb A q 0 b BA q 0 λ BBA q 1 λ BBA q 0 abbb λ q 0 bbb A q 0 bb BA q 1 bb BA q 1 b A q 0 abbb λ q 0 bbb A q 0 bb BA q 0 b BBA q 0 λ BBBA q 1 λ BBBA c) To show that the string aaaa and baab are in L(M), we trace a computation of M that accepts these strings. 3

q 0 aaaa λ q 0 aaa A q 0 aa AA q 1 aa AA q 1 a A q 1 λ λ q 0 baab λ q 0 aab B q 0 ab AB q 1 ab AB q 1 b B q 1 λ λ d) To show that the string aaa and ab are not in L(M), we trace all computations of these strings in M, and check whether none of them accepts these strings. We have listed all the computations of ab in (b), and none of them accepts it. Now we trace all computations of aaa in M q 0 aaa λ q 1 aaa λ q 0 aaa λ q 0 aa A q 0 a AA q 1 a AA q 1 λ A q 0 aaa λ q 0 aa A q 1 aa A q 1 a λ q 0 aaa λ q 0 aa A q 0 a AA q 0 λ AAA q 1 λ AAA Since none of the computations above is accepted, we have aaa is not in M. 3. (7.3, 10 points) Construct PDAs that accept each of the following languages. a) {a i b j 0 i j} b) {a i c j b i i,j 0} c) {a i b j c k i + k = j} d) {w w {a,b} and w has twice as many a s as b s} e) {a i b i i 0} a b f) {a i b j c k i = j or j = k} g) {a i b j i j} h) {a i b j 0 i j 2i} i) {a i+j b i c j i,j > 0} j) The set of palindromes over {a,b} Solution: 4

aλ/a ba/λ, bλ/λ a) b) c) aλ/a cλ/λ ba/λ q 0 q 1 q 2 aλ/a ba/λ, bλ/b cb/λ q 0 q 1 q 2 d) The pushdown automaton defined by the transitions δ(q 0,λ,λ) = {[q 1,C]} δ(q 1,a,A) = {[q 2,A]} δ(q 1,a,C) = {[q 2,C]} δ(q 1,b,B) = {[q 3,B]} δ(q 1,b,C) = {[q 3,C]} δ(q 1,a,B) = {[q 1,λ]} δ(q 1,b,A) = {[q 1,λ]} δ(q 1,λ,C) = {[q 5,λ]} δ(q 2,λ,λ) = {[q 1,A]} δ(q 3,λ,λ) = {[q 4,B]} δ(q 4,λ,λ) = {[q 1,B]} accepts strings that have twice as many a s as b s. A computation begins by pushing a C onto the stack, which serves as a bottom-maker throughout the computation. The stack is used to record the relationship between the number of a s and b s scanned during the computation. The stacktop will be a C when the number of a s processed is exactly twice the number of b s processed. The stack will contain n A s if the automaton has read n more a s than b s. If n more b s than a s have been read, the stack will hold 2n B s. When an a is read with an A or C on the top of the stack, an A is pushed onto the stack. This is accomplished by the transition to q 2. If a B is on the top of the stack, the stack is popped removing one b. If a b is read with a C or B on the stack, two B s are pushed onto the stack. Processing a b with an A on the stack pops the A. The lone accepting state of the automation is q 5. If the input string has twice as many a s as b s, the transition to q 5 pops the C, terminates the computation, and accepts the string. 5

ba/λ, ab/λ q 0 q 1 aa/a, ac/c q 2 λλ/a λλ/b λλ/b bb/b bc/c λc/λ q 4 q 3 q 5 aλ/a ba/λ q 2 q 3 e) aλ/λ bλ/λ aλ/a ba/λ cλ/λ q 2 q 3 q 4 q 5 f) aλ/λ bλ/b cb/λ aλ/a ba/λ bλ/λ bλ/λ q 2 λa/λ g) q 3 λa/λ h) The language L = {a i b j 0 i j 2 i} is generated by the context-free grammar S asb λ B bb b The B rule generates one or two b s for each a. A pushdown automaton M that accepts L uses the a s to record an acceptable number of matching b s on the stack. Upon processing an a, the computation nondeterministically pushes one or two A s onto the stack. The transitions 6

of M are δ(q 0,a,λ) = {[q 1,A]} δ(q 0,λ,λ) = {[q 3,λ]} δ(q 0,a,λ) = {[q 0,A]} δ(q 0,b,A) = {[q 2,λ]} δ(q 1,λ,λ) = {[q 0,A]} δ(q 2,b,A) = {[q 2,λ]} The states q 2 and q 3 are the accepting states of M. The null string is accepted in q 3. For a nonnull string a i b j L, one of the computations will push exactly j A s onto the stack. The stack is emptied by processing the b s in q 2. The state diagram of the PDA is aλ/a aλ/a λλ/a ba/λ q 3 q 2 ba/λ i) aλ/a ba/λ ca/λ q 0 q 1 q 2 aλ/a, bλ/b aa/λ, bb/λ j) aλ/λ, bλ/λ, 4. (7.7, 10 points) Let L be the language {w {a,b} w has a prefix containing more b s than a s.}. For example, baa, abba, abbaaa L, but aab, aabbab / L. a) Construct a PDA that accepts L by final state. b) Construct a PDA that accepts L by empty stack. Solution: aλ/a, ba/λ aλ/λ, bλ/λ a) λλ/b bb/λ q 2 aλ/a, ba/λ aλ/λ, bλ/λ b) λλ/b bb/λ q 2 7

5. (7.12, 20 points) Use the technique of Theorem 7.3.1 to construct a PDA that accepts the languages of the Greibach normal form grammar. S aaba abb A ba b B cb c Solution: The state diagram for the extended PDA obtained from the grammar is Q = {q 0,q 1 } Σ = {a,b,c} Γ = {A,B} F = {q 1 } δ(q 0,a,λ) = {[q 1,ABA],[q 1,BB]} δ(q 1,b,A) = {[q 1,A],[q 1,λ]} δ(q 1,c,B) = {[q 1,B],[q 1,λ]} ba/λ, ba/a, cb/λ, cb/b aλ/aba, aλ/bb 6. (7.15, 20 points) Let M be the PDA in Example 7.1.1. Q = {q 0,q 1 } Σ = {a,b,c} Γ = {A,B} F = {q 1 } δ(q 0,a,λ) = {[q 0,A]} δ(q 0,b,λ) = {[q 0,B]} δ(q 0,c,λ) = {[q 1,λ]} δ(q 1,a,A) = {[q 1,λ]} δ(q 1,b,B) = {[q 1,λ]} aλ/a, bλ/b aa/λ, bb/λ q 0 cλ/λ q 1 a) Trace the computation in M that accepts bbcbb. b) Use the technique from Theorem 7.3.2 to construct a grammar G that accepts L(M). c) Give the derivation of bbcbb in G. Solution: a) q 0 bbcbb λ q 0 bcbb B q 0 cbb BB q 1 bb BB q 1 b B q 1 λ λ b) First we add transitions to M as follows. 8

δ(q 0,a,λ) = {[q 0,A]} δ(q 0,a,A) = {[q 0,AA]} δ(q 0,a,B) = {[q 0,AB]} δ(q 0,b,λ) = {[q 0,B]} δ(q 0,b,A) = {[q 0,BA]} δ(q 0,b,B) = {[q 0,BB]} δ(q 0,c,λ) = {[q 1,λ]} δ(q 0,c,A) = {[q 1,A]} δ(q 0,c,B) = {[q 1,B]} δ(q 1,a,A) = {[q 1,λ]} δ(q 1,b,B) = {[q 1,λ]} Second the rules of the equivalent grammar G and the transition from which they were constructed are presented in Table 1. c) [q 0,bbcbb,λ] S q 0,λ,q 1 [q 0,bcbb,B] b q 0,B,q 1 [q 0,cbb,BB] bb q 0,B,q 1 q 1,B,q 1 [q 1,bb,BB] bbc q 1,B,q 1 q 1,B,q 1 [q 1,b,B] bbcb q 1,λ,q 1 q 1,B,q 1 bbcb q 1,B,q 1 [q 1,λ,λ] bbcbb q 1,λ,q 1 bbcbb 7. (7.17, 20 points) Use the pumping lemma to prove that each of the following languages is not context-free. a) {a k k is a perfect square} b) {a i b j c i d j i,j 0} c) {a i b 2i a i i 0} d) {a i b j c k 0 < i < j < k < 2i} e) {ww R w w {a,b} } f) The set of finite-length prefixes of the infinite string abaabaaabaaaab ba n ba n+1 b Solution: a) Assume that language L consisting of strings over {a} whose lengths are a perfect square is context-free. By the pumping lemma, there is a number k such that every string in L with length k or more can be written uvwxy where 9

Transition Rule S q 0,λ,q 1 δ(q 0,a,λ) = {[q 0,A]} q 0,λ,q 0 a q 0,A,q 0 q 0,λ,q 1 a q 0,A,q 1 δ(q 0,a,A) = {[q 0,AA]} q 0,A,q 0 a q 0,A,q 0 q 0,A,q 0 q 0,A,q 0 a q 0,A,q 1 q 1,A,q 0 q 0,A,q 1 a q 0,A,q 0 q 0,A,q 1 q 0,A,q 1 a q 0,A,q 1 q 1,A,q 1 δ(q 0,a,B) = {[q 0,AB]} q 0,B,q 0 a q 0,A,q 0 q 0,B,q 0 q 0,B,q 0 a q 0,A,q 1 q 1,B,q 0 q 0,B,q 1 a q 0,A,q 0 q 0,B,q 1 q 0,B,q 1 a q 0,A,q 1 q 1,B,q 1 δ(q 0,b,λ) = {[q 0,B]} q 0,λ,q 0 b q 0,B,q 0 q 0,λ,q 1 b q 0,B,q 1 δ(q 0,b,A) = {[q 0,BA]} q 0,A,q 0 b q 0,B,q 0 q 0,A,q 0 q 0,A,q 0 b q 0,B,q 1 q 1,A,q 0 q 0,A,q 1 b q 0,B,q 0 q 0,A,q 1 q 0,A,q 1 b q 0,B,q 1 q 1,A,q 1 δ(q 0,b,B) = {[q 0,BB]} q 0,B,q 0 b q 0,B,q 0 q 0,B,q 0 q 0,B,q 0 b q 0,B,q 1 q 1,B,q 0 q 0,B,q 1 b q 0,B,q 0 q 0,B,q 1 q 0,B,q 1 b q 0,B,q 1 q 1,B,q 1 δ(q 0,c,λ) = {[q 1,λ]} q 0,λ,q 0 c q 1,λ,q 0 q 0,λ,q 1 c q 1,λ,q 1 δ(q 0,c,A) = {[q 1,A]} q 0,A,q 0 c q 1,A,q 0 q 0,A,q 1 c q 1,A,q 1 δ(q 0,c,B) = {[q 1,B]} q 0,B,q 0 c q 1,B,q 0 q 0,B,q 1 c q 1,B,q 1 δ(q 1,a,A) = {[q 1,λ]} q 1,A,q 0 a q 1,λ,q 0 q 1,A,q 1 a q 1,λ,q 1 δ(q 1,b,B) = {[q 1,λ]} q 1,B,q 0 b q 1,λ,q 0 q 1,B,q 1 b q 1,λ,q 1 q 0,λ,q 0 λ q 1,λ,q 1 λ Table 1: The rules of the equivalent grammar G and the transition from which they were constructed (Problem 7.15 (b)) 10

(i) length(vwx) k (ii) v and x are not both null (iii) uv i wx i y L for all i 0. The string z = a k2 must have a decomposition uvwxy that satisfies the preceding conditions. Consider the length of the string uv 2 wx 2 y obtained by pumping uvwxy. length(z) =length(uv 2 wx 2 y) =lenght(uvwxy) + length(v) + length(x) =k 2 + length(v) + length(x) k 2 + k <(k + 1) 2 Since the length of z is greater than k 2 but less than (k + 1) 2, we conclude that z / L and that L is not context-free. b) Assume that language L = {a i b j c i d j i,j 0} is context-free. By the pumping lemma, there is a number k such that every string in L with length k or more can be written uvwxy where (i) length(vwx) k (ii) v and x are not both null (iii) uv i wx i y L for all i 0. The string z = a k b k c k d k must have a decomposition uvwxy that satisfies the preceding conditions. Consider the string uv 2 wx 2 y obtained by pumping uvwxy. Since v and x are not both null by condition (ii), we have that vwx contains at least one terminal. Without loss of generality, assume vwx contains a terminal which is either a or c (similar argument for the case that the terminal is either b or d). Condition (i) requires the length of vwx to be at most k. This implies that vwx is a string that cannot contain both a and c types of terminal. Thus uv 2 wx 2 y increases the number of either a s or c s, but not the both, compared with uvwxy. Hence uv 2 wx 2 y / L, a contradiction. We conclude that L is not context-free. c) Assume that language L = {a i b 2i a i i 0} is context-free. By the pumping lemma, there is a number k such that every string in L with length k or more can be written uvwxy where (i) length(vwx) k (ii) v and x are not both null (iii) uv i wx i y L for all i 0. The string z = a k b 2k a k must have a decomposition uvwxy that satisfies the preceding conditions. Consider the string uv 2 wx 2 y obtained by pumping uvwxy. Since by assumption uv 2 wx 2 y L, we must have that the union of v and x contains both a type and b type of terminals. Otherwise it only increases one type of terminal while keeping the other the same, thereby no longer in L. Further more, condition (i) requires the length of vwx to be at most k. This implies that the substring vwx of z cannot contain a s from both sides of the b s substring. Therefore uv 2 wx 2 y only increases the number of a s either preceding or after b s, but not both. Hence uv 2 wx 2 y / L, and consequently, L is not context-free. 11

d) Assume that language L = {a i b j c k 0 < i < j < k < 2i} is context-free. By the pumping lemma, there is a number k such that every string in L with length k or more can be written uvwxy where (i) length(vwx) k (ii) v and x are not both null (iii) uv i wx i y L for all i 0. Without loss of generality, we assume k > 2, since we can always increase k while maintaining the three conditions above. Then the string z = a k b k+1 c k+2 is in L and must have a decomposition uvwxy that satisfies the preceding conditions. Consider the string uv k wx k y obtained by pumping uvwxy. Condition (i) requires the length of vwx to be at most k. This implies that vwx is a string containing only one type of terminal or the concatenation of either a and b types, or b and c types. If c is not contained in vwx, pumping v and x only increases the number of a s or b s. Thus the new string cannot keep the number of a s less than the number of b s which is less than the number of c s, i.e. k + 2. If c is contained in vwx, then a is not contained in vwx. Thus uv k wx k y would have at least (k + 2) + (k 1) = 2k + 1 number of c s while keeping the number of a s the same, i.e. k. Hence uv k wx k y / L, and consequently, L is not context-free. e) Assume that language L = {ww R w w {a,b} } is context-free. By the pumping lemma, there is a number k such that every string in L with length k or more can be written uvwxy where (i) length(vwx) k (ii) v and x are not both null (iii) uv i wx i y L for all i 0. The string z = (a k b k )(a k b k ) R (a k b k ) = a k b 2k a 2k b k must have a decomposition uvwxy that satisfies the preceding conditions. By condition (ii), we have v and x have at least one terminal. Without loss of generality, assume that at least one a is in v or x (similar argument for the case of at least one b in v or x ). Condition (i) requires the length of vwx to be at most k. This implies that the substring vwx of z cannot contain a s from both sides of b 2k. If the a s in the substring vwx of z are before b 2k, then uv 2 wx 2 y increases the number of a s before b 2k while keeping the number of a s after b 2k the same as 2k. Hence uv 2 wx 2 y is no long in L = {ww R w w {a,b} }. If the a s in the substring vwx of z are after b 2k, we have uv 2 wx 2 y / L by similar argument. Therefore L is not context-free. f) Assume that the language L consisting of prefixes of string abaabaaabaaaab ba n ba n+1 b is context-free and let k be the number specified by the pumping lemma. Consider the string z = abaab ba k b, which is in the language and has length greater than k. Thus z can be written uvwxy where (i) length(vwx) k 12

(ii) v and x are not both null (iii) uv i wx i y L for all i 0. To show that the assumption that L is context-free produces a contradiction, we examine all possible decomposition of z that satisfy the conditions of the pumping lemma. By (ii), one or both of v and x must be nonnull. In the following argument we assume that v λ. Case 1: v has no b s. In this case, v consists solely of a s and lies between two consecutive b s. That is, v occurs in z in a position of the form ba n ba i va j ba n+2 b where i + length(v) + j = n + 1. Pumping v produces an incorrect number of a s following ba n b and, consequently, the resulting string is not in the language. Case 2: v has two or more b s. In this case, v contains a substring ba n b. Pumping v produces a string with two substrings of the form ba n b. No string with this property is in L. Case 3: v has one b. Then v can be written a i ba j and occurs in z as Pumping v produces the substring ba n 1 ba n i va n+1 j b ba n 1 ba n i a i ba j a i ba j a n+1 j b = ba n 1 ba n ba j+i ba n+1 b, which cannot occur in a string in L. Regardless of its makeup, pumping any nonnull substring v of z produces a string that is not in the language L. A similar argument shows that pumping x produces a string not in L whenever x is nonnull. Since one of v or x is nonnull, there is no decomposition of z that satisfies the requirements of the pumping lemma and we conclude that the language is not context-free. 13