You are being asked to do a lot.
Analytical
Count through the code and compute the Big-O and Big-Ω. If they are pretty close to the same thing, then you have a Big-Ɵ. (This is the easy part.)
Big-O (and others) are not interested in constant operations (like *=). They are interested in
loops (and recursion, which is a form of loop). In other words, the number of things you do per loop is not important. The number of times you loop
is important.
Examples:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
int x = 12; // O(1) — totally unimportant
for (int n = 0; n < N; n++) // O(N) — this is important!
x = 12;
for (int n = 0; n < N1; n++) // O(N1) ...
{
int x = 12;
for (int m = 0; m < N2; m++) // × O(N2) → O(N1×N2) → O(N²) — important!
}
for (int n = 0; n < N; n++) // O(N) ...
{
int x = 12;
for (int m = n; m < N; n++) // × O(log N) → O(N log N) — important!
}
|
(My explanations aren’t always the best. I just found this SO answer which is brilliant.
https://stackoverflow.com/a/2307314/2706707)
Empirical
That’s another word for “observational”. You must construct a number of different inputs designed to try to get both best and worst behavior from the program. Observe the actual behavior and report whether or not the inputs support or contradict your Big-O/Ω/Ɵ analyses.
You would probably be able to just use a simple clock timer to see how long the program takes to complete on a given input. Make sure to push the limits of your program (so that you can overcome the cost of I/O operations).
If you are smart, you might mention that the best case behavior includes the cost of I/O, show that the cost of I/O is the same for both best and worst case behavior (because the same amount of I/O is being done for both cases), then analyze the difference between the best case and all other results.
One last note about time analysis: the first time you run the program will always cost more. Make sure to run each case multiple times in a row. Discount the first time you run each case and average the remaining times to get a mean representative time for that specific case. Impress your professor by putting this in your “Procedures” section and the reasons for doing it.
Hope this helps.