简体   繁体   English

在摊销分析中使用潜力和会计方法

[英]Using the potential and the accounting methods in amortized analysis

I have read about the accounting and the potential methods but I still having trouble solving such questions:我已经阅读了有关会计和潜在方法的信息,但我仍然无法解决这些问题:

在此处输入图像描述

Intuition直觉

By analyzing for each operation its expensive case and cheap case you can build an idea of how to charge each operation (then you may need some small fixes to 'fix' the numbers)通过分析每个操作的昂贵案例和廉价案例,您可以了解如何对每个操作收费(然后您可能需要一些小修复来“修复”数字)

By looking at the important parameter of the data structure you can build a potential function (here for example it is the number of the elements in s2)通过查看数据结构的重要参数,您可以构建潜在的 function(这里例如是 s2 中的元素数)

  • Also, seeing many examples really helps here此外,在这里看到很多例子真的很有帮助

The accounting method:核算方法:

Lets charge each insertion two coins: one will be used to pop the element from s2, the second will be used to insert the element to s1 and Lets charge each deletion one coin that will be used to delete the element from s1.让每次插入收取两枚硬币:一枚用于从 s2 中弹出元素,第二枚用于将元素插入到 s1 中,每次删除收取一枚硬币,用于从 s1 中删除元素。

Then note that the credit in the bank cannot be negative because if s1 is not empty then we are paying only for the actual cost of the operation (which is the only deletion from s1) and if s1 is empty then the operations are popping from s2 and inserting to s1 which we already charged for.然后请注意,银行中的信用不能为负,因为如果 s1 不为空,那么我们只需支付操作的实际成本(这是从 s1 中唯一的删除),如果 s1 为空,那么操作将从 s2 弹出并插入我们已经收费的 s1。 ( it is important to note that we assume we start from empty data structure, OR, that we got the proper credit for every initial state of the data structure ) 重要的是要注意,我们假设我们从空数据结构开始,或者,我们为数据结构的每个初始 state 获得了适当的信用

Now you can see that for each set of operations our total credit of 3n covers the actual cost of the operations (and we got a margin of the credit of the remaining elements in s2) and hence these are valid amortized bounds.现在您可以看到,对于每组操作,我们的总信用 3n 涵盖了操作的实际成本(我们得到了 s2 中剩余元素的信用边际),因此这些是有效的摊销界限。

To solve with potential function lets consider the function:为了解决潜在的 function,让我们考虑 function:

Potential(DataStructure) = 2 * Number of elements in s2势(DataStructure)= 2 * s2 中的元素数

Recall that we compute like this:回想一下,我们是这样计算的:

amortized cost of OP.A = actual cost of OP.A + Potential(DS after)-Potential(DS before) OP.A 的摊余成本 = OP.A 的实际成本 + 潜力(DS after)-潜力(DS before)

So we got (denote number of elements in s2 in k):所以我们得到(表示 k 中 s2 中的元素数):

For insertion: 1 + 2(k+1)-2k = 3插入: 1 + 2(k+1)-2k = 3

For cheap deletion: 1 + 2k - 2k = 1廉价删除: 1 + 2k - 2k = 1

For Expensive deletion: 1+2k + 0 - 2k = 0 (the actual cost is 1+2k because we pop from s2 and insert to s1 each element and then pop one element from s1)对于昂贵的删除: 1+2k + 0 - 2k = 0(实际成本为 1+2k,因为我们从 s2 弹出并插入每个元素到 s1,然后从 s1 弹出一个元素)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM