Topic 2.12 — Informal Run-Time Analysis

Goal: describe how an algorithm’s running time grows as input size grows (informally), using ideas like “linear” vs “quadratic,” especially by analyzing loop structures.

The big idea

Run-time analysis isn’t about exact seconds—it’s about growth. As input size (n) gets bigger, how does the number of operations grow?

AP CSA keeps this informal: you mainly compare algorithms by recognizing patterns.

Common growth categories

Pattern Typical description What it “feels like”
O(1) constant doesn’t depend on n
O(n) linear proportional to n
O(n^2) quadratic n × n work (often nested loops)

You don’t need advanced proofs—just recognize which category fits.

Constant time: O(1)

A fixed number of operations, regardless of input size.

int x = a + b;
if (x > 10) {
  y++;
}

Linear time: O(n)

One loop that goes through n items once.

int sum = 0;
for (int i = 0; i < n; i++) {
  sum += i;
}

Quadratic time: O(n²)

A nested loop where each item is paired with many others.

int count = 0;
for (int i = 0; i < n; i++) {
  for (int j = 0; j < n; j++) {
    count++;
  }
}

Inner body runs about n * n times.

Don’t overthink constants

In informal analysis, you usually ignore constant factors and small additions.

// Still O(n), not “O(2n)”
for (int i = 0; i < n; i++) { ... }
for (int i = 0; i < n; i++) { ... }

How to analyze quickly on AP

  1. Identify how many times the main work repeats.
  2. One loop over n items → likely linear.
  3. Two nested loops over n → likely quadratic.
  4. If bounds aren’t exactly n, still classify by the growth pattern.

Quick self-check

  1. What’s the difference between “exact time” and “growth”?
  2. What kind of loop pattern usually creates O(n²)?
  3. Is two separate loops over n items linear or quadratic?
  4. What does O(1) mean in plain English?
  5. Why do we ignore constants in informal analysis?

← Back to Unit 2 topics