- Experiments need an implementation, depend on hardware/software, and can’t cover all inputs → theoretical analysis.
- Theoretical analysis: count primitive operations as a function of input size n; take the worst case.
- Primitive operations: assignment, arithmetic, comparison, array index, method call, return.
- Seven functions: constant, log n, n, n log n, n², n³, 2ⁿ.
🎯 How this can come up · 1 question
Which grows fastest?
Correct: 2ⁿ.
- Changing hardware changes T(n) by a constant factor but not the growth rate.
- f(n) is O(g(n)) if f(n) ≤ c·g(n) for all n ≥ n₀ (some positive c, n₀).
🎯 How this can come up · 2 questions
7n − 2 is:
It is also O(n²), but the tight bound is O(n).
3n³ + 20n² + 5 is:
Correct: O(n³).
- Big-Oh is an UPPER bound on the growth rate.
- Asymptotic analysis: find the worst-case number of primitive operations, express it in Big-Oh.
Asked in a real exam
🎯 How this can come up · 2 questions
for (i = 0; i < n; i++) for (j = 0; j < n; j++) sum++; is:
Correct: O(n²).
for (i = 1; i < n; i *= 2) sum++; is:
Correct: O(log n).
- prefixAverage1 recomputes each sum → 1 + 2 + … + n → O(n²).
- prefixAverage2 keeps a running sum → O(n).
🎯 How this can come up · 1 question
Why is the second prefix-averages algorithm linear?
It keeps a running total, adding one element per step instead of re-summing all earlier elements, so each of the n steps is constant time: O(n) instead of O(n²).
- Big-Omega = lower bound; Big-Theta = tight bound (both upper and lower).
🎯 How this can come up · 1 question
f(n) is Θ(g(n)) means:
Correct: f is both O(g) and Ω(g).
No slides match this filter.