# hw0sol - CS 473 Homework 0(due Spring 2010 1(a I understand...

This preview shows pages 1–4. Sign up to view the full content.

CS 473 Homework 0 (due January 26, 2009) Spring 2010 1. (a) I understand the course policies. Rubric: No credit for HW0 without this sentence. But we graded and recorded everything else even if you omitted this sentence. We’ll retroactively restore credit for HW0 if you write the same sentence on HW1. (b) [5 pts] Solve the following recurrences. A ( n ) = 3 A ( n - 1 )+ 1 B ( n ) = B ( n - 5 )+ 2 n - 3 C ( n ) = 4 C ( n / 2 )+ p n D ( n ) = 3 D ( n / 3 )+ n 2 E ( n ) = E ( n - 1 ) 2 - E ( n - 2 ) 2 , where E ( 0 ) = 0 and E ( 1 ) = 1 [Hint: This is easy!] Solution: A ( n ) = Θ( 3 n ) — The recurrence unrolls into the geometric series n i = 1 3 i . Only the largest term in a geometric series matters for Θ( · ) bounds. B ( n ) = Θ( n 2 ) — The recurrence unrolls into the sum B ( n ) = Θ( n ) i =Θ( 1 ) Θ( i ) . C ( n ) = Θ( n 2 ) — Using recursion trees; the level sums are an increasing geometric series. D ( n ) = Θ( n 2 ) — Using recursion trees; the level sums are a decreasing geometric series. E ( n ) = Θ( 1 ) — The ﬁrst several values of E ( n ) are 0,1,1,0, - 1,1,0, - 1,1,0,. .., and the last three values repeat forever. ± Rubric: 1 point each; all or nothing. No proofs are required. 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CS 473 Homework 0 (due January 26, 2009) Spring 2010 (c) Sort the following functions from asymptotically smallest to asymptotically largest, indicating ties if there are any. n lg n p n 5 n p lg n lg p n 5 p n p 5 n 5 lg n lg ( 5 n ) 5 lg p n 5 p lg n p 5 lg n lg ( 5 p n ) lg p 5 n p lg ( 5 n ) Solution: p lg n ± lg p n lg n ± 5 p lg n ± p n p lg ( 5 n ) lg ( 5 p n ) ± n lg ( 5 n ) lg p 5 n 5 log 5 n ± 5 lg p n = p 5 lg n = n ( lg5 ) / 2 ± 5 lg n = n lg5 ± 5 p n ± p 5 n = ( p 5 ) n ± 5 n ± Rubric: 5 points max. - 1 / 2 for each misplaced, missing, or repeated function, but no negative scores. No proofs are necessary. 2
CS 473 Homework 0 (due January 26, 2009) Spring 2010 2. (a) What is the maximum possible depth of an n -node binary search tree? Give an exact answer, and prove that it is correct. Solution: If the elements are inserted in sorted order, the depth is n - 1. Every tree with n nodes has exactly n - 1 edges, so its depth cannot be more than n - 1. Thus, the maximum possible depth of an n -node binary tree is n - 1 . ± Rubric: 3 points max 1 point for answer n - 1 . All or nothing. 1 point for proving n - 1 . All or nothing. 1 point for proving n - 1 . All or nothing. This is not the only correct proof. (b) Exactly how many different insertion orders result in an n -node binary search tree with maximum possible depth? Prove your answer is correct. Solution: There are exactly 2 n - 1 binary trees with depth n - 1. Proof:

This preview has intentionally blurred sections. Sign up to view the full version.

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

## This note was uploaded on 04/18/2011 for the course CS 473 taught by Professor Chekuri,c during the Spring '08 term at University of Illinois, Urbana Champaign.

### Page1 / 9

hw0sol - CS 473 Homework 0(due Spring 2010 1(a I understand...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online