test question examples

test question examples - NOTE: As you may have noticed, we...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
NOTE: As you may have noticed, we use a lot of examples and diagrams in the lectures. So email is not an effective method to answer questions related to course material. Please DO NOT ask how to solve the following problems via email. Come to the office hours instead. 1. Order the following running time θ bounds by asymptotic growth rate in nondescending order. Indicate equality, if any. N 2 , 2 N , 25, Nlg(lgN), Nlg(N 2 ), N 2 lgN, N 3 , NlgN, and N! . 2. Solve the following recurrences by obtaining a θ bound for T(N) given that T(1) = θ(1) : a. T(N) = 2N - 1 + T(N-1) b. T(N) = N + T(N-3) c. T(N) = N 2 + T(N-1) 3. Perform a worst-case analysis of each of the following fragments and give a θ bound for the running time: 4. a. sum = 0; 5. for (int i = 0; i < N; i++) 6. for (int j = 0; j < i * i; j++) 7. for (int k = 0; k < j; k++) 8. sum++; 9. 10. b. sum = 0; 11. for (int i = 0; i < N; i++) 12. for (int j = 0; j < i * i; j++) 13. if (j % i == 0) 14. { 15. for (int k = 0; k < j; k++) 16. sum++; } 17. Mergesort does have a worst-case time of θ(NlgN) but its overhead (hidden in the constant factors) is high and this is manifested near the bottom of the recursion tree where many merges are made. Someone proposed that we stop the recursion once the size reaches K and switch to insertion sort at that point. Analyze this proposal (by modifying the recurrence analysis of standard mergesort) and prove that its running time
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/13/2011 for the course CSE 2011 taught by Professor Someone during the Winter '10 term at York University.

Page1 / 5

test question examples - NOTE: As you may have noticed, we...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online