Back to index

CSC 378F Data Structures and Algorithm Analysis

POTENTIAL METHOD[CLR 18.3] 
Store credit, or 'potential', in the data structure as a whole, not on individual pieces of data.

Let pm_1.gif be the data structure after the pm_2.gif operation.

pm_3.gif is the "potential energy" ( "bank balance" in credits, for example ) of pm_4.gif .

Let -

 
pm_5.gif 
i.e. actual cost + change in potential

Does this satisfy the Amortization Property?

pm_6.gif

 pm_7.gif

 pm_8.gif

 pm_9.gif if pm_10.gif

The potential, pm_11.gif , must always be at least as large as the initial potential, pm_12.gif .

Usually, pm_13.gif .

Two-Stack Queue
 
pm_14.gif should be large before an expensive operation and much smaller afterward!
 
... so that pm_15.gif is comprised of -
large positive cost + very negative change of potential = a small result.
What to choose?

Let pm_16.gif be the number of elements in S. Suppose S has s elements.
Then -

pm_17.gif

 pm_18.gif 1 + ( s + 1 ) - ( s )

 pm_19.gif 2

Suppose S has s elements and Dequeue causes x of them to be transferred to T.
Then -
pm_20.gif

 pm_21.gif ( pop + transfer ) + ( after ) - ( before )

 pm_22.gif ( 1 + x ) + ( s - x ) - ( s )

 pm_23.gif 1

Is pm_24.gif always?
Yes, since pm_25.gif and pm_26.gif .
However, you must always check this condition!
By the amortization property -
pm_27.gif

 pm_28.gif

 pm_29.gif

sequence of M Enqueue and Dequeue operations takes at most 2M steps.
Back to index