Chapter 9Complexity Analysisslides.en.pdf:203-204

Performance Scaling

How algorithms grow with input size

Concept

Before formal definitions, let's build intuition. Suppose you have an algorithm
that takes nn seconds on input of size nn. You scale the input by a factor
of 10 — what happens?

ScalingConstant 11Linear nnQuadratic n2n^2Exponential 2n2^n
n=10n = 101101001024
n=100n = 100110010 0001.27×10301.27 \times 10^{30}
n=1000n = 10001100010610^6astronomically huge

The lesson. A linear-time algorithm on n=1000n = 1000 is 10× slower than on
n=100n = 100. A quadratic one is 100× slower. An exponential one becomes
impossible.

Practical examples:
- Looking up a name in a sorted list (binary search): logarithmic.
- Sorting nn items: O(nlogn)O(n \log n) — near-linear.
- Checking all pairs in a list: quadratic.
- Solving a traveling salesman by brute force: factorial.

The "one year" example. Suppose algorithm A does nn operations,
algorithm B does 100n100n operations. On a machine doing 10710^7 ops/sec, B is
100× slower than A. If A takes 5 minutes, B takes 500 minutes — about 8
hours. If C does 7n27n^2 operations, on n=1000n = 1000 it does 7×1067 \times 10^6
ops — fine. On n=106n = 10^6 it does 7×10127 \times 10^{12} — about 8 days.

The growth class matters far more than constants. We capture this formally
with Landau sets next.

Animation — big o growth
Transcript — click a line to jump8 cues
  1. 0.0sGrowth of Common Functions
  2. 0.8sAxes drawn: n on the horizontal, f(n) on the vertical.
  3. 1.8sConstant 1: flat baseline.
  4. 2.6slog n: barely rises across the entire range.
  5. 3.4sn: a steady diagonal line.
  6. 4.2sn squared: curves up gently at first, steepens later.
  7. 5.0s2 to the n: explodes exponentially and dwarfs every other curve.
  8. 6.4sExponential eventually overtakes everything.
Worked example
Step 0 of 2
Practice — score 100% to advance
Multiple choice
Q1
If an algorithm does n2n^2 operations and nn grows 10×, the work grows by…
Q2
Why is 2n2^n considered a 'bad' growth rate?
Q3
Binary search on a sorted list of nn items takes about ___ steps.
Q4
What matters MORE for large inputs: the constant factor or the growth class?
Order the steps
Arrange these proof steps in the correct order using the arrows.
1
O(logn)O(\log n) — logarithmic. Binary search. Doubling nn adds one step.
2
O(1)O(1) — constant. Hash table lookup. Independent of nn.
3
O(n)O(n) — linear. Scan a list once. Doubling nn doubles the work.
4
O(n2)O(n^2) — quadratic. All pairs. Doubling nn quadruples the work.
5
O(2n)O(2^n) — exponential. Subsets. Adding 1 to nn doubles the work.
Loading…