Brodal queue 论文及翻译
翻译是机翻 + 修改一些不像样的地方。
Worst-Case Efficient Priority Queues
Abstract / 摘要
An implementation of priority queue is presented that supports the operations MakeQueue, FindMin, Insert, Meld and DecreaseKey in wost case time and DeleteMin and Delete in worst case time . The space requirement is linear. The data structure presented is the first achieving this worst case performance.
我们搞出了一种奇怪的优先队列,支持最坏 创建、找最小值、插入、合并和减值操作以及 的删除最小值和删除给定节点。这是第一个不用均摊就能达到该复杂度的数据结构。
1. Introduction / 介绍
We consider the problem of implementing priority queue which are efficient in the worst case sense. The operations we want to support are the following commonly needed priority queue operations [11].
我们考虑在最坏情况下实现高效优先队列的问题,我们希望支持的操作是以下常见的优先队列操作。
MakeQueue creates and returns an empty priority queue.
FindMin() returns the minimum element contained in priority queue .
Insert() inserts an element into priority queue .
Meld() melds priority queues and to a new priority queue and returns the resulting priority queue.
DecreaseKey() replaces element by in priority queue provided and it known where in stored in .
DeleteMin() deletes and returns the minimum element from priority queue .
Delete() deletes element from priority queue provided it is known where is stored in .
MakeQueue 创建并返回一个空优先队列。
FindMin() 返回优先队列 中包含的最小元素。
Insert() 将元素 插入优先队列 。
Meld() 将优先队列 和 合并到新的优先队列,并返回结果。
DecreaseKey() 将优先队列 中的元素 替换为 ,保证 ,并且知道 存储在 的何处。
DeleteMin() 从优先队列 中删除并返回最小元素。
Delete() 从优先队列 中删除元素 ,前提是知道 存储在 的位置。
The construction of priority queues is a classical topic in data structures [1, 2, 3, 4, 5, 6, 7, 10, 12, 15, 16, 17]. A historical overview of implementations can be found in [11]. There are many applications of priority queues. Two of the most prominent examples are sorting problems and network optimization problems [13].
优先队列是数据结构中的一个经典主题([1、2、3、4、5、6、7、10、12、15、16、17])。实现的历史概述见 [11]。优先队列有许多应用。两个最突出的例子是排序问题和网络优化问题 [13]。
In the amortized sense, [14], the best performance for these operations is achieved by Fibonacci heaps [7]. They achieve amortized constant time for all operations except for the two delete operations which require amortized time . The data structure we present achieves matching worst case time bounds for all operations. Previously, this was only achieved for various strict subsets of the listed operations [1, 2, 3, 15]. For example the relaxed heaps of Driscoll et al. [3] and the priority queues in [1] achieve the above time bounds in the worst case sense except that in [3] Meld requires worst case time and in [1] DecreaseKey requires worst case time . Refer to Table 1. If we ignore the Delete operation our results are optimal in the following sense. A lower bound for DeleteMin in the comparison model is proved in [1] where it is proved that if Meld can be performed in time then DeleteMin cannot be performed in time .
在均摊的意义上,[14],这些操作的最佳性能由斐波那契堆 [7] 实现。除两个需要均摊时间 的删除操作外,它们实现了所有操作的均摊固定时间。我们提出的数据结构实现了所有操作的最坏情况时间复杂度。以前,这仅针对所列操作的各种严格子集实现 [1, 2, 3, 15]。例如,Driscoll 等人在 [3] 中的松弛堆和 [1] 中的优先级队列在最坏情况下实现了上述时间界限,除了 [3] 中 Meld 需要最坏情况时间 ,[1] 中 DecreaseKey 需要最坏条件时间 。参考表 1。如果我们忽略 Delete 操作,我们的结果在以下意义上是最佳的。[1] 中证明了比较模型中 DeleteMin 的下界,其中如果 Meld 可以在 时间中执行。
The data structure presented in this paper originates from the same ideas as the relaxed heaps of Driscoll et al. [3]. In [3] the data structure is based on heap ordered trees where nodes may violate heap order. We extend this to allow heap order violations which is a necessary condition to be able to support Meld in worst case constant time and if we allow a nonconstant number of violations.
本文提出的数据结构来源于与 Driscoll 等人在 [3] 中的松弛堆相同的思想。在 [3] 中,数据结构基于堆顺序树,其中 个节点可能违反堆性质。我们将其扩展为允许 个违规节点,这是在最坏情况下支持 Meld 的必要条件,如果我们允许非常数量的违规。
In Section 2 we describe the data structure representing a priority queue. In Section 3 we describe a special data structure needed internally in the priority queue construction. In Section 4 we show how to implement the priority queue operations. In Section 5 we summarize the required implementation details. Finally some concluding remarks on our construction are given in Section 6.
在第 2 节中,我们描述了表示优先级队列的数据结构。在第 3 节中,我们描述了优先级队列构造内部所需的特殊数据结构。在第 4 节中,我们展示了如何实现优先级队列操作。在第 5 节中,我们总结了所需的实现细节。最后,第 6 节给出了一些关于我们的建设的总结。
2 The Data Structure / 数据结构
In this section we describe the components of the data structure representing a priority queue. A lot of technical constraints are involved in the construction. Primary these are consequences of the transformations to be described in Section 3 and Section 4.3. In Section 5 we summarize the required parts of the construction described in the following sections.
在本节中,我们将描述表示优先队列的数据结构的组件。实现有许多细节。这些主要是第 3 节和第 4.3 节中描述的转换的结果。在第 5 节中,我们总结了以下章节中描述的结构的所需部分。
The basic idea is to represent a priority queue by two trees and where all nodes contain one element and have a nonnegative integer rank assigned. Intuitively the rank of a node is the logarithm of the size of the subtree rooted at the node. The details of the rank assignment achieving this follow below.
基本思想是用两棵树 和 表示优先队列,其中所有节点都包含一个元素,并有一个非负整数秩。直观地说,节点的秩是以节点为根的子树大小的对数。实现这一目标的秩分配详情如下。
The sons of a node are stored in a doubly linked list in increasing rank order from right to left. Each node has also a pointer to its leftmost son and a pointer to its parent.
一个节点的子节点从右到左存储在双向链表中。每个节点还有一个指向其最左侧子节点的指针和一个指向其父节点的指针。
The notation we use is the following. We make no distinction between a node and the element it contains. We let denote nodes, the parent of , the rank of , the number of sons of rank that has and the root of . Nodes which are larger than their parents are called good nodes — good because they satisfy heap order. Nodes which are not good are called violating nodes.
我们不区分节点和其包含的元素,定义一些符号:
-
表示节点。
-
表示 的父节点。
-
表示 的秩。
-
表示 的子节点中秩为 的节点个数。
-
表示 的根。
-
权值大于其父节点的节点称为好节点,因为它们满足堆性质。不好的节点称为 violating nodes。
The idea is to let be the minimum element and to lazy merge the two trees and such that becomes empty. Since is the minimum element we can support FindMin in worst case constant time and the lazy merging of the two trees corresponds intuitively to performing Meld incrementally over the next sequence of operations. The merging of the two trees is done by incrementally increasing the rank of by moving the sons of to such that becomes empty and becomes the node of maximum rank. The actual details of implementing Meld follow in Section 4.5.
思想是让 成为最小元素,并惰性地合并两个树 和 ,使得 为空。由于 是最小元素,我们可以在最坏常数时间内下支持 FindMin,两棵树的惰性合并直观地对应于在下一个操作序列中增量执行 Meld。通过将 的子节点移动到 ,从而 变为空。实施 Meld 的实际细节见第 4.5 节。
As mentioned before we have some restrictions onthe trees forcing the rank of a node to be related to the size of the subtree rooted at the node. For this purpose we maintain the invariants S1~S5 below for any node .
如前所述,我们对树有一些限制,让节点的秩与该节点上根的子树的大小相关。为此,我们为任何节点 保持下面的不变量:
S1: If is a leaf, then ,
S2: ,
S3: if , then ,
S4: ,
S5: or .
S1:如果 没有子节点,那么 ,
S2:,
S3:如果 ,那么 ,
S4:,
S5:如果 不为空那么 。
The first two invariants just say that leaves have rank zero and that the ranks of the nodes strictly increase towards the root. Invariant S3 says that a node of rank has at least two sons of rank . This guarantees that the size of the subtree rooted at a node is at least exponential in the rank of the node (by induction it follows from S1 and S3 that the subtree rooted at node has size at least ). Invatiant S4 bounds the number of sons of a node that have the same rank within a constant. This implies the crucial fact that all nodes have rank and degree . Finally S5 says that either is empty or its root has rank larger than or equal to the rank of the root of .
前两个不变量限制只有叶子结点的秩为零,节点的秩严格地向根增加。S3 表明秩为 的节点至少有两个秩为 的子节点。这保证了以节点为根的子树的大小在节点的秩中至少是指数的(利用 S1 和 S3 进行归纳,以节点 为根的子树的大小至少为 )。S4 将具有相同秩的节点的子节点数量限制在一个常数内。这意味着所有节的秩和度都是 量级的这一关键事实。最后 S5 表示要么 为空要么其根的秩大于或等于 的根的秩。
Notice that in S4 we do not allow a node to have only a single son of a fiven rank. This is because this allows us to cut off the leftmost sons of a node such that the node can get a new rank assigned where S3 is still satisfied. This property is essential to the transformations to be described in Section 4.3 The requirement in S4 is a consequence of the construct described in Section 3.
注意,在 S4 中,我们不允许一个节点只有一个五级的子节点。这是因为这允许我们切断一个节点的最左边的子节点,这样该节点可以在 S3 仍然满足的情况下获得新的秩。此属性对于第 4.3 节中所述的转换至关重要。S4 中的要求 是第 3 节中所描述的构造的结果。
After having described the conditions of how nodes are assigned ranks and how this forces structure on the trees we now turn to consider how to handle the violating nodes — which together with the two roots could be potential minimum elements. To keep track of the violating nodes we associate to each node two subsets and of nodes larger than from the trees and . That is the nodes in and are good with respect to . We do not require that if that and belong to the same tree. But we require that a node belongs to at most one or one set. Also we do not require that if then .
在描述了节点如何被分配秩的条件以及这如何强制树上的结构之后,我们现在开始考虑如何处理 violation nodes — 这些节点与两个根一起可能是潜在的最小元素。为了跟踪 violation nodes,我们将树 和 中大于 的两个子集 和 与每个节点 相关联。即 和 中的节点相对于 是好的。我们不要求如果 ,则 和 属于同一棵树。但我们要求节点 最多属于一个 或一个 集合。此外,我们不要求如果 ,则 。
The sets and the sets are all stored as doubly linked lists. Violations added to a set are always added to the front of the list. Violations added to a set are always added in such a way that violations of the same rank are adjacent. So if we have to add a violation to and there is already a node in of the same rank, then we insert the new node adjacent to this node. Otherwise we just insert the new node at the front of .
集合和 集合都用双向链表存储。添加到 集合的 violation node 总是添加到列表的前面。添加到 集合的违规总是添加到相同等级的 violation nodes。因此,如果我们必须向 添加一个 violation node,并且在 中已经有一个具有相同秩的节点,那么我们在与该节点相邻位置插入新节点。否则,我们只需在 的前面插入新节点。
We implement the and sets by letting each tree node have four additional pointers: One to the first node in , one to the first node in , and two to the next and previous node in the violation list that belongs to — provided is contained in a violation list. Each time we add a node to a violation set we always first remove the node from the set it possibly belonged to.
我们通过让每个树节点 有四个额外的指针来维护 和 集合:一个指针指向 中的第一个节点,一个指向 中的第一个节点,两个指针指向 violation list 中 所属的下一个和上一个节点,前提是 包含在 violation list 中。每次我们向 violation set 添加节点时,我们总是首先从它可能属于的集合中删除该节点。
Intuitively ‘s purpose is to contain violating nodes of large rank. Whereas ‘s purpose is to contain violating nodes of small rank. If a new violating node is created which has large rank, i.e. , we add the violation to , otherwise we add the violation to . To be able to add a node to at the correct position we need to know if a node already exists in of the same rank. In case there is we need to know such an element. For this purpose we maintain an extendible array of size of pointers to nodes in of each possible rank. If no node exists of a given rank in the corresponding entry in the array is null.
直观地说, 的目的是包含大秩的违规节点。而 的目的是包含小秩的违规节点。如果创建了一个具有大秩的新 violation node,即 ,我们将这个节点添加到 ,否则我们将违规加入到 。为了能够在正确的位置向 添加节点,我们需要知道节点是否已经存在于相同秩的 中。万一我们需要知道这样一个元素。为此,我们维护了一个大小为 的可扩展数组,该数组包含指向每个可能秩的 中的节点的指针。如果 中不存在给定秩的节点,则数组中的相应条目为空。
The structure on the and sets is enforced by the following invariants O1~O5. We let denote the number of nodes in of rank .
和 集合上的结构由以下不变量 O1~O5 实现。我们让 表示秩 的 中的节点数。
O1: ,
O2: if , then ,
O3: if , then an exists such that ,
O4: ,
O5: if , then
for where is a constant.
O1:,
O2:如果 ,那么 ,
O3:如果 那么存在一个节点 使得 且 ,
O4:,
O5:如果 ,那么对于 ,
成立,其中 是一个常数。
O1 guarantees that the minimum element contained in a priority queue always is the root of . O2 says that the elements are heap ordered with respect to membership of the and sets. O3 says that all violating nodes belong to a or set. Because all nodes have rank invariants O4 and O5 imply that the sizes of all and sets are . Notice that if we remove an element from a or set, then the invariants O4 and O5 cannot become violated.
O1 保证优先队列中的最小元素始终是 的根。O2 表示元素是根据 和 集合的成员关系进行堆排序的。O3 表示所有违规节点都属于 或 集合。因为所有节点都有 的秩。O4 和 O5 能过说明所有 和 集合的大小都是 。请注意,如果我们从 或 集合中删除一个元素,那么不变量 O4 和 O5 不会被违反。
That invariants O4 and O5 are stated quite differently is because the and sets have very different roles in the construction. Recall that the sets take care of large violations, i.e. violations that have rank larger than when they are created. The constant is the number of large violations thar can be created between two increases in the rank of .
O4 和 O5 的表述非常不同,因为 和 集合在构造中具有非常不同的作用。回想一下, 集合会处理较大的违规行为,即创建时秩大于 的违规行为。常数 是在 的两次增加之间可以创建的大型违规次数。
For the roots and we strengthen the invariants such R1~R3 also should be satisfied.
对于根 和 ,我们加强了约束,如 R1~R3 也应满足。
R1: for ,
R2: ,
R3: if then .
R1:对于 ,,
R2:,
R3:如果 那么 ,
Invariant R1 guarantees that there are at least two sons of each rank at both roots. This property is important for the transformations to be described in Section 4.2 and Section 4.3. Invariant R2 together with invariant O5 guarantee that if we can increase the rank of by one we can create new large violations and add them to without violating invariant O5. Invariant R3 says that all violations in have to be small. The maintenance of R1 and O4 turns out to be nontrivial but they can all be maintained by applying the same idea. To unify this idea we introduce the concept of a guide to be described in Section 3.
不变量 R1 保证在两个根上每个秩至少有两个儿子。此属性对于第 4.2 节和第 4.3 节中描述的变换非常重要。不变量 R2 和不变量 O5 保证,如果我们可以将 的秩增加 ,我们可以创建 个新的大 violation nodes,并将它们添加到 中,而不违反不变量 O5。不变量 R3 表示 中的所有 violation nodes 必须很小。R1 和 O4 的维护结果是不平凡的,但它们都可以通过应用相同的思想来维护。为了统一这一思想,我们引入了第 3 节中描述的 guides 概念。
The main idea behind the construction is the following captured by the DecreaseKey operation. The details follow in Section 4. Each time we perform a DecreaseKey operation we just add the new violating node to one of the sets or . To avoid having too many violations stored at the root of we incrementally do two different kinds of transformations. The first transformation moves the sons of to such that the rank of increases. The second transformation reduces the number of violations in by replacing two violations of rank by at most one violation of rank . These transformations are performed to reestablish invariants R2 and O4.
构造背后的主要思想是由 DecreaseKey 操作捕获的以下内容。详细信息见第 4 节。每次我们执行 DecreaseKey 操作时,我们只需将新的违规节点添加到集合 或 。为了避免在 的根目录中存储太多 violation nodes,我们增量地执行两种不同类型的转换。第一个变换将 的子节点移动到 ,从而让 的秩增加。第二个变换通过将秩 的两个 violation nodes 替换为秩 的最多一个 violation nodes 来减少 的大小。执行这些变换以重建不变量 R2 和 O4。
3 Guides
In this section we describe the guide data structure that helps us maintaining the invariants R1 and O4 on and . The relationship between the abstract sequences of variables in this section and the sons and the violations stored at the roots are explained in Section 4.
在本节中,我们将描述数据结构 guide,该结构有助于我们在 和 上保持不变量 R1 和 O4。第 4 节解释了本节中的抽象变量序列与子变量之间的关系以及存储在根中的违规行为。
The problem can informally be described as follows. Assume we have to maintain a sequence of integer variables (all sequences in this sectiongoes from right to left) and we want to satisfy the variant that all for some threshold . On thesequence we can only perform Reduce() operationswhich decrease by at least two and increase by at most one. The can be forced to increase anddecrease by one, but for each change in an we areallowed to do Reduce operations to prevent any from exceeding . The guide’s job is to tell us which operations to perform.
这个问题可以非正式地描述为:假设我们必须维护一个整数变量序列 (本节中的所有序列都从右向左),并且我们希望满足一个不变量,即对于某个阈值 有 。在该序列中,我们只能执行 Reduce() 操作,该操作将 减少至少 ,并将 最多增加 。每当 被增加和减少 ,我们需要执行 次 Reduce 操作,以防止任何 超过 。guide 的工作是告诉我们要执行哪些操作。
This problem also arises implicitly in [1, 2, 8, 9]. But the solution presented in [8] requires time to find which Reduce operations to perform whereas the problems in the other papers are simpler because only can be forced to increase and decrease. The data structure we present can find which operations to perform in worst case time for the general problem.
这个问题也隐含在 [1, 2, 8, 9] 中。但是 [8] 中给出的解决方案是 的,而其他论文中的问题更简单,因为只有 可以强制增加和减少。我们给出的数据结构可以找到在一般问题的最坏情况下 地找到要执行的操作。
To make the guide’s knowledge about the as small as possible we reveal to the guide another sequence such that (this choice is a consequence of the construction we describe below). As long as all we do not require help from the guide. First when an is forced to become we require help from the guide. In the following we assume w.l.o.g. that the threshold is two such that and that Reduce() decreases by two and increases by one.
为了使 guide 对 的了解尽可能少,我们给 guide 另一个序列 ,使得 (这个选择是我们下面描述的构造的结果)。只要所有 ,我们就不需要 guide 的帮助。首先,当 被迫变成 时,我们需要 guide 的帮助。在下文中,我们假设阈值 为 ,使得 ,并且 Reduce() 将 减少 ,将 增加 。
The data structure maintained by the guide partitions the sequence into blocks of consecutive is of the form where the number of ones is allowed to be zero. The guide maintains the invariant that all is not belonging to a block of the above type have value either zero or one. An example of a sequence satisfying this is the following where blocks are shown by underlining the subsequences.
guide 维护的数据结构将序列 划分为连续的块,每个块都形如 ,其中 的数量可能为 。guide 保证即所有值为 或 的 不属于上述类型的块。满足这一要求的序列的一个例子如下,其中通过在子序列下面加下划线来显示块。
The guide stores the values of the variables in one array and uses another array to handle the blocks. The second array contains pointers to memory cells which contain the index of an or the value —. All variables in the same block point to the same cell and this cell contains the index of the leftmost variable in the block. Variables not belonging to a block point to a cell containing —. A data structure for the previous example is illustrated in Figure 1. Notice that several variables can share a memory cell containing —. This data structure has two very important properties:
guide 将变量 的值存储在一个数组中,并使用另一个数组来处理块。第二个数组包含指向包含 索引或值 — 的内存单元的指针。同一块中的所有变量都指向同一单元格,即该单元格包含块中最左侧变量的索引。不属于块的变量指向包含 — 的单元格。前一个示例的数据结构如图 1 所示。请注意,几个变量可以共享包含 — 的存储单元。此数据结构有两个非常重要的属性:
-
Given a variable we can in worst case time find the leftmost variable in the block, and
-
we can in worst case time destroy a given block, i.e. let all nodes in the block belong to no block, by simply assigning — to the block’s memory cell.
-
给定一个变量,我们可以在最坏情况下 时间内找到块中最左边的变量,并且
-
在最坏的情况下,我们可以在 时间内销毁给定的块,即通过简单地将 — 分配给块的存储单元,让块中的所有节点不属于任何块。
When an is forced to increase the guide can in worst case time decide which Reduce operations to perform. We only show how to handle one nontrivial case, all other cases are similar. Assume that there are two blocks of variables adjacent to each other and that the leftmost in the rightmost block has to be increased. Then the following transformations have to be performed:
当 被迫增加时,在最坏的情况下, 就可以决定执行哪些 Reduce 操作。我们只展示如何处理一个非平凡的案例(意为:自己分类讨论去),所有其他案例都是相似的。假设有两个彼此相邻的变量块,并且必须增加最右边块中最左边的 。然后必须执行以下转换:
increment
Reduce,
Reduce,
reestablish blocks.
To reestablish the blocks the two pointers of the new variables in the leftmost block are set to point to the leftmost block’s memory cell and the rightmost block’s memory cell is assigned the value —.
为了重新建立块,最左侧块中新变量的两个指针被设置为指向最左侧块的存储单元,最右侧块的存储单元被分配值 —。
In the case described above only two Reduce operations were required and these were performed on where . This is true for all cases.
在上述情况下,只需要两个 Reduce 操作,这些操作是在 的 上执行的。所有情况都是如此。
We conclude this section with two remarks on the construction. By using extendible arrays the sequence of variables can be extended by a new equal to zero or one in worst case time . If we add a reference counter to each memory cell we can reuse the memory cells is at most .
在本节结束时,我们对其结构做两点评论。通过使用可扩展数组,我们可以在 时间内将变量序列加入一个新的 或 。如果我们给每个存储单元添加一个参考计数器,我们最多可以重用 的存储单元。
4 Operations / 操作
In this section we describe how to implement the different priority queue operations. We begin by describing some transformations on the trees which are essential to the operations to be implemented.
在本节中,我们将描述如何实现不同的优先队列操作。我们首先描述树上的一些转换,这些转换对于要实现的操作是必不可少的。
4.1 Linking and delingking trees / link 和 delink
The fundamental operation on the trees is the linking of trees. Assume that we have three nodes and of equal rank and none of them is a root . By doing two comparisons we can find the minimum. Assume w.l.o.g. that is the minimum. We can now make and the leftmost sons of and increase the rank of by one. Neither or become violating nodes and still satisfies all the invariants S1S5 and O1O5.
树的基本操作是 link。假设我们有三个相同秩的节点 ,并且它们都不是根 。通过做两次比较,我们可以找到最小值。不失一般性地假设 是最小值。现在我们可以使 和 成为 的最左边的儿子,并将 的秩增加一。 或 都不成为 violation nodes,并且 仍然满足所有不变量 S1S5 和 O1O5。
The delinking of a tree rooted at node is a little bit more tricky. If has exactly two or three sons of rank , then these two or three sons can be cut off and gets the rank of the largest ranked son plus one. From S4 it follows that still satisfies S3 and it follows that S1S5 and O1O5 are still satisfied. In the case where has at least four sons of rank two of these sons are simply cut off. Because still has at least two sons of rank the invariants are still satisfied.
根为节点 的树的 delink 有点棘手。如果 正好有 个或 个秩为 的儿子,那么这 个或 个儿子可以被剔除, 的秩变为秩最高的儿子加 。从 S4 可以得出 仍然满足 S3,并且可以得出 S1S5 和 O1O5 仍然满足。在 至少有四个秩为 的子节点的情况下,这些子节点中的两个可以被简单地截断。因为 仍然有至少两个秩 的子节点,不变量仍然满足。
It follows that the delinking of a tree of rank always results in two or three trees of rank and on additional tree of rank at most (the tree can be of any rank between zero and ).
因此,对秩为 的树的 delink 总是导致 个或 个秩为 的树以及秩至多为 的额外树(该树的秩可以是 到 之间的任何数)。
4.2 Maintaining the sons of a root / 维护根的子节点
We now describe how to add sons below a root and how to cut off sons at a root while keeping R1 satisfied. For this purpose we require four guides, two for each of the roots and . We only sketch the situation at because the construction for is analogous.
现在,我们将描述如何在根下面添加子节点,以及如何在保持 R1 满足的同时在根上截断子元素。为此,我们需要四个 guide,根 和 各有两个。我们只在 处描述情况,因为 的构造是类似的。
To have constant time access to the sons of we maintain an extendible array of pointers that for each rank has a pointer to a son of of rank . Because of R1 such sons are guaranteed to exist. This enables us to link and delink sons of rank in worst case time for an arbitrary . One guide takes care of that and the other of that for (to maintain a lower bound on a sequence of variables is equivalent to maintaining an upper bound on the negated sequence). The sons of of rank and are treated separately in a straight forward way such that there always are between and sons of these ranks. This is necessary because of the dependency between the guide maintaining the upper bound on and the guide maintaining the lower bound on . The “marked” variables that we reveal to the guide that maintains the upper bound on have values and to the guide that maintains the lower bound have values .
为了对 的子节点进行 地访问,我们维护了一个可扩展的指针数组,对于每个秩 都有一个指向秩为 的 子节点的指针。因为 R1,这样的儿子是可以保证存在的。这使得我们能够在最坏的情况下为任意的秩 的子节点进行 link 的 delink。一个 guide 负责维护 ,并且另一个负责维护 ,其中 (保持变量序列的下界等同于保持负序列的上界)。秩为 和 的 的子节点以直接的方式分开处理,使得这些秩的子节点个数总是在 和 之间。这是必须的因为维护 上界的 guide 和维护 下界的 guide 之间有依赖。我们向维护 上限的 guide 显示的“marked”变量的值为 ,向维护下限的指南显示值为 。
If we add a new son at of rank we tell the guide maintaining the upper bound that is forced to increase by one (this assumes ). Then the guide then tells us where to do at most two Reduce operations. The Reduce() operation in this context corresponds to the linking of three trees of rank . This decreases by three and increases by one. We only do the linking when so that the guide maintaining the lower bound on will be unaccected (this implies a minor change in the guide). If this results in too many sons of rank or we link some of these sons of rank or we link some of these sons and possibly increase the domain of the two guides.
如果我们向 添加一个秩为 的子节点,我们告诉维持上界的向导 被迫增加 (这假设 )。然后,guide 告诉我们最多在哪里执行两个 Reduce 操作。在此上下文中 的 Reduce() 操作对应于秩为 的三棵树的 link。这将使 减少 ,并使 增加 。我们只在 时进行 link,以便保持 下限的 guide 将不被接受(这意味着 guide 中的一个小变化)。如果这导致秩为 或 的子节点太多,我们将 link 秩为 或者 的一些子节点。
To cut off a son is similar, but now the Reduce operation corresponds to the delink a tree. Tadditional tree from the delinking ransformation thatcan have various ranks is treated separately after the delinking. We just add it below as described above.
切断一个儿子是类似的,但现在 Reduce 操作对应于树的 delink。delink 变换的附加树可以具有不同的等级,在 delink 后分别处理。我们只需像上面所说地将其添加到 下面。
At the situation is nearly the same. The major difference is that because we knew that was the smallest element the linking and delinking of sons of would not create new violations. This is not true at . The linking of sons never creates new violations but delinking of sons at can create three new violations. We will see in Section 4.4 that it turns out that we only cut off sons of which have rank larger than . The tree “left over” by a delinking is made a son of if it has rank less than . Otherwise it is made a son of . The new violations which have rank larger than are added to . To satisfy O5 and R2 we justnave to guarantee that the rank of , will be increasedand that in R2 and O5 is chosen large enough.
在 时,情况几乎相同。主要的区别在于,因为我们知道 是最小的元素,所以 link 和 delink 的子元素不会产生新的 violation node。 的情况并非如此。儿子的 link 不会产生新的违规行为,但在 delink 时 儿子会产生三个新的 violation nodes。我们将在第 4.4 节中看到,结果是我们只切断了秩高于 的 的儿子。如果树的秩小于 ,则 delink 时“剩余”的树将成为 的子树。否则它将成为 的儿子。秩大于 的新 violation nodes被添加到 。为了满足 O5 和 R2,我们只需要保证 的秩将增加,并且 R2 和 O5 中的 选择得足够大。
4.3 Violation reducing transformations / 减少 violation nodes 变换
We now describe the most essential transformation on the trees. The transformation reduces the number of potential violations in the tree by at lease one.
我们现在描述树上最基本的变换。该转换将树中潜在 violation nodes 的数量减少至少一个。
Assume we have two potential violations and of equal rank which are not roots or sons of a root. First we check that both and are violating nodes. If one of the nodes already is a good node we remove it from the corresponding violation set. Otherwise we proceed as described below.
假设我们有两个潜在的 violation nodes 和 ,它们的秩为 ,它们不是根或根的子节点。首先,我们检查 和 是否都是 violation nodes。如果其中一个节点已经是一个好节点,我们将其从相应的冲突集中删除。否则,我们将按如下所述进行。
Because of S4 we know that both and have at least one brother. If and are not brothers assume w.l.o.g. that and swap the subtrees rooted at and at a brother of . The number of violations can only decrease by doing this swap. We can now w.l.o.g. assume that and are brothers and both sons of node .
因为 S4,我们知道 和 都至少有一个兄弟。如果 和 不是兄弟,则不失一般性地假定 并交换 的子树与 的一个同秩兄弟的子树。通过执行此交换,violation nodes 只能减少。现在我们可以假设 和 是兄弟和节点 的两个儿子。
If has more than one brother of rank we just cut off and make it a good son of as described in Section 4.2. Because had at least two brothers of rank k, S4 is still satisfied at .
如果 有不止一个秩为 的兄弟,我们只需将 切掉,使其成为 的好儿子,如第 4.2 节所述。因为 至少有两个秩为 的兄弟,S4 仍然满足于 。
In case and are the only brothers of rank and we just cut off both and and make them new good sons of as described in Section 4.2. Because of invariant S4 we are forced to cut off both sons.
如果 和 是秩为 和 的唯一兄弟,我们只需将 和 都切掉,使它们成为第 4.2 节所述的 的新好儿子。由于 S4 不变,我们被迫将这两个儿子都切掉。
The only case that remains to be considered is when and are the only sons of rank and that . In this case we cut off and . The new rank of is uniquely given by one plus the rank of its new leftmost son. We replace by a son of of rank which can be cut off as described in Section 4.2. If was a son of we only cut off . If the replacement for becomes a violating node of rank we add it to . Finally, and are made good sons of as described in Section 4.2.
唯一需要考虑的情况是当 和 是秩 的唯一子节点并且 时。在这种情况下,我们切断了 和 。 的新秩是新的最左子节点的秩加 唯一给出。我们将 替换为等级为 的 的子节点,如第 4.2 节所述,该子节点可以被阶段。如果 是 的子节点我们只截断 。如果 的替换成为秩为 的 violation node,我们将其添加到 。最后,如第 4.2 节所述, 和 是 的好儿子。
4.4 Avoiding too many violations / 避免太多 violation nodes
We now describe how to avoid too many violations. The only violation sets we add violations to are and . Violations of rank larger than are added to and otherwise they are added to . The violations in are controlled by a guide. This guide guarantees that . We maintained a single array so we could access the violating nodes in by their rank.
我们现在描述如何避免太多 violation nodes。我们添加冲突的唯一冲突集是 和 。秩大于 的 violation nodes 将被添加到 ,否则,它们将被添加至 。 中的 violation nodes 由 guide 控制。这个 guide 需要保证 。我们维护了一个数组,这样我们就可以按秩访问 中的 violation nodes。
If we add a violation to the guide tells us for which ranks we should do violation reducing transformations as described in the previous section. We only do the transformation if there are exactly six violations of the given rank and that there is at least two violating nodes which are not sons of . If there are more than four violations that are sons of we cut the additional violations off and links them below . This makes these nodes good and does not accect the guides maintaining the sons at .
如果我们向 添加一个 violation nodes,指南会告诉我们应该对哪些秩进行 violation nodes 减少转换,如前一节所述。我们只在给定秩正好有六个 violation nodes 并且至少有两个 violation nodes 不是 的子节点的情况下进行转换。如果有四个以上的 violation nodes 是 的子节点,我们将其他 violation nodes 剪掉,并将它们 link 到 下。这使得这些节点变好,不会访问将子节点保持在 的 guide。
For each priority queue operation that is performed we increase the rank of by at least one by moving a constant number of sons from to — provided . By increasing the rank of by one we can afford creating new violations of rank larger than by invariant O5 and we can just add the violations to the list . If and we just cut of the largest sons of and link them below and finally add below . This will satisfy the invariants. Otherwise we cut off a son of of rank and delink this son and add the resulting trees below such that the rank of increases by at least one. By choosing large enough the invariants will become reestablished.
对于执行的每个优先队列操作,我们通过将恒定数量的子节点从 移动到 来将 的秩增加至少 ,前提是 。通过将 的秩增加 ,我们可以通过不变量 O5 创建秩大于 的 个新 violation nodes,我们只需将这些 violation nodes 添加到列表 。如果 且 ,我们只需 delink 的最大子节点并将它们 link 到 下方,最后在 下方 link 。这将满足不变量。否则,我们切断秩为 的 的子节点,并将该子节点 delink,并将生成的树添加到 以下,使得 的秩至少增加 。通过选择足够大的 ,不变量将重新建立。
If is empty we cannot increase the rank , but this also implies that is the node of maximum rank so no large violations can be created and R2 cannot become violated.
如果 为空,我们不能增加 的秩,但这也意味着 是最大秩的节点,因此不会创建大秩的冲突,也不会违反 R2。
4.5 Priority queue operations / 优先队列操作
In the following we describe how to implement the different priority queue operations such that the invariants from Section 2 are maintained.
在下文中,我们将描述如何实现不同的优先队列操作,以便维护第 2 节中的不变量。
-
MakeQueue is trivial. We return a pair of empty trees.
-
FindMin() returns .
-
Insert() is a special case of Meld where is a priority queue only containing one element.
-
Meld() involves at most four trees: two for each queue tree having the new minimum element, as root becomes the new tree. Thistree was either the tree of or of . If this tree is the tree of maximum rank we just add the other trees below this tree as described previously. In this case no violating node is created so transformation is done on the violating nodes.
Otherwise the tree of maximum rank becomes the new tree and the remaining trees are added below this node as described in Section 4.2, possibly delinking the new sons once if they have the same rank as . The violations created by this are treated as described in Section 4.4. The guides and arrays used at the old roots that now are linked below the new , node we just discard.
-
DecreaseKey() replaces the element of by (). If is less than we swap the elements in the two nodes. If is a good node we stop, otherwise we proceed as described in Section 4.4 to avoid having too many violations stored at .
-
DeleteMin() is allowed to take worst case tiem . First is made empty by moving all sons of to and making the root a rank zero son of . Then is deleted. This gives us at most independent trees. The minimum element is then found by looking at the sets and of the old root of and all the roots of the independent trees. If the minimum element is not a root we swap it with one of the independent trees of equal rank. This at most creates one new violation. By making the independent trees sons of the new minimum element and performing linking and delinking operations on these sons we can reestablish S1
S5 and R1 and R3. By merging the and sets at the root to one set and merging the old minimum element’s and sets with the set we get one new set of violations of size . Possibly we also have to add the single violation created by the swapping. By doing at most violation reducing transformations as described previously we can reduce the set to contain at most one violation of each rank. We make the resulting set the new set of the new root and let the corresponding set be empty. This implies that O1O5 and R2 are being reestablished. The guides involved are initiated according to the new situation at the root of . -
Delete(). If we let denote the smallest possible element, then Delete can be implemented as DecreaseKey(), followed by DeleteMin().
-
MakeQueue 很平凡,我们直接返回空树即可,
-
FindMin() 返回 ,
-
Insert() 是 Meld 的一种特殊情况,其中 是仅包含一个元素 的优先队列。
-
Meld() involves at most four trees: two for each queue tree. The tree having the new minimum element as root becomes the new tree. This tree was either the tree of or of . If this tree is the tree of maximum rank we just add the other trees below this tree as described previously. In this case no violating node is created so no transformation is done on the violating nodes.
-
Meld() 最多包含 个树:每个队列 个树。具有新的最小元素作为根的树成为新的 树。此树是 或 的 树。如果这棵树是最大秩的树,我们只需在这棵树下面添加其他树,如前所述。在这种情况下,不会创建违规节点,因此不会对违规节点进行转换。
否则,最大秩的树将成为新的 树,剩余的树将添加到此节点下,如第 4.2 节所述,如果新的子节点的秩与 相同,则可能会将其 delink 一次。由此产生的 violation nodes 将按照第 4.4 节所述进行处理。在旧根上使用的 guide 和数组现在链接到我们刚刚丢弃的新 节点下面。
-
DecreaseKey() replaces the element of by (). If is less than we swap the elements in the two nodes. If is a good node we stop, otherwise we proceed as described in Section 4.4 to avoid having too many violations stored at .
-
DecreaseKey() 将 的元素替换为 ()。如果 小于 ,则交换两个节点中的元素。如果 是一个好节点,我们将停止,否则我们将按照第 4.4 节所述继续,以避免在 中存储过多的violation nodes。
-
DeleteMin() 可以在最坏 时间内完成。通过将 的所有子节点移动到 并使 的根成为 的秩为 的子节点,使 为空。然后删除 。这给了我们 棵独立的树。然后通过查看 的旧根的集合 和 以及独立树的所有根来找到最小元素。如果最小元素不是根,我们将其与具有相同秩的独立树之一交换。这最多会创建一个新的 violation node。通过使独立树成为新的最小元素的子节点,并对这些子元素执行 次 link 和 delink 操作,我们可以重新建立 S1
S5 和 R1 和 R3。通过将根上的 和 集合合并为一个集合,并将旧的最小元素的 和 集合与该集合合并,我们得到了一组大小为 的新违规集合。可能我们还必须添加由交换创建的单个 violation node。通过如上所述最多执行 violation nodes 减少转换,我们可以将集合减少到每个秩最多包含一个 violation node。我们将结果集设为新根的新 集,并将相应的 集设为空。这意味着 O1O5 和 R2 正在重建。所涉及的 guide 是根据 根的新情况启动的。 -
Delete()。如果我们让 表示可能的最小元素,那么 Delete 可以实现为 DecreaseKey(),后面是 DeleteMin()。
5 Implementation details / 实现细节
In this section we summarize the required details of our new data structure.
在本节中,我们总结了新数据结构所需的详细信息。
Each node we represent by a record having the following fields.
我们用一条记录表示的每个节点具有以下字段。
-
The element associated with the node,
-
the rank of the node,
-
pointers to the node’s left and right brothers,
-
a pointer to the father node,
-
a pointer to the leftmost son,
-
pointers to the first node in the node’s and sets, and
-
pointers to the next and the previous node in the violation list that the node belongs to. The first node in a violation list or has its previous violation pointer pointing to .
-
节点存储的元素的值,
-
节点的秩,
-
指向节点的左兄弟和右兄弟的指针,
-
指向父节点的指针,
-
指向最左边子节点的指针,
-
指向节点的 和 集合中的第一个节点的指针,以及
-
指向该节点所属的冲突列表中的下一个和上一个节点的指针。冲突列表 或 中的第一个节点的上一个冲突指针指向 。
In addition to the above nodes we maintain the following three extendible arrays:
除上述信息外,我们还维护以下三个可扩展数组:
-
An array of pointers to sons of of rank ,
-
a similar array for , and
-
an array of pointers to nodes in of rank (if no node in exist of a given rank we let the corresponding pointer be NULL.)
-
指向秩为 的 的子节点的数组,
-
的类似数组,以及
-
指向秩为 的 中的节点的指针数组(如果 中不存在给定秩的节点,那么该指针为空)。
Finally we have five guides: Three to maintain the upper bounds on and and two to maintain the lower bounds on and .
最后,我们有五个 guide:三个用于维持 和 的上界,两个用于保持 和 的下界。
6. Conclusion / 结论
From the construction presented in the previous sections we conclude that:
根据前面章节中的构造,我们得出结论:
Theorem 6.1. An implementation of priority queues exists that supports the operations MakeQueue, FindMin, Insert, Meld and DecreaseKey in worst case time and DeleteMin and Delete in worst case time . The space required is linear in the number of elements contained in the priority queues.
定理 6.1:存在优先队列的实现,它支持最坏情况下 的MakeQueue, FindMin, Insert, Meld 和 DecreaseKey 操作,以及最坏情况时 的 DeleteMin 和 Delete 操作。所需的空间与优先队列中包含的元素数量成线性关系。
The data structure presented is quite complicated. An important issue for further work is to simplify the construction to make it applicable in practice. It would also be interesting to see if it is possible to remove the requirement for arrays from the construction.
给出的数据结构相当复杂。进一步工作的一个重要问题是简化结构,使其在实践中适用。看看是否有可能从构造中删除对数组的要求,也会很有趣。
Acknowledgement / 致谢
The author thanks Rolf Fagerberg for the long discussions that lead to the results presented in the paper.
作者感谢 Rolf Fagerberg 进行了长时间的讨论,最终得出了论文中的结果。
References / 参考资料
太长了。

