the accounting method
Think of every operation as paying a fixed price at the counter — its amortized cost — which may be more or less than the actual work the operation does. When you overpay, the leftover coins are not wasted: you stash them on the data structure as prepaid credit. Later, when an operation costs more than its fixed price, it pays the difference out of the credit that earlier operations left behind. This is the accounting method, also called the banker's method.
The discipline is one inequality you must keep true forever: the credit balance can never go negative. Concretely, you (the analyst) assign each operation type an amortized charge. You then verify that for ANY sequence, the total amortized charges are always at least the total actual cost — equivalently, that the stored credit never drops below zero at any point. If you can show this, then total amortized cost is an upper bound on total actual cost, so the amortized charges you picked are valid. The trick is choosing charges large enough that cheap operations bank enough credit to cover the rare expensive ones. For a doubling array you might charge 3 per append: 1 pays for the write now, and the spare 2 are saved on the new element so that only the elements inserted since the last resize carry credit — and when the array doubles, those k/2 elements hold 2 credits each, exactly k in total, enough to pay the k-unit copy.
The accounting method shines when you can tell a clean story about which cheap operations pay for which expensive ones, and it lets different operations carry different charges, unlike the blunt aggregate method. The thing to watch: you must prove the balance stays non-negative for every prefix of every sequence, not just at the end. A charge that balances out 'on average' but lets credit go negative midway is invalid, because an adversary could stop the sequence exactly at the moment the books are in the red.
Doubling array, charge 3 per append. After an append at a non-full array, write costs 1 and 2 credits go onto the new element. When the array of size k is full and doubles, the k/2 elements added since the last resize each carry 2 saved credits, 2*(k/2)=k in total — exactly enough to pay the k units to copy all current elements (the older half already spent their credit on the previous resize). The balance never goes negative, so amortized 3 = O(1) per append is valid.
Overcharge cheap operations to bank credit; spend that credit on rare expensive ones, keeping the balance never negative.
Validity hinges on the credit balance staying non-negative for every prefix of the sequence, not just at the end. If credit can dip below zero partway, an adversary stops the sequence there and your amortized bound fails.