This section records two compact textbook amortized-analysis examples. The
stack model uses the real operation cost for MULTIPOP: at most one unit
per popped element. The counter model includes the executable little-endian
increment, the exact one-step flip count, and the standard one-bit-count
potential proof.
Main results:
Theorem multiPop_totalCost_le: one MULTIPOP operation pops at
most the requested number of stack cells.
Theorem binaryCounter_increment_potential_le_two: one executable
binary-counter increment has amortized cost at most 2 under the number-of-one
bits potential.
Theorem binaryCounter_trace_potential_le: the executable multi-step
increment trace has total flips plus final potential bounded by the initial
potential plus 2n.
Theorem binaryCounter_trace_totalFlips_le: starting from the empty
counter, the executable trace flips at most 2n bits.
Theorem binaryCounter_totalFlips_le: the first-pass counter cost model
has total flip count at most 2n.
Current gaps:
The first-pass constant-cost wrapper remains as a lightweight aggregate model
for examples that do not need the executable trace.
namespaceCLRSnamespaceChapter17
Stack multipop
Pop at most k elements from a stack represented by a list.
Executable little-endian binary-counter increment. This definition is included
for the public model; the first-pass cost theorem below uses a specification
cost sequence with the standard constant amortized bound.