Skip to content
Part IA Lent Term

The Potential Method

The potential method is the most powerful amortised analysis technique. It defines a potential function Φ\Phi mapping each state of the data structure to a real number, representing “stored energy”. Changes in potential pay for work.

Definition

A potential function Φ:ΩR\Phi: \Omega \to \mathbb{R} maps each possible data structure state to a real number, satisfying:

  1. Φ(D0)=0\Phi(D_0) = 0 for the initial (empty) state D0D_0
  2. Φ(D)0\Phi(D) \ge 0 for all states DD

For an operation that transforms state Di1D_{i-1} to DiD_i with actual cost cic_i, the amortised cost is:

c^i=ci+Φ(Di)Φ(Di1)\hat{c}_i = c_i + \Phi(D_i) - \Phi(D_{i-1})

Proof of Correctness

For a sequence of mm operations, starting from D0D_0:

i=1mc^i=i=1m(ci+Φ(Di)Φ(Di1))=i=1mci+Φ(Dm)Φ(D0)\sum_{i=1}^{m} \hat{c}_i = \sum_{i=1}^{m} \big(c_i + \Phi(D_i) - \Phi(D_{i-1})\big) = \sum_{i=1}^{m} c_i + \Phi(D_m) - \Phi(D_0)

Since Φ(D0)=0\Phi(D_0) = 0 and Φ(Dm)0\Phi(D_m) \ge 0, we have:

i=1mc^ii=1mci\sum_{i=1}^{m} \hat{c}_i \ge \sum_{i=1}^{m} c_i

The total amortised cost bounds the total actual cost. This is the potential theorem.

Interpretation

  • ΔΦ>0\Delta\Phi > 0: the structure becomes “messier” (higher potential); the amortised cost exceeds the actual cost, “saving up” to pay for future cleanup
  • ΔΦ<0\Delta\Phi < 0: cleanup occurs, releasing potential to pay for the current operation

Think of Φ\Phi as a measure of “disorder” in the data structure, or as a bank balance tracking stored credit.

Example: Binary Counter

Let Φ(D)=number of 1’s in the counter\Phi(D) = \text{number of 1's in the counter}.

  • Φ(D0)=0\Phi(D_0) = 0 (counter starts at 0, no 1’s)
  • Φ(D)0\Phi(D) \ge 0 always (count of bits cannot be negative)

Consider an INCREMENT where tt trailing 1’s flip to 0 and one 0 flips to 1. Actual cost: c=t+1c = t + 1.

Change in potential:

  • Before: bi1b_{i-1} ones
  • After: bi1t+1b_{i-1} - t + 1 ones (removed tt ones, added one)
  • ΔΦ=(bi1t+1)bi1=1t\Delta\Phi = (b_{i-1} - t + 1) - b_{i-1} = 1 - t

Amortised cost:

c^=c+ΔΦ=(t+1)+(1t)=2\hat{c} = c + \Delta\Phi = (t + 1) + (1 - t) = 2

Amortised per INCREMENT: O(1)O(1).

This matches the accounting method result (charge 2 per increment). The potential method generalises the accounting intuition into a formal proof technique.

Choosing a Potential Function

Good potential functions often:

  1. Measure “disorder” that expensive operations will clean up (e.g. number of trees in a binomial heap root list, number of marked nodes in a Fibonacci heap)
  2. Increase smoothly with cheap operations and drop sharply during expensive cleanup
  3. Are non-negative and start at zero

For a dynamic array, Φ=2sizecapacity\Phi = 2 \cdot \text{size} - \text{capacity} works (see Dynamic Arrays Example).

For Fibonacci heaps, Φ=numRoots+2numMarkedNodes\Phi = \text{numRoots} + 2 \cdot \text{numMarkedNodes} (see Binomial Heap Amortized Analysis).

Summary

AspectDetail
Φ(D)\Phi(D)Potential: “stored energy” in state DD
c^i\hat{c}_ici+Φ(Di)Φ(Di1)c_i + \Phi(D_i) - \Phi(D_{i-1})
RequirementΦ(D0)=0\Phi(D_0) = 0, Φ(D)0\Phi(D) \ge 0
Total boundc^ici\sum \hat{c}_i \ge \sum c_i
Key insightΦ\Phi rises during cheap ops, drops during expensive cleanup

Past Tripos: y2024p1q9, y2023p2q7.