Professional Documents
Culture Documents
Binomial Heaps
Fibonacci Heaps
Data structures maintaining a dynamic set of items
with keys, supporting
Insert
Delete
Min, Extract-Min
Update
Union
Binomial tree
B0 : a single node.
Bk : merging two Bk -1 , root of one Bk -1 becomes a
child of the root of the other Bk -1.
Properties:
(1) B(k, i) = # nodes at level i of Bn .
level i of Bk : level i - 1 of left Bk -1 +
level i of left Bk -1
k
B(k, i) = B(k - 1, i - 1) + B(k - 1, i) =
i
k
(2) Bk has 2 nodes.
| Bk |= 2 | Bk -1 | .
n i = # Bi in the heap H = 0 or 1.
n :=| H |= n i 2i
i
# trees in H logn.
Implications:
Max. degree of any node = O(logn)
O(logn) trees in the heap, if no two roots have the
same degree.
Primitives
O(1) per op, including cost for maintaining min(H).
Create(x) -- A new node x is created.
Remove(x) Node x, a singleton, is removed from the
F-heap.
Cut(x)
x cannot be a root.
The subtree rooted at x is cut from parent(x) and
become a new tree.
When delete or update, or a second child of x is cutoff from x (cascade-cut).
Link(x,y)
x and y are roots.
degree(x)=degree(y).
key(x) key(y).
When only applied during consolidation.
Mark(x)
x cannot be a root.
When after first cut happens to any child of x.
Policy
1. Heap property.
2. (Link policy) Two roots are linked only if their
degrees are the same.
3. (Cut policy) After becoming a non-root, a node can
have at most one child cut off. (2nd cut-off causes the
node itself to be cut off from its parent and become a
root.)
4. Consolidate only after an extract-min is performed.
Lemma 1
= ( H N ) ( H 0 )
# cuts# links + ( H 0 ) = ( H N ) 0
Remark: proof does not dependon Policy.
= (T ) (0) = (T ) 0. ( (0) = 0)
# cascade - cuts # actual cuts.
Lemma 3
# cuts + # links 4# actual cuts + # insertions + n0 ,
where n0 = # trees initially
Pr oof :
Lemma 1 :# links # cuts + n0 + # insert.
Lemma 2 :# cascade - cuts # actual cuts.
# cuts 2# actual cuts
# cuts + # links 2# cuts + n0 4# actual cuts+ # insert + n0
Re mark : n0 = 0 amortized cost = O(1+ # actual cuts)
Lemma 4
Any node has degree 2 log n + 1, where n =# H .
Re mark : a consequence of Cut and Link policies.
Pr oof : G (k ) := min # nodes ina subtree rooted at a
node of degree k .
(min over all possible configurations of an F - heap
which is initially empty.)
w := a node of degree k in an F - heap of size n.
deg t ( w) := degree of w at time t.
Fibonacci sequence :
F (1) = F (2) = 1,
F (k ) = F (k 1) + F (k 2).
5 +1
F (k ) , =
.
2
F (k + 2) = F (k ) + ... + F (1) + 1.
k 2
G (0) = 1, G (1) = 2.
Inductively assume G (i ) F (i + 2), i = 0,..., k 1.
G (k ) G (k 2) + G (k 3) + ... + G (1) + 1 + 1 + 1
F (k ) + F (k 1) + ... + F (3) + 1 + 1 + 1
= F (k + 2).
n G (k ) F (k + 2) k k log n.
Lemma 5
A Fibonacci heap of size n has no more than
2 log n + 1 trees if no two roots are of the same degree.
Pr oof :
Lemma 4 deg ree of a node 2 log n.
= O ( c( i ))
i =1
Extract-min
The root with the minimum key is extracted.
The subtrees of this root become new trees.
Consolidation work merge trees using link op
until no two roots have the same degree.
Delete(x)
cut(x), then cut (y) for each child y of x.
Remove(x).
Amortized cost = O(deg(x))=O(log|H|).
Decrease(x)
Update on x and if heap property is violated, then
cut(x).
Amortized cost = O(1).