Time complexity

Growth rates, P and NP · Chapter 7

How fast do running times grow?

How long is that, at a billion steps per second?

Hover the chart to read exact step counts.

Big-O, in Sipser's words

f(n) = O(g(n)) if there are c > 0 and n0 such that f(n) ≤ c·g(n) for every n ≥ n0 (Definition 7.2). Constants and lower-order terms don't matter: 5n3 + 2n + 22 = O(n3).

f(n) = o(g(n)) if f(n)/g(n) → 0 (Definition 7.5). For example n log n = o(n2), and every polynomial nk is o(2n).

P is the class of languages decidable in polynomial time, O(nk) for some k, on a single-tape deterministic Turing machine (Definition 7.12).

Time complexity, hands on

Chapter 7 of Sipser measures how many steps a Turing machine needs as the input grows. This page compares growth rates, measures real machines from the Turing machines page, and shows why SAT answers are easy to check but seem hard to find.

Growth rates

  1. Tick the functions to compare and choose how far n goes.
  2. The log scale shows the difference between polynomial and exponential growth.
  3. The table turns step counts into time at a billion steps per second.

Counting steps

  1. Pick a machine, or the one you drew on the Turing machines page.
  2. The page runs it on every input of each length and records the worst case.
  3. Compare with n, n log n or n²: the ratio that levels off shows the growth rate.

Writing a formula

TypeMeans
∧, &, andand (between clauses)
∨, |, oror (inside a clause)
¬x, ~x, !x, x'not x
x1, x_2, avariables