hw01solutions - CSE 331 Spring 2008 Homework 1 Solutions 1....

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

View Full Document Right Arrow Icon
CSE 331 Spring 2008 Homework 1 Solutions 1. (a) The following running times for the three algorithms were obtained on arctic. Your times will probably be slightly different. The source code used to obtain these times is available in the file hw1_prob1.cpp . For the cases where N = 3200 and N = 6400, the call to the first algorithm was commented out: it would have taken more than an hour to execute! All times are given in seconds. N Algorithm 1 Algorithm 2 Algorithm 4 100 0.134119 0.007796 0.000151 200 1.0301 0.030165 0.000453 400 7.82168 0.121277 0.000581 800 61.5979 0.468062 0.001165 1600 485.929 1.87814 0.002303 3200 N/A 7.44625 0.004824 6400 N/A 29.9456 0.009402 (b) Whenever N doubles, the running time of algorithm 1 increases by about a factor of 8. This behavior suggests a polynomial running time. Since 8 = 2 3 , a good guess for the complexity of algorithm 1 would be Θ(N 3 ). The running time of algorithm 2 increases by a factor of 4 when N doubles. Noting that 4 = 2 2 , it seems likely that the complexity of algorithm 2 is Θ(N 2 ). Algorithm 3's running time appears to grow linearly with N. Therefore, it is probably Θ(N). (c) After modifying the subsequence functions slightly to count the number of times that the innermost loop was executed, the following execution counts were obtained. The execution count for these algorithms will always be the same for a given input size, so you should have the same results. The execution counts for the first algorithm with N = 3200 and N = 6400 were obtained on adriatic using a 64-bit long long integer. N Algorithm 1 Algorithm 2 Algorithm 4 100 171700 5050 100 200 1353400 20100 200 400 10746800 80200 400 800 85653600 320400 800 1600 683947200 1280800 1600 3200 5466454400 5121600 3200 6400 43711148800 20483200 6400
Background image of page 1

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

View Full DocumentRight Arrow Icon
These figures agree with the complexities guessed in part (b). The execution count of the innermost loop in algorithm 1 increases by a factor of about 8 every time N doubles. Since the execution counts are determined by the algorithm itself and are not system-dependent like the running times, this provides stronger evidence that algorithm 1 is Θ(N 3 ). In fact, applying a cubic regression function to the numbers here shows that the execution count can be exactly modeled by the function (N 3 + 3N 2 + 2N) / 6. Like the running time, the execution count of algorithm 2 increases by a factor of about four
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/25/2008 for the course CSE 331 taught by Professor M.mccullen during the Spring '08 term at Michigan State University.

Page1 / 4

hw01solutions - CSE 331 Spring 2008 Homework 1 Solutions 1....

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

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