This is the Aggregate method. Why: the defining move is computing T(m)directly as one lump and reporting T(m)/m identically for every operation.
Weakness: because it hands every operation the same amortized cost, it is weak when different operation types have genuinely different amortized behaviour (e.g. a structure with both cheap find and expensive delete) — it can't distinguish them.
Recall Solution L1.2
They broke requirement 1: Φ(D0)=0 (the empty start must have zero stored energy). A negative starting potential means the amortized total could undershoot the real total, so the bound would be dishonest. (It also violates Φ≥0.)
(a) Copy work. Copies happen when size crosses 1,2,4,… The last power of two ≤1000 is 512=29. Copy costs sum to
1+2+4+⋯+512=210−1=1023<2m=2000.✓
So total copy work is exactly 1023.
(b) Total work T(m)=writes1000+copies1023=2023. Amortized =2023/1000=2.023≤3=O(1).
Why the "3": even in the loosest bound T(m)<m+2m=3m, so c^<3 always.
Recall Solution L2.2
Direct count. Bit b0 (least significant) flips every increment: 16 times. Bit b1 flips every 2 increments: 8. Bit b2: every 4: 4. Bit b3: every 8: 2. Bit b4: every 16: 1.
total flips=16+8+4+2+1=31.Check the charge:c^⋅n=2⋅16=32≥31. ✓ The bank stays solvent.
Why it works: every 0→1 flip prepays its own future 1→0 flip. In general total flips over n increments =∑j≥0⌊n/2j⌋<2n — the geometric tail again.
Actual cost ci=1 (write one element). Potential change:
ΔΦ=(2(n+1)−s)−(2n−s)=2.c^i=ci+ΔΦ=1+2=3.Why: the push does 1 unit of real work but deposits2 units of stored energy for the copy that is coming. Amortized =3=O(1).
Recall Solution L3.2
Actual cost ci=n+1 (copy n + insert 1).
Before (full): Φbefore=2n−s=2n−n=n.
After (doubled): Φafter=2(n+1)−2s=2(n+1)−2n=2.
ΔΦ=2−n,c^i=(n+1)+(2−n)=3.What cancels: the giant real cost n+1 is annihilated by the potential dropping by n−2. The stored energy pays the copy, leaving c^=3. See the picture below — the red bar (potential) collapses exactly as the copy fires.
Recall Solution L3.3
If n<s/2 then 2n<s, so 2n−s<0 — the potential goes negative, violating requirement Φ≥0. A negative potential means we might be "borrowing" energy we never stored, and the amortized total could fall below the real total → dishonest bound.
The real fix: structures that also shrink use a two-piece potential, e.g.
Φ={2n−s2s−nn≥s/2n<s/2
so that potential rises again as the table empties, ready to pay for a shrink copy. Below s/2, each pop deposits energy for the eventual halving. The figure shows both wings.
Requirements: Φ(D0)=0 (empty) ✓ and Φ≥0 (a count) ✓.
Push (n→n+1): ci=1, ΔΦ=+1, so c^=1+1=2.
Multipop popping p=min(k,n) elements: ci=p, but ΔΦ=−p (stack shrinks by p). So
c^=p+(−p)=0.
Every operation has amortized cost ≤2=O(1). Why it works: you can only pop what you pushed; each element's pop was prepaid by the +1 stored at its push. A multipop of 1000 elements looks expensive but its real cost is exactly cancelled by the potential it releases.
Recall Solution L4.2
ChooseΦ=2⋅(size of In). Check: Φ(D0)=0 ✓, Φ≥0 ✓.
Enqueue (push to In): ci=1, ΔΦ=+2, so c^=1+2=3.
Dequeue with Out non-empty:ci=1 (one pop), ΔΦ=0, c^=1.
Dequeue triggering a flip of j elements:ci=j(pop In)+j(push Out)+1(pop Out)=2j+1. In empties, so ΔΦ=−2j. Then
c^=(2j+1)+(−2j)=1.
Every operation is O(1) amortized. Why the factor 2: each enqueued element will later be moved twice (popped from In, pushed to Out), so we bank 2 units at enqueue time to prepay exactly that.
Design. Let Φ=(number of currently-set slots). Check: Φ(D0)=0 ✓, Φ≥0 ✓.
SET on an unset slot:ci=1, ΔΦ=+1⇒c^=2.
SET on an already-set slot (idempotent, no state change): ci=1, ΔΦ=0⇒c^=1.
RESET clearing r set slots:ci=r, ΔΦ=−r⇒c^=r+(−r)=0.
Both ≤2=O(1). Each set slot stored +1 at its SET, released to pay its own clear.
Degenerate RESET on empty structure:r=0, so ci=0, ΔΦ=0, c^=0. No underflow, potential never negative — the bound survives the empty case cleanly.
Recall Solution L5.2
All three methods bound the same quantity: ∑i=1mc^i≥T(m)=∑ci, and each reports a valid upper bound on T(m).
Aggregate computes T(m) itself and sets c^i=T(m)/m for all i: total =T(m).
Accounting requires the bank ∑(c^i−ci)≥0, i.e. ∑c^i≥T(m).
Potential gives ∑c^i=T(m)+Φ(Dm)−Φ(D0)≥T(m) since Φ(Dm)≥Φ(D0).
All three satisfy the same inequality ∑c^i≥T(m). The real total work T(m) is a physical fact — it doesn't depend on our bookkeeping. What differs is only how each method distributesT(m) (plus leftover credit/potential) across the m operations. Given the tightest choices (Φ(Dm)=Φ(D0), zero leftover credit), they collapse to the identical bound T(m)/m. Bookkeeping cannot change reality.
Recall Feynman recap
The three methods are three ways to pay a bill you already owe. The bill (T(m)) is fixed by physics. Aggregate = pay the lump sum and split evenly. Accounting = put coins in a jar per element. Potential = track the "stored energy" of the whole structure. Every jar-of-coins or energy trick must, when you cash out, cover the same real bill — so all three land on the same O(1) per operation.