Consider the following buffer manag-ment problem. Initially the buffer size (the number of blocks) is one. Each block can accommodate exactly one item. As soon as a new item arrives, check if there is an available block. If yes, put the item into the block, induced a cost of one. Otherwise, the buffer size is doubled, and then the item is able to put into. Moreover, the old items have to be moved into the new buffer so it costs k+1 to make this insertion, where k is the number of old items. Clearly, if there are N items, the worst-case cost for one insertion can be Ω(N). To show that the average cost is O(1), let us turn to the amortized analysis. To simplify the problem, assume that the buffer is full after all the N items are placed. Which of the following potential functions works?
A.The number of items currently in the buffer
B.The opposite number of items currently in the buffer
C.The number of available blocks currently in the buffer
D.The opposite number of available blocks in the buffer
为什么选D
不是应该选C吗,取反之后变成了负数,potential function可以是负的?
问题概述:类似于C++动态数组,用摊还分析势能法。求合适的势能函数。