Which grows fastest?
Algorithm Analysis
Measuring running time experimentally and its limits, primitive operations and theoretical analysis, the seven important functions, growth rates, Big-Oh (and Big-Omega, Big-Theta), and the prefix-averages example (quadratic vs. linear). Quiz 2 asked for the Big-O of code statements.
How to read this page
Every original slide is shown unchanged. Yellow marks on a slide point to a numbered note: hover or tap a mark to jump to its note, and hover a note to see its marks. Questions tagged Past exam appeared on a real paper; Prediction questions are likely angles, not confirmed. Pick an answer to each question: a wrong pick tells you why it is wrong, so you can try again.
All 53 slides
- 1 Analysis of Algorithms
- 2 Running time
- 3 Measuring the running time
- 4 Measuring the running time
- 5 Measuring the running time
- 6 begian
- 7 Slide 7
- 8 a
- 9 9000
- 10 Limitations of Experiments
- 11 Challenges
- 12 Goals of Algorithm analysis
- 13 Running Time
- 14 Theoretical Analysis
- 15 Primitive Operations
- 16 n
- 17 iinssciswi.swasisst.sn
- 18 Cost of basic operations
- 19 Cost of basic operations
- 20 Example: 1-S UM
- 21 Seven Important Functions
- 22 Functions Graphed Using “Normal” Scale
- 23 i
- 24 Estimating Running Time
- 25 Growth Rate of Running Time
- 26 Why Growth Rate Matters
- 27 Practical implications of order-of-growth 2
- 28 Practical implications of order-of-growth
- 29 Practical implications of order-of-growth
- 30 Comparison of Two Algorithms
- 31 Constant Factors
- 32 Big-Oh Notation
- 33 w.c.sfens.sn
- 34 fen
- 35 Slide 35
- 36 not
- 37 More Big-Oh Examples
- 38 5511
- 39 ni von
- 40 Big-Oh and Growth Rate
- 41 imago
- 42 Asymptotic Algorithm Analysis
- 43 Computing Prefix Averages
- 44 Prefix Averages (Quadratic)
- 45 Arithmetic Progression
- 46 Prefix Averages 2 (Linear)
- 47 Math you need to Review
- 48 Relatives of Big-Oh
- 49 Intuition for Asymptotic Notation
- 50 Example Uses of the Relatives of Big-Oh
- 51 lognio
- 52 Slide 52
- 53 cn.zstcn.sn
Analysis of Algorithms
Notes
Tip Growth rates, slow → fast: 1 < log n < n < n log n < n² < n³ < 2ⁿ. Drop constants and lower-order terms.
Limitations of Experiments
Notes
Experiments need an implementation, depend on hardware/software, and can’t cover all inputs → theoretical analysis.
Theoretical Analysis
Notes
Theoretical analysis: count primitive operations as a function of input size n; take the worst case.
Primitive Operations
Notes
Primitive operations: assignment, arithmetic, comparison, array index, method call, return.
Seven Important Functions
Notes
Tip Growth rates, slow → fast: 1 < log n < n < n log n < n² < n³ < 2ⁿ. Drop constants and lower-order terms.
Exam angle
Big-Oh Notation
Notes
f(n) is O(g(n)) if f(n) ≤ c·g(n) for all n ≥ n₀ (some positive c, n₀).
Exam angle
7n − 2 is:
- It is also O(n²), but the tight bound is O(n).
3n³ + 20n² + 5 is:
Asymptotic Algorithm Analysis
Exam angle
Big-O of each statement
for (i = 0; i < n; i++) for (j = 0; j < n; j++) sum++; is:
for (i = 1; i < n; i *= 2) sum++; is:
Prefix Averages (Quadratic)
Notes
prefixAverage1 recomputes each sum → 1 + 2 + … + n → O(n²).
Prefix Averages 2 (Linear)
Notes
prefixAverage2 keeps a running sum → O(n).
Exam angle
Why is the second prefix-averages algorithm linear?
Compare with the model answer
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²).
Relatives of Big-Oh
Notes
Big-Omega = lower bound; Big-Theta = tight bound (both upper and lower).
Exam angle
f(n) is Θ(g(n)) means: