hw9sol - Homework 9 Solution Problem 1 Assuming an...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Homework 9 Solution Problem 1 Assuming an increasing function T(n) satisfying T(n) = 4T(n /2)+2n. Estimate the growth of T(n) with the Master theorem. T(n)=4T(n/2)+2n a=4, b=2, c=2, d=1 a=4 > bd=21=2 ) = O(n2) T(n) = O( Problem 2 Assuming an increasing function T(n) satisfying T(n) = 2T(n/4)+2n. Estimate the growth of T(n) with the Master theorem. T(n)=2T(n/4)+2n a=2, b=4, c=2, d=1 a=2 < bd=41 =4 T(n) = O( ) = O(n) Problem 3 Chapter 7, Suppl. Exercise 14, page 516 Problem 4 Chapter 7, Suppl. Exercise 16, page 516 Simply divide the sequence into two halves then find the largest two elements in each half. At the end you need to return the largest two out of the four by twice comparisons because each half returns two elements. The base case for recursion is when the sequence contains one or two elements. Therefore, T(n)=2T(n/2)+2 Problem 5 Section 12.1, Exercise 4, page 794 G={V,T,S,P}, V={0,1,A,S}, T={0,1}, P={S→1S, S→00A, A→0A, A→0} a) 111000 S→1S→11S→111S→11100A→111000 b) 11001 Because of the productions in this grammar, 1 cannot be at the end of the string. c) {1n0m|n≥0, m≥3} Problem 6 Section 12.1, Exercise 8, page 794 G={V,T,S,P}, V={0,1,S}, T={0,1}, P={S→0S1, S→ λ} n=0, S→ λ n=1, S→0S1→0λ1 n=2, S→0S1→00S11→00 λ 11 n=k, S→0S1→00S11→…→0kλ 1k As shown above, the grammar can generate the set {0n1n|n=0,1,2,…} Problem 7 Section 12.1, Exercise 16, page 794 a) {1n|n≥0} G={V,T,S,P}, V={1,S}, T={1}, P={S→1S, S→λ} b) {10n|n≥0} G={V,T,S,P}, V={1,0,S,A}, T={0,1}, P={S→1A, A→0A,A→λ} c) {(11)n|n≥0} G={V,T,S,P}, V={1,S}, T={1}, P={S→11S,S→λ} Problem 8 Chapter 12, Suppl. Exercise 2, page 840 Let G =(V,T,S,P) be a grammar with alphabet V = (0,L,R,D,B), terminal symbol T = {0}, start symbol S, and production rules P ={S→LD0R, LD0→0, 0R→0, D0→00D, DR→BR, LB→LD, 0B→B0}. The initial production S→LD0R sets the stage. The nonterminal symbols L and R are left and right end markers. The nonterminal symbol D serves as a doubling operator. By traversing from left to right, D can double the number of existing 0s using the production D0→00D. The nonterminal symbol B allows one to walk back from the right end to the left end without changing the number of 0s using the production rule 0B→B0. The last two productions allow one to switch the directions. The second and third production allow one to terminate the process so that only terminal symbols remain whenever D is at the left end. Using n passes of D from left to right (each followed with a pass by B from right to left), we can obtain any string of 0 with 2n elements. For instance, S → LD0R → L00DR → L00BR → L0B0R →LB00R → LD00R → 00R → 00 ...
View Full Document

This note was uploaded on 11/05/2011 for the course CSCE 222 taught by Professor Math during the Spring '11 term at Texas A&M.

Ask a homework question - tutors are online