HTW Berlin |
Exercise
3: Execution Times
|
Finger Exercises
Please have these completed before coming to the lab. BTW, I like questions like this on the exam...
1. Programs A and B are analyzed and are found to have worst-case running times no greater than 150 N log N and N2 , respectively. Answer the following questions, if possible:
1. Which program has the better
guarantee on the running time for large values of N (N > 10 000)?
2. Which program has the better guarantee on the running time
for small values of N (N < 100)?
3. Which program will run faster on average for N = 1000?
4. Is it possible that program B will run faster than
program A on all possible inputs?
2. An algorithm takes 0.5 ms for input size 100. How long will it take for input size 500 if the running time is the following:
1. linear
2. O (N log N)
3. quadratic
4. cubic
3. An algorithm takes 0.5 ms for input size 100. How large a problem can be solved in 1 min if the running time is the following:
1. linear
2. O (N log N)
3. quadratic
4. cubic
4. Order the following functions by growth
rate, and indicate which, if any, grow at the same rate.:
N, square root of N, N1.5, N2 , N log N, N log
log N, N log2 N, N log (N2), 2/N, 2N, 2N/2,
37,N3, N2 log N
Lab exercises:
These are the required exercises for this week. Work in groups of two, doing pair programming, and turn in the same report for each member of the pair. Remember to put your names on the report. You can continue to use BlueJ, or move to Eclipse, if you wish.
// Fragment #1 for ( int i = 0; i < n; i ++) sum++; // Fragment #2 // Fragment #3 // Fragment #4 // Fragment #5 // Fragment #6 // Fragment #7 // Fragment #8 |
For the bored:
Try the sequence that is generated by the following method: public int sequence (int n) { int sum = 0; int i = n; while (i > 1) { if (i%2 == 0) { i = i/2; } else { i = 3*i + 1; } sum++; } return sum; }Can you determine the complexity of the number of steps needed for the loop to terminate for various values of n? Can you find out more about this sequence?
Your report is due by 10.00 pm the night before your next lab! As in Informatics 1, We are more interested in process than in product, although we are now getting more interested in products as well. Your report should include any collaborators, summarize what you learned, and note the time you invested in this exercise. How many lines of code did you write for each exercise? Record this in your report.