1 / 11

Priority Queues

Learn about priority queues, binomial queues, Fibonacci heaps, Dijkstra's algorithm, and Fibonacci heap operations, with an in-depth overview of implementation details and key theorems.

michellej
Download Presentation

Priority Queues

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PriorityQueues MakeQueuecreate new emptyqueue Insert(Q,k,p) insertkeykwithpriorityp Delete(Q,k) deletekeyk (given a pointer) DeleteMin(Q) deletekeywith min priority Meld(Q1,Q2) mergetwo sets Empty(Q) returnsifempty Size(Q) returns #keys FindMin(Q) returnskeywith min priority

  2. PriorityQueues – Ideal Times Thm 1) Meld O(n1-ε)  DeleteMinΩ(log n) • 2) Insert, DeleteO(t)  FindMinΩ(n/2O(t)) Follows from Ω(n∙logn) sortinglowerbound 2) [G.S. Brodal, S. Chaudhuri, J. Radhakrishnan,The Randomized Complexity of Maintaining the Minimum. In Proc. 5th Scandinavian Workshop on Algorithm Theory, volume 1097 of Lecture Notes in Computer Science, pages 4-15. Springer Verlag, Berlin, 1996] MakeQueue, Meld, Insert, Empty, Size, FindMin: O(1) Delete, DeleteMin: O(log n)

  3. 0 3 1 Binomial Queues 3 2 9 2 0 0 1 4 5 7 8 1 0 0 • [Jean Vuillemin, A data structure for manipulating priority queues, • Communications of the ACM archive, Volume 21(4), 309-315, 1978] 6 5 8 0 7 • Binomial tree • each node stores a (k,p) and satisfiesheaporderwithrespect to priorities • all nodes have a rankr (leaf = rank 0, a rank r node has exactlyonechild of each of the ranks 0..r-1) • Binomial queue • forest of binomial treeswithrootsstored in a list withstrictlyincreasingrootranks

  4. Problem • Hints • Two rank itreescanbelinked to create a rank i+1 tree in O(1) time • Potential Φ = max rank + #roots x y x y r+1 r r link x ≥ y r Implement binomial queue operations to achieve the ideal times in the amortizedsense

  5. Dijkstra’sAlgorithm(Single sourceshortestpath problem) AlgorithmDijkstra(V, E, w, s) Q := MakeQueue dist[s] := 0 Insert(Q, s, 0) forvV \ { s } do dist[v] := +∞ Insert(Q, v, +∞) whileQ ≠ do v := DeleteMin(Q) foreachu : (v, u)  Edo ifu  Qanddist[v]+w(v, u) < dist[u] then dist[u] := dist[v]+w(v, u) DecreaseKey(u, dist[u]) n x Insert + n x DeleteMin+ m x DecreaseKey Binaryheaps / Binomial queues : O((n + m)∙logn)

  6. PriorityBounds AmortizedWorst-case  Dijkstra’sAlgorithm O(m + n∙logn) (and Minimum SpanningTree O(m∙log* n)) Empty, FindMin, Size, MakeQueue – O(1) worst-case time

  7. 3 FibonacciHeaps 3 2 0 • [Fredman, Tarjan, Fibonacci Heaps and Their Use in Improved Network Algorithms, • Journal of the ACM, Volume 34(3), 596-615, 1987] 4 7 1 0 6 5 0 7 • F-tree • heaporderwithrespect to priorities • all nodes have a rankr {degree, degree + 1} (r = degree + 1  node is marked as having lost a child) • The i’thchildof a node from the right has rank≥i - 1 • FibonacciHeap • forest (list) of F-trees (treescan have equal rank)

  8. FibonnaciHeap Property Thm Max rank of a node in an F-tree is O(log n) ProofA rank r node has at least 2 children of rank ≥ r – 3. By inductionsubtreesize is at least 2└r/3┘□ ( in fact the size is at leastr , where=(1+5)/2 )

  9. Problem • Hints • Two rank itreescanbelinked to create a ranki+1 tree in O(1) time • Eliminating nodes violating orderor nodes having lost twochildren • Potential Φ = 2∙marks + #roots x x y x y x r+1 r y r y link x ≥ y r d r cut degree(x) = d ≤ r-2 ImplementFibonacciHeap operations withamortized O(1) time for all operations, except O(log n) for deletions

  10. Implementation of FibonacciHeap Operations FindMinMaintain pointer to min root InsertCreate new tree = new rank 0 node +1 JoinConcatenatetwoforestsunchanged DeleteDecreaseKey -∞ + DeleteMin DeleteMinRemove min root-1 + addchildren to forest+O(log n ) + bucketsortroots by rankonly O(log n ) not linkedbelow + link whiletworootsequal rank -1 each DecreaseKeyUpdatepriority + cut edge to parent +3 + ifparentnow has r – 2 children, recursively cut parentedges -1 each, +1 final cut * = potential change

  11. Worst-Case Operations (withoutJoin) • [Driscoll, Gabow, Shrairman, Tarjan, Relaxed Heaps: An Alternative to Fibonacci Heaps with Applications to Parallel Computation, • Communications of the ACM, Volume 34(3), 596-615, 1987] Basicideas Require ≤ max-rank + 1 trees in forest(otherwise rank r where two trees can be linked) Replacecutting in F-trees by having O(log n) nodes violating heaporder Transformationreplacingtwo rank rviolations by one rank r+1 violation

More Related