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 follows a power law: , then taking logs:
On a log-log plot (both axes logarithmic), this is a straight line with slope . The constant determines the vertical intercept.
The slope directly estimates the polynomial degree of the algorithm’s growth. Linear regression on log-transformed data can estimate from empirical measurements.
Recognising Growth Patterns
On a log-log plot:
| Curve shape | Growth rate |
|---|---|
| Flat horizontal line | (constant) |
| Gentle upward curve (concave) | |
| Straight line with slope 1 | |
| Straight line with slope slightly 1 | (appears nearly straight but slightly curved on log-log) |
| Straight line with slope 2 | |
| Near-vertical | (exponential) |
On a log-linear plot (y-axis logarithmic, x-axis linear), exponential growth appears as a straight line: for .
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:
Equivalently, . A log-log plot transforms this into a straight line with slope , confirming the relationship . 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 with measured runtimes :
- Plot .
- Fit a linear regression to estimate the slope .
- If , the algorithm is . If , it is .
Caution: does not produce a perfectly straight line on a log-log plot; it is slightly curved. To distinguish from , you can plot against — the former should appear linear.
Summary
| Property | Value |
|---|---|
| Purpose | Empirically determine algorithmic growth rate |
| Power law | Straight line with slope on log-log |
| Exponential | Straight line on log-linear |
| Slightly curved on log-log; linear on vs. | |
| Slope | Decreasing function (e.g. inverse relationship) |