Title: Fibonacci heaps, and applications
1Fibonacci heaps,and applications
2Yet a better MST algorithm (Fredman and Tarjan)
Iteration i We grow a forest, tree by tree, as
follows. Start with a singleton vertex and
continue as in Prims algorithm until either 1)
The size of the heap is larger than ki 2) Next
edge picked is connected to an already grown
tree 3) Heap is empty (if the graph is connected
this will happen only at the very end)
3Contract each tree into a single vertex and start
iteration i1. How do we contract ?
Do a DFS on the tree, marking for each vertex the
of the tree which contains it. Each edge e gets
two numbers l(e), h(e) of the trees at its
endpoints. If h(e) l(e) remove e (self
loop). (stable) Bucket sort by h(e) and by l(e),
parallel edge then become consecutive so we can
easily remove them. O(m) time overall.
4Analysis each iteration takes linear time
Let ni be the number of vertices in the i-th
iteration.
O(m) inserts, O(m) decrease-key, O(ni)
delete-min total O(nilog(ki) m)
Set ki 2(2m/ni) so the work per phase is O(m).
5How many iterations do we have ?
Every tree in iteration i is incident with at
least ki edges. So ni1 ki ? 2mi ? 2m
gt ni1 ? 2mi / ki ? 2m / ki
2m/n
gt ki1 2(2m/ni1) ? 2ki ?
6This runs in O(m?(m,n))
Once ki ? n we stop.
So the number of iterations is bounded by the
minimum i such that
? n
i
j mini 2m/n ? logi(n) ?(m,n)
7Summary
The overall complexity of the algorithm is O(m
?(m,n) )
Where ?(m,n) mini logi(n) ? 2m/n for every
m ? n ?(m,n) ? log(n)
- For m gt n log(n) the algorithm degenerates to
Prims. - One can prove that O(m ?(m,n) ) O(nlogn m).
8So our record is O(m ?(m,n) ), can we do better ?
Where is the bottleneck now ?
We may scan an edge ?(m,n) times. When we
abandon a heap we will rescan an edge per vertex
in the heap.
Delay scanning of edges (heavy edges)
9Packets (Gabow, Galil, Spencer, Tarjan)
- Group the edges incident to each vertex into
packets of size p each - Sort each packet
- Treat each packet as a single edge (the first
edge in the packet)
10Working with packets
- When you extract the min from the heap it is
associated with a packet whose top edge is (u,v). - You add (u,v) to the tree, delete (u,v) from its
packet, and relax this packet of u - Traverse the packets of v and relax each of them
- How do you relax a packet ?
11Relaxing packet p of vertex v
- Check the smallest edge (v,u) in p
- If u is already in the tree, discard (v,u), and
recur - If u is not in the heap insert it into the heap
with weight w(v,u) - If u is in the heap
- If the weight of u is larger than the weight of
(v,u) then decrease its key - Let p be the packet with larger weight among
the current and the previous packet associated
with u, discard its first edge and recur on p
12Analysis
- Initialization O(m) to partition into packets,
O(mlog(p)) to sort the packets - An iteration O(nilog(ki)) for extract-mins, and
O(m/p) work for each packet - Additional work per packet we can charge to an
edge which we discard Total O(m)
Summing up
13Analysis (Cont)
O(mlog(p) S(nilog(ki) m/p) )
iterations
Set ki 2(2m/pni) so the work per phase is
O(m/p).
Set k1 2(2m/n) the work in the first phase
is O(m)
Every tree in iteration i is incident with at
least ki packets So ni1 ki ? 2m/p
gt ni1 ? 2m / pki
? We have ?(m,n) iterations
2m/n
gt ki1 2(2m/pni1) ? 2ki ?
14Analysis (Cont)
The running time is
O(mlog(p) ?(m,n) m/p )
Choose p ?(m,n) so we get
O(mlog(?(m,n)))
15But we cheated
If we want the running time per iteration to be
m/p, how do we do contractions ?
Use union/find (conract by uniting vertices and
concatenating their adjacency lists)
You get an ?(m,n) overhead when you relax a
packet and overall
O(m ?(m,n) m log(?(m,n)) Sni ) O(m
log(?(m,n)))
16Furthermore, it wasnt our only cheat..
We cannot partition the edges incident to a
vertex into packets each of size p exactly ?
So there can be at most one undersized packet per
vertex
When you contract merge undersized packets
How do you merge undersized packets ?
17Use a little F-heap to represent each packet
This gives log(p) overhead to relax a packet
But still the overall time is O(m log(?(m,n)))