{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

midtermsampsol

midtermsampsol - 1(a none(b W X(c W X(c none 2(a Let n0 = 1...

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

View Full Document Right Arrow Icon
tshughes 1. (a) none; (b) W X; (c) W X; (c) none 2. (a) Let n 0 = 1 and c = 1. Then 1 /n 2 c · 1 /n for all n n 0 (b) f ( n ) = 1 (c) Suppose, to arrive at a contradiction, that f ( n ) Ω( n 2 ). Then constants c, n 0 > 0 such that n n 0 , f ( n ) c · n 2 . But let n = max( n 0 , 1 /c , 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) 0 [ 23 ] (d) 0 [ ] 1 [ ] 1 [ ] 1 [ ] 1 [ ] 2 [ ] 2 [ ] 2 [ ] 2 [ 23 ] 3 [ 23-+->[ 18 ] 3 [ 23 ] 3 [ 18 ] 3 [ 18 ] 4 [ 4 ] 4 [ 4 ] 4 [ 4 ] 4 [ 4 ] 7. (a) [ 3 , 5 ] (b) [ 3 ] (c) [ 3 ] (d) [ 6 ] / \ / \ / \ [ 1 ] [ 5 ] [1,2] [5,6] [ 3 ] [ 8 ] / \ / \ [1,2] [5] [7] [9] (e) A height 0 tree has at most 4 keys. A height 2 tree has at least 17 keys. Therefore T must have height 1. 8. (a) 5-sort(A) 1. 5-median-partition(A); 2. if A[0] > A[1] then A[0],A[1] := A[1],A[0] 3. if A[3] > A[4] then A[3],A[4] := A[4],A[3]
Image of page 1
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern