Relaxed Fibonacci heaps: An alternative to Fibonacci heaps with worst case rather than amortized time bounds∗
- Chandrasekhar Boyapati
- C. Pandu Rangan
Department of Computer Science and Engineering Indian Institute of Technology, Madras 600036, India
Email: [email protected]
November 1995
Introduction
The implementation of priority queues is a classical problem in data structures. Priority queues find applications in a variety of network problems like single source shortest paths, all pairs shortest paths, minimum spanning tree, weighted bipartite matching etc. [1] [2] [3] [4] [5]
In the amortized sense, the best performance is achieved by the well known
Fibonacci heaps. They support delete and delete min in amortized (log ) time and find min, insert, decrease key and meld in amortized constant time.
Fast meldable priority queues described in [1] achieve all the above time bounds in worst case rather than amortized time, except for the decrease key operation which takes (log ) worst case time. On the other hand, relaxed heaps described in [2] achieve in the worst case all the time bounds of the Fibonacci heaps except for the meld operation, which takes (log ) worst case
∗
1time. The problem that was posed in [1] was to consider if it is possible to support both decrease key and meld simultaneously in constant worst case time.
In this paper, we solve this open problem by presenting relaxed Fibonacci heaps as a new priority queue data structure for a Random Access Machine (RAM). (The new data structure is primarily designed by relaxing some of the constraints in Fibonacci heaps, hence the name relaxed Fibonacci heaps.) Our data structure supports the operations find minimum, insert, decrease key and meld, each in (1) worst case time and delete and delete min in (log ) worst case time. The following table summarizes the discussion so far.
For simplicity we assume that all priority queues have at least three elements.
- We use the symbol
- to denote a relaxed Fibonacci heap and to denote the
size of a priority queue it represents. Unless otherwise mentioned, all the time bounds we state are for the worst case.
In Section 1, we prove some results regarding binomial trees which will be central to establishing the (log ) time bound for the delete min operation. In Section 2.1, we describe the relaxed Fibonacci heaps. In Section 3, we describe the various operations on relaxed Fibonacci heaps.
1 Some results regarding binomial trees
Consider the following problem. We are given a binomial tree has degree . The children of any node in are arranged in the increasing are 1, ... −1, then
[5] whose root order of their degrees. That is, if the children of
= .
,
0
We are to remove some nodes from this tree. Every time a node gets removed, the entire subtree rooted at that node also gets removed. Suppose the resulting
0
tree is 0, which is not necessarily a binomial tree. For any node
∈
,denotes the number of children lost by . For any node
∈
- 0, define
- as
2
−1
- .
- the weight of node
Define weight
Given an upper bound on weight
- as follows:
- = 0, if
- = 0. Else,
- = 2
0
- .
- =
- for all nodes
∈
0
- that
- can lose, let
- be the tree
obtained by removing as many nodes from as possible.
0
Lemma 1
defined above has the following properties:
0
- 1. Let
- be any node in 0. If
= 0.
- = 0 and if
- is a descendant of
- then
0
0
- 2. Let
- be any node in
- such that
- = . Then the children lost by
are its last children (which had the highest degrees in ).
- 3. Let
- and
- be two nodes that have the same parent such that
0
- , in . Then, in
- ,
≥
.
- 4. Let a node
- have four consecutive children
- ,
=
- ,
- and
=
be-
- +3
- +1
- +2
longing to 0. Then it cannot be true that
=
- +1
- +2
0.
+3
Proof: If any of the 4 statements above are violated, then we can easily show that by reorganizing the removal of nodes from , we can increase the number of
- nodes removed from without increasing the weight
- removed. In particular, if
statement 4 is violated, then we can reorganize the removal of nodes by increasing
- by one and decreasing
- and
- by one each.
- +3
- +1
Lemma 2 Let
be a binomial tree whose root has degree . Let
- 4
- 0 + 3,
where loose be 2 . Then,
= dlog 0e, for some 0. Let the upper bound on the weight that can
0
0
- will have more than
- nodes in it.
- 0
- 0
- Proof: Let the children of the root of be
- ,
- 1, ..., −1. We first claim
0
- that
- = 0. Or else, it follows trivially from the previous lemma that
0
≥
+ 2, because statement 4 implies that there can be at most
- 4
- 0+3
- 0
three consecutive nodes which have lost the same number of children. This in
0+1
turn implies that the weight lost by is greater than 2 possible. Thus our claim holds.
≥ 2 , which is not
0
- Since
- = 0, no nodes are deleted from the subtree rooted at
- ,
- 0
- 0
according to statement 1 of the previous lemma. Thus the number of nodes in
0
0
- is greater than 2 ≥
- .
0
2 The relaxed Fibonacci heaps
Our basic representation of a priority queue is a heap ordered tree where each node contains one element. This is slightly different from binomial heaps [4] and Fibonacci heaps [3] where the representation is a forest of heap ordered trees.
3
2.1 Properties of the relaxed Fibonacci heaps
We partition the children of a node into two types, type I and type II. A relaxed Fibonacci heap must satisfy the following constraints.
1. A node of type I has at most one child of type II. A node of type II cannot have any children of type II.
- 2. With each node we associate a field
- which denotes the number of
children of type I that has. (Thus the number of children of any node
- is either
- + 1 or
- depending on whether
- has a child of type
II or not.)
0
- (a) The root is of type I and has
- zero.
- has a child
- of type
and let
II.
- 0
- 0
- (b) Let
- = . Let the children of
- be
- ,
- 1, ...,
- 0
- −1
0
- ≤
- ≤
- ≤
- . Then,
- =
≤
- 0
- 1
- −1
+ 1.
−1
- 3. With each node
- of type I we associate a field
- which denotes the
number of children of type I lost by zero.
- since its
- field was last reset to
- For any node
- of type I in , define
- as the weight of node
- as
−1
- follows:
- = 0, if
- = 0. Else,
- = 2
- .
Also for any node losing its last child. That is,
- of type I, define
- as the −in2crease in
- due to
- respectively depending
- = 0 or 1 or 2
- on whether
- = 0 or 1 or greater than one.
- Define weight
- =
- for all of type I in
- .
Every relaxed Fibonacci heap has a special variable , which is equal to one of the nodes of the tree. Initially, = .
- (a)
- =
- =
- =
- =
- = 0.
=
- 0
- 1
- −1
(b) Let of be any node of type I. Let of type I be and let the children
- ,
- 1, ...,
- −1. Then, for any
- ,
- +
0
≥ .
(c)
≤
- +
- .
4. Associated with type II in
- we have a list
- = (
- ) of all0 nodes of
- 1
- 2
- other than 0. Each node
- was originally the
till some meld operation. Let just before that meld operation. of some relaxed Fibonacci heap number of nodes in denote the
(a) (b)
≤ 4dlog e + 4.
+ ≤ .
4
R
25
R’
R2
8
R1 13
15
17 R0
- 25
- 21,1
24,1
- 12,1
- 9
P
14 M1
30
- L
- = ( M1 )
M
20 23
Figure 1: A relaxed Fibonacci heap
Example
Figure 1 shows a relaxed Fibonacci heap. The nodes of type I are represented by circles and the nodes of type II are represented by squares. Each node contains either and the list
- or just
- if
- = 0. The node
are also shown.
Lemma 3 The heap order implies that the minimum element is at the root.
- Lemma 4 For any node
- of type I,
- ≤ 4 0 + 3, where
+ 3. If
= dlog e.
0
- Proof: On the contrary, say
- =
= 2
- 4
- 1, then
- ,
0
- when expanded, will contain the term
- −1. Th−u2s according to property
−1
3c, 2
- ≤
- ≤ +
- = +2
- −2. That is, 2
- ≤ . Hence,
- ≤ 2 .
This inequality obviously holds true even if the subtree rooted at , say , is not more than 2 .
Let us now try to estimate the minimum number of nodes present in us first remove all the children of type II in and their descendants. In the process, we might be decreasing the number of nodes in the tree but we will not be increasing
≤ 1. Thus the weight lost by
. Let
.
In the resulting 0 , we know from property 3b that for any ( + 1) child
- 0
- 0
- of any node
- ,
- +
≥ . But for the binomial tree problem
- 0
- 0
described in Section 1, nodes present in
- +
- = . Thus the minimum number of
is at least equal to the minimum number of nodes present in
5a binomial tree of degree after it loses a weight less than or equal to 2 . But according to Lemma 2, this is more than . Thus, which is obviously not possible. has more than nodes,
- Lemma 5 For any node
- in , the number of children of
- ≤ 4 0 + 4, where
= dlog e.
0
Proof: If
is a node of type I, the number of children of
≤
+ 1 ≤
- 4
- 0 + 4, according to the0 previous lemma.
- From property 2b,
- =
≤
+ 1 ≤ 4 + 4, according
- −1
- 0
- to the previous lemma, since
- is of type I. Thus, number of children of
−1
- 0
- 0
=If
≤ 4 0 + 4.
0
- is any node of type II other than
- ,
- is equal to some
- in
- ,
- according to property 4. According to property 4a,
- ≤ 4dlog e + 4.
- But according to property 4b,
- . Thus the number of children of
- =
≤ 4 0 + 4.
Remarks
The restrictions imposed by property 3c are much weaker than those in fast meldable queues [1] or in relaxed heaps [2]. But according to the above lemma, the number of children of any node is still (log ). We believe that the introduction of property 3c is the most important contribution of this paper.
2.2 Representation
The representation is similar to that of Fibonacci heaps as described in [5]. The children of type I of every node are stored in a doubly linked list, sorted according to their degrees. Besides, each node of type I has an additional child pointer which can point to a child of type II.
0
To preserve the sorted order, every node that is inserted as a child of must be inserted at the appropriate place. To achieve this in constant time,0 we maintain an auxiliary array degree .
- such that [ ] points to the first child of
- of
0
- We will also need to identify two children of
- of same degree, if they exist.
- To achieve this in constant time, we maintain a linked list
- of pairs of nodes
such that of degree is even.
0
- that are children of
- and have same degree and a boolean array
0
[ ] is true if and only if the number of children of Besides, we will also require to identify some node in such that
1, if such a node exists. To implement this in constant time, we maintain a list of all nodes in such that 1.
6
3 Operations on relaxed Fibonacci heaps
In this section, we will describe how to implement the various operations on relaxed Fibonacci heaps. But before we do that, we will describe a few basic operations namely, link, add, reinsert and adjust.
Though we will not be mentioning it explicitly every time, we will assume that whenever a node of type I loses a child, its by one unless the node is or a child of 0. Similarly, whenever a node is inserted
- a child of 0, its
- field is automatically reset to zero. We also assume that if
node gets deleted from the tree after a delete min operation, then is reset field is automatically incremented
- to to ensure that node still belongs to
- .
3.1 Some basic operations
The link operation is similar to the linking of trees in binomial heaps and Fibonacci heaps.
- Algorithm 1 : Link( ,
- ,
- )
- /* Link the two trees rooted at
- and
- into one tree */
0
- /*
- and
- are children of
- and have equal degrees, say */
- 1. Delete the subtrees rooted at
- and
- from
2. If
then
- (
- )
3. Make 4. Make the last child of (whose
0
- now = + 1) a child of
- of
- Algorithm 2 : Add( ,
- )
- /* Add the tree rooted at
- to the relaxed Fibonacci heap */
0
- 1. Make
- a child of
- of
- 0
- 0
2. If
then
0 then
((
))
- 0
- 0
3. If 4. If among the children of such that
- there exist any two different nodes
- and
=
then
- (
- )