This preview shows page 1. Sign up to view the full content.
Unformatted text preview: crement
7 6 5 4 3 2 1 0 0 1 0 1
0 0
1 0
1 0
1 0
1 19 Binary counter: accounting method
Credits. One credit pays for a bit flip.
Invariant. Each bit that is set to 1 has one credit.
Accounting. ・Flip bit j from 0 to 1: charge two credits (use one and save one in bit j).
・Flip bit j from 1 to 0: pay for it with saved credit in bit j.
7 6 5 4 3 2 1 0 0 1 0 1 0 0 0 0 20 Binary counter: accounting method
Credits. One credit pays for a bit flip.
Invariant. Each bit that is set to 1 has one credit.
Accounting. ・Flip bit j from 0 to 1: charge two credits (use one and save one in bit j).
・Flip bit j from 1 to 0: pay for it with saved credit in bit j.
Theorem. Starting from the zero counter, a sequence of n INCREMENT
operations flips O(n) bits.
Pf. The algorithm maintains the invariant that any bit that is currently set to
1 has one credit ⇒ number of credits in each bit ≥ 0. ▪ 21 Potential method (physicist's method)
Potential function. Φ(Di) maps each data structure Di to a real number s.t.: ・Φ(D0) = 0.
・Φ(Di) ≥ 0 for eac...
View
Full
Document
This document was uploaded on 02/05/2014.
 Spring '14

Click to edit the document details