midtermsampsol

midtermsampsol - t s h u g h e s 1. (a) none; (b) W X; (c)...

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: t s h u g h e s 1. (a) none; (b) W X; (c) W X; (c) none 2. (a) Let n = 1 and c = 1. Then 1 /n 2 c 1 /n for all n n (b) f ( n ) = 1 (c) Suppose, to arrive at a contradiction, that f ( n ) ( n 2 ). Then constants c,n > 0 such that n n , f ( n ) c n 2 . But let n = max( n , d 1 /c e , 2). Then cn 2 n 2 1 = f ( n ), a contradiction. 3. Let the cost of steps 2 and 4 be c 1 and c 2 , respectively. The number of iterations of the inner while loop is at most log 2 i each time around, for a cost of c 2 log 2 i . From the outer for loop, the total cost is at most 2 n i =1 ( c 1 + c 2 log 2 i ) = 2 nc 1 + c 2 log 2 (2 n )!, which is O ( n log n ). 4. (b) A = [85 , 80 , 21 , 43 , 17 , 5 , 19 , 2 , 20]; (c) A = [43 , 20 , 21 , 2 , 17 , 5 , 19] 5. (a) T is an AVL Tree because it is a BST and all balance factors are- 1, 0 or 1. (b) 51 (c) 51 / \ / \ 35 65 35 62 / \ / \ / \ / \ 18 40 62 78 18 40 57 78 / \ \ / 57 63 86 65 6. (a) 0 [ ] (b) 0 [ 18 ] (c)...
View Full Document

This note was uploaded on 01/14/2012 for the course CS 246 taught by Professor Wormer during the Winter '08 term at Waterloo.

Ask a homework question - tutors are online