CS 415, Section 002 | Sonoma State University | Spring, 2022 |
Algorithm Analysis
|
||
Instructor: Henry M. Walker
Lecturer, Sonoma State University |
Instructions:
Many Web sites provide summation formulas for sums of the form:
for various constants a (e.g., a = 1, 2, 3, ...).
Once such reference is "Summation formulas" from Tripod
Consider the following code segment:
int sum = 0; for (int i=1 ; i <= n * n; i+= n) for (int j=1 ; j <= 10 ; j++) for (int k=0; k < i ; k++ ) sum++;
Develop an algebraic expression for the function f(n) that describes the time required for processing, given n. (If the time depends upon specific details of input, consider a "worst-case" analysis.)
Determine if the resulting code has O(n), O(n2), O(n3), O(n4), and O(n5). In each case, give a careful argument justifying your conclusions.
Determine if the resulting code has Θ(n), Θ(n2), Θ(n3), Θ(n4), and Θ(n5). In each case, give a careful argument justifying your conclusions.
Naturally, the running time of this code segment will depend upon the particular computer and compiler used. On a particular machine and compiler, suppose the running time for this code is 8 seconds when n is 1000. Based on your answers earlier in this problem, estimate the likely time for the running of this code when n is 2000 and when n is 5000. Justify your answer briefly.
Consider the C program simple-loop-analysis.c.
Give a micro-analysis of the iter_compute procedure to describe its run time.
On the basis of your answer to part a, determine if the resulting code has Θ(n), Θ(n2), Θ(n3), Θ(n4), and Θ(n5). In each case, give a careful argument justifying your conclusions.
Develop a recurrence relation that describes the run time of rec_compute procedure. (For this problem, you need not solve the recurrence relation — but wait until later in the semester.)
On a particular machine and compiler, suppose the running time for this code is 5 seconds when n is 800. Based on your answers earlier in this problem, estimate the likely time for the running of this code when n is 1600 and when n is 8000. Justify your answer briefly.
Review the recurrence examples from Appendix B in the text, and study the discussion of the Master Theorem that begins in page 490.
Notes:
created December, 2021 revised December-January 2021 |
|
For more information, please contact Henry M. Walker at walker@cs.grinnell.edu. |