Fibonacci heaps, and applications - PowerPoint PPT Presentation

About This Presentation
Title:

Fibonacci heaps, and applications

Description:

We may scan an edge (m,n) times. ... 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) ... – PowerPoint PPT presentation

Number of Views:94
Avg rating:3.0/5.0
Slides: 18
Provided by: Sint1
Category:

less

Transcript and Presenter's Notes

Title: Fibonacci heaps, and applications


1
Fibonacci heaps,and applications
2
Yet 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)
3
Contract 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.
4
Analysis 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).
5
How 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 ?
6
This 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)
7
Summary
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).

8
So 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)
9
Packets (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)

10
Working 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 ?

11
Relaxing 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

12
Analysis
  • 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
13
Analysis (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 ?
14
Analysis (Cont)
The running time is
O(mlog(p) ?(m,n) m/p )
Choose p ?(m,n) so we get
O(mlog(?(m,n)))
15
But 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)))
16
Furthermore, 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 ?
17
Use 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)))
Write a Comment
User Comments (0)
About PowerShow.com