L06

Due by the end of today by midnight

Starter Files:


SUBMIT   /   Submission Summary

Counting Operations

Activity 1
Download the file Analysis.java. Run the program and examine the code. Take particular note of the formulas the program generates at the end, and whether they're "constant", "linear", or "quadratic". Add a comment at the bottom of the program stating what the formulas were for each method.
/* Original code: - Equation for Stupid is [formula goes here] ([order of magnitude goes here]) - Equation for Better is [formula goes here] ([order of magnitude goes here]) */

The two methods that fill the array (simulating counting to n) each have and return an opCount variable. But I wasn't very consistent with counting my operations. Normally, we only count operations that involve the data structure we're working with (in this case, the array).

For example, step 1 from fillIntelligently (where k is set to 1) really shouldn't be counted -- it doesn't involve any element of the array.

On the other hand, step 1 from fillStupidly (where array[0] is set to 1) should be counted -- it involves an element of the array.

Go thru fillStupidly and fillIntelligently and remove all opCount increments that don't involve operations on the array elements.

Rerun the program and note the new formulas found. Add a comment in the program indicating the new formulas found. Compare them to the old formulas you noted before. What's changed? What's the same?

Revised code: - Equation for Stupid is [formula goes here] ([order of magnitude goes here]). - Equation for Better is [formula goes here] ([order of magnitude goes here]) The ________ has changed, but the _______ is the same for each.

Activity 2
Using the new formulas you've generated, predict how many operations it will take to count to 50. Write your prediction into the comments at the bottom of the class.
Predicted number of steps to print to 50: - Stupid method: ____ - Better method: ____
Then add code to test your prediction for the new formulas. Write the actual result into the comment, along with a note reporting the accuracy of your estimate.
Measured number of steps to print to 50: - Stupid method: ____ - Better method: ____ My predictions were ____________.
Your predictions may have been accurate, inaccurate, or accurate for one but not the other. If either was not accurate, try to figure out what went wrong and try again!

Submit this/these files:


SUBMIT   /   Submission Summary