| Brodal queue | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Type | Heap/priority queue | |||||||||||
| Invented | 1996 | |||||||||||
| Invented by | Gerth Stølting Brodal | |||||||||||
| ||||||||||||
In computer science, the Brodal queue is a heap/priority queue structure with very low worst case time bounds: for insertion, find-minimum, meld (merge two queues) and decrease-key and for delete-minimum and general deletion. They are the first heap variant to achieve these bounds without resorting to amortization of operational costs. Brodal queues are named after their inventor Gerth Stølting Brodal. [1]
While having better asymptotic bounds than other priority queue structures, they are, in the words of Brodal himself, "quite complicated" and "[not] applicable in practice." [1] Brodal and Okasaki describe a persistent (purely functional) version of Brodal queues. [2]
A Brodal queue is a set of two trees and and 5 guides. The definition of the guide data structure can be found in the following section. For both trees, each node has a rank, this rank is useful for later operations and intuitively corresponds to the logarithm of the size of the subtree rooted in the node. We note the number of children of the node with rank . We will also use for the root of tree and for the root of tree . At each given time, every subtree rooted in a node needs to fulfill these 5 invariants :
Here guaranties us that the size of the subtree rooted in a node is at least exponential to the rank of that node. In addition, bounds the number of children of each rank for a given node, this implies that all nodes have rank and degrees in .
In a Brodal queue, not every node will have a bigger value than its parent, the nodes vialoating this condition will be called violating nodes. However, we want to keep the number of violating nodes relatively small. To keep track of violating nodes, we create for each node two sets and of nodes larger than . Intuitively, are the nodes larger of with large rank (such that if ), and are the nodes with small rank (). These sets are implemented using doubly linked list meanung they have an order. In particular, all violating nodes added to are added at the front of the list, and all violating nodes added to are inserted next to a node of same rank. The and lists fulfill these 5 invariants (we let denote the number of nodes in of rank ):
This definition is based on the definition from Brodal's paper [1] .
We assume that we have a sequence of variables and we want to make sure that for some threshold . The only operation allowed is which decreases by at least 2 and increases by at most 1. We can assume without loss of generality that reduces by 2 and increases by 1.
If a is increased by one, the goal of the guide is to tell us on which indices to apply in order to respect the threshold. The guide is only allowed to make calls to the function for each increase.
The guide has access to another sequence such that and . As long as after the increase of we have we do not need to ask help from our guide since is "far" bellow . However, if before the increase, then we have after the change.
To simplify the explanation, we can assume that , so that . The guide will create blocks in the sequence of of form where we allow there to be no . The guide maintains the invariant that each element which isn't in a block is either a or a . For example, here are the blocks for a sequence of .
The guide is composed of 3 arrays :
With this definition, a guide has two important properties :
This way, the guide is able to decide which indices to in time . Here is an example :
To reestablish the blocks, the pointers of the 1 and 0 added to the first block now point to the same cell as all the other elements from the first block, and the value of the second block's cell is changed to . In the previous example, only two operations were needed, this is actually the case for all instances. Therefore, the queue only needs operations to reestablish the property.
Here are time complexities [3] of various heap data structures. The abbreviation am. indicates that the given complexity is amortized, otherwise it is a worst-case complexity. For the meaning of "O(f)" and "Θ(f)" see Big O notation. Names of operations assume a min-heap.
| Operation | find-min | delete-min | decrease-key | insert | meld | make-heap [a] |
|---|---|---|---|---|---|---|
| Binary [3] | Θ(1) | Θ(log n) | Θ(log n) | Θ(log n) | Θ(n) | Θ(n) |
| Skew [4] | Θ(1) | O(log n) am. | O(log n) am. | O(log n) am. | O(log n) am. | Θ(n) am. |
| Leftist [5] | Θ(1) | Θ(log n) | Θ(log n) | Θ(log n) | Θ(log n) | Θ(n) |
| Binomial [3] [7] | Θ(1) | Θ(log n) | Θ(log n) | Θ(1) am. | Θ(log n) [b] | Θ(n) |
| Skew binomial [8] | Θ(1) | Θ(log n) | Θ(log n) | Θ(1) | Θ(log n) [b] | Θ(n) |
| 2–3 heap [10] | Θ(1) | O(log n) am. | Θ(1) | Θ(1) am. | O(log n) [b] | Θ(n) |
| Bottom-up skew [4] | Θ(1) | O(log n) am. | O(log n) am. | Θ(1) am. | Θ(1) am. | Θ(n) am. |
| Pairing [11] | Θ(1) | O(log n) am. | o(log n) am. [c] | Θ(1) | Θ(1) | Θ(n) |
| Rank-pairing [14] | Θ(1) | O(log n) am. | Θ(1) am. | Θ(1) | Θ(1) | Θ(n) |
| Fibonacci [3] [15] | Θ(1) | O(log n) am. | Θ(1) am. | Θ(1) | Θ(1) | Θ(n) |
| Strict Fibonacci [16] [d] | Θ(1) | Θ(log n) | Θ(1) | Θ(1) | Θ(1) | Θ(n) |
| Brodal [17] [d] | Θ(1) | Θ(log n) | Θ(1) | Θ(1) | Θ(1) | Θ(n) [18] |
Gerth Stølting Brodal is a professor at the University of Aarhus, Denmark. [19] He is best known for the Brodal queue.