Skip to content
Part IA Lent Term

Scaling Analysis and Log-Log Plots

Overview

Empirically assessing algorithmic complexity involves measuring runtime (or operation count) against input size and plotting the data. Log-log and log-linear plots reveal the functional form of the growth rate. This technique helps distinguish polynomial, linearithmic, and exponential behaviour without requiring a theoretical analysis.

The Log-Log Plot

If runtime T(n)T(n) follows a power law: T(n)cnkT(n) \approx c \cdot n^k, then taking logs:

logT(n)=logc+klogn\log T(n) = \log c + k \log n

On a log-log plot (both axes logarithmic), this is a straight line with slope kk. The constant cc determines the vertical intercept.

The slope kk directly estimates the polynomial degree of the algorithm’s growth. Linear regression on log-transformed data can estimate kk from empirical measurements.

Recognising Growth Patterns

On a log-log plot:

Curve shapeGrowth rate
Flat horizontal lineΘ(1)\Theta(1) (constant)
Gentle upward curve (concave)Θ(logn)\Theta(\log n)
Straight line with slope 1Θ(n)\Theta(n)
Straight line with slope slightly >> 1Θ(nlogn)\Theta(n \log n) (appears nearly straight but slightly curved on log-log)
Straight line with slope 2Θ(n2)\Theta(n^2)
Near-verticalΘ(2n)\Theta(2^n) (exponential)

On a log-linear plot (y-axis logarithmic, x-axis linear), exponential growth appears as a straight line: logT(n)=logc+nloga\log T(n) = \log c + n \log a for T(n)=canT(n) = c \cdot a^n.

Example: Heart Rate and Lifespan

A classic data set from Levine (1997, Journal of the American College of Cardiology) plots resting heart rate against average lifespan across mammal species. The raw scatter plot appears hyperbolic, suggesting an inverse relationship:

heart rate×lifespanconstant\text{heart rate} \times \text{lifespan} \approx \text{constant}

Equivalently, log(heart rate)+log(lifespan)=constant\log(\text{heart rate}) + \log(\text{lifespan}) = \text{constant}. A log-log plot transforms this into a straight line with slope 1-1, confirming the relationship heart rate(lifespan)1\text{heart rate} \propto (\text{lifespan})^{-1}. This is the same technique applied to biological scaling rather than algorithmic scaling.

Applying to Algorithm Analysis

Given empirical timing data for various input sizes nin_i with measured runtimes tit_i:

  1. Plot (logni,logti)(\log n_i, \log t_i).
  2. Fit a linear regression to estimate the slope kk.
  3. If k1k \approx 1, the algorithm is Θ(n)\Theta(n). If k2k \approx 2, it is Θ(n2)\Theta(n^2).

Caution: Θ(nlogn)\Theta(n \log n) does not produce a perfectly straight line on a log-log plot; it is slightly curved. To distinguish nlognn \log n from nn, you can plot T(n)/nT(n)/n against logn\log n — the former should appear linear.

Summary

PropertyValue
PurposeEmpirically determine algorithmic growth rate
Power law cnkc n^kStraight line with slope kk on log-log
ExponentialStraight line on log-linear
nlognn \log nSlightly curved on log-log; linear on T(n)/nT(n)/n vs. logn\log n
Slope <0< 0Decreasing function (e.g. inverse relationship)