Dijkstra's SSSP & Fibonacci Heaps

Dijkstra's SSSP & Fibonacci Heaps

CSE 548: Analysis of Algorithms Lectures 14 & 15 ( Dijkstra’s SSSP & Fibonacci Heaps ) Rezaul A. Chowdhury Department of Computer Science SUNY Stony Brook Fall 2012 Fibonacci Heaps ( Fredman & Tarjan, 1984 ) A Fibonacci heap can be viewed as an extension of Binomial heaps which supports DECREASE -KEY and DELETE operations efficiently. Binary Heap Binomial Heap Heap Operation ( worst-case ) ( amortized ) MAKE -HEAP Θ Θ 1 1 INSERT Ο Θ log ͢ 1 MINIMUM Θ Θ 1 1 EXTRACT -MIN Ο Ο log ͢ log ͢ UNION Θ Θ ͢ 1 DECREASE -KEY Ο log ͢ Ǝ DELETE Ο log ͢ Ǝ Fibonacci Heaps ( Fredman & Tarjan, 1984 ) A Fibonacci heap can be viewed as an extension of Binomial heaps which supports DECREASE -KEY and DELETE operations efficiently. Binary Heap Binomial Heap Heap Operation ( worst-case ) ( amortized ) MAKE -HEAP Θ Θ 1 1 INSERT Ο Θ log ͢ 1 MINIMUM Θ Θ 1 1 EXTRACT -MIN Ο Ο log ͢ log ͢ UNION Θ Θ ͢ Ο 1 DECREASE -KEY Ο ( worstlog case ͢ ) log ͢ Ο DELETE Ο ( worstlog case͢ ) log ͢ Fibonacci Heaps ( Fredman & Tarjan, 1984 ) A Fibonacci heap can be viewed as an extension of Binomial heaps which supports DECREASE -KEY and DELETE operations efficiently. Binary Heap Binomial Heap Fibonacci Heap Heap Operation ( worst-case ) ( amortized ) ( amortized ) MAKE -HEAP Θ Θ Θ 1 1 1 INSERT Ο Θ Θ log ͢ 1 1 MINIMUM Θ Θ Θ 1 1 1 EXTRACT -MIN Ο Ο Ο log ͢ log ͢ log ͢ UNION Θ Θ Θ ͢ Ο 1 1 DECREASE -KEY Ο Θ ( worstlog case ͢ ) log ͢ 1 Ο DELETE Ο Ο ( worstlog case͢ ) log ͢ log ͢ Dijkstra’s SSSP Algorithm with a Min-Heap ( SSSP: Single-Source Shortest Paths ) Input: Weighted graph with vertex set and edge set , a weight function , and ́a source Ɣ ͐, ̿ vertex . ͐ ̿ Output: For all ͫ , is set to theͧ ∈ shortest ́ ͐ distance from to . ͪ ∈ ́ ͐ ͪ. ͘ ͧ ͪ Dijkstra-SSSP ( ) ́ Ɣ ͐, ̿ , ͫ, ͧ 1. for each do 2. ͪ ∈ ́ ͐ ͪ. ͘ ← ∞ 3. ͧ. ͘ ← 0 { empty min-heap } ͂ ← & 4. for each do INSERT ( ) 5. while ͪ ∈do ́ ͐ ͂, ͪ ͂ ƕ ∅ 6. EXTRACT -MIN ( ) 7. forͩ ←each ͂ do ͪ ∈ ̻͘͞ ͩ 8. if then ͪ. ͘ Ƙ ͩ. ͘ ƍ ͫ0,1 9. DECREASE -KEY ( ) ͂, ͪ, ͩ. ͘ ƍ ͫ0,1 10. ͪ. ͘ ← ͩ. ͘ ƍ ͫ0,1 Dijkstra’s SSSP Algorithm with a Min-Heap ( SSSP: Single-Source Shortest Paths ) Input: Weighted graph with vertex set and edge set , a weight function , and ́a source Ɣ ͐, ̿ vertex . ͐ ̿ Output: For all ͫ , is set to theͧ ∈ shortest ́ ͐ distance from to . ͪ ∈ ́ ͐ ͪ. ͘ ͧ ͪ Dijkstra-SSSP ( ) Let and ́ Ɣ ͐, ̿ , ͫ, ͧ 1. for each do ͢ Ɣ ́ ͐ ͡ Ɣ ́ ̿ 2. ͪ ∈ ́ ͐ ͪ. ͘ ← ∞ # INSERTS ͧ. ͘ ← 0 3. { empty min-heap } # EXTRACT -MINS ͂ ← & Ɣ ͢ 4. for each do INSERT ( ) # DECREASE -KEYS 5. while ͪ ∈do ́ ͐ ͂, ͪ Ɣ ͢ ͂ ƕ ∅ 6. EXTRACT -MIN ( ) ƙ ͡ 7. forͩ ←each ͂ do Total cost ͪ ∈ ̻͘͞ ͩ 8. if then ͪ. ͘ Ƙ ͩ. ͘ ƍ ͫ0,1 9. DECREASE -KEY ( ) ͂, ͪ, ͩ. ͘ ƍ ͫ0,1 ). -/ 3/-/ͯ$) 10. ƙ ͢ ͗ͣͧͨ ƍ ͗ͣͧͨ ͪ. ͘ ← ͩ. ͘ ƍ ͫ0,1 ƍ ͡ ͗ͣͧͨ - . ͯ 4 Dijkstra’s SSSP Algorithm with a Min-Heap ( SSSP: Single-Source Shortest Paths ) Input: Weighted graph with vertex set and edge set , a weight function , and ́a source Ɣ ͐, ̿ vertex . ͐ ̿ Output: For all ͫ , is set to theͧ ∈ shortest ́ ͐ distance from to . ͪ ∈ ́ ͐ ͪ. ͘ ͧ ͪ Dijkstra-SSSP ( ) Let and ́ Ɣ ͐, ̿ , ͫ, ͧ 1. for each do ͢ Ɣ ́ ͐ ͡ Ɣ ́ ̿ 2. ͪ ∈ ́ ͐ ͪ. ͘ ← ∞ For Binary Heap ( worst-case costs ): 3. ͧ. ͘ ← 0 { empty min-heap } ͂ ← & 4. for each do INSERT ( ) Ο 5. while ͪ ∈do ́ ͐ ͂, ͪ ͗ͣͧͨ ). -/ Ɣ logΟ ͢ ͂ ƕ ∅ 6. EXTRACT -MIN ( ) ͗ͣͧͨ3/-/ͯ$) Ɣ Οlog ͢ 7. forͩ ←each ͂ do ͪ ∈ ̻͘͞ ͩ - . ͯ 4 8. if then ͗ͣͧͨ Ɣ log ͢ ͪ. ͘ Ƙ ͩ. ͘ ƍ ͫ0,1 9. DECREASE -KEY ( ) Total cost ( worst-case ) ͂, ͪ, ͩ. ͘ ƍ ͫ0,1 10. ∴ Ο ͪ. ͘ ← ͩ. ͘ ƍ ͫ0,1 Ɣ ͡ ƍ ͢ log ͢ Dijkstra’s SSSP Algorithm with a Min-Heap ( SSSP: Single-Source Shortest Paths ) Input: Weighted graph with vertex set and edge set , a weight function , and ́a source Ɣ ͐, ̿ vertex . ͐ ̿ Output: For all ͫ , is set to theͧ ∈ shortest ́ ͐ distance from to . ͪ ∈ ́ ͐ ͪ. ͘ ͧ ͪ Dijkstra-SSSP ( ) Let and ́ Ɣ ͐, ̿ , ͫ, ͧ 1. for each do ͢ Ɣ ́ ͐ ͡ Ɣ ́ ̿ 2. ͪ ∈ ́ ͐ ͪ. ͘ ← ∞ For Binomial Heap ( amortized costs ): 3. ͧ. ͘ ← 0 { empty min-heap } ͂ ← & 4. for each do INSERT ( ) Ο 5. while ͪ ∈do ́ ͐ ͂, ͪ ͗ͣͧͨ ). -/ Ɣ 1 Ο ͂ ƕ ∅ 6. EXTRACT -MIN ( ) ͗ͣͧͨ3/-/ͯ$) Ɣ Οlog ͢ 7. forͩ ←each ͂ do ͪ ∈ ̻͘͞ ͩ - . ͯ 4 ( worst-case ) 8. if then ͗ͣͧͨ Ɣ log ͢ ͪ. ͘ Ƙ ͩ. ͘ ƍ ͫ0,1 9. DECREASE -KEY ( ) ͂, ͪ, ͩ. ͘ ƍ ͫ0,1 10. Total cost ( worst-case ) ͪ. ͘ ← ͩ. ͘ ƍ ͫ0,1 ∴ Ο Ɣ ͡ ƍ ͢ log ͢ Dijkstra’s SSSP Algorithm with a Min-Heap ( SSSP: Single-Source Shortest Paths ) Input: Weighted graph with vertex set and edge set , a weight function , and ́a source Ɣ ͐, ̿ vertex . ͐ ̿ Output: For all ͫ , is set to theͧ ∈ shortest ́ ͐ distance from to . ͪ ∈ ́ ͐ ͪ. ͘ ͧ ͪ Dijkstra-SSSP ( ) Let and ́ Ɣ ͐, ̿ , ͫ, ͧ 1. for each do Total͢ cost Ɣ ́ ͐ ͡ Ɣ ́ ̿ 2. ͪ ∈ ́ ͐ ͪ. ͘ ← ∞ 3. ͧ. ͘ ← 0 { empty min-heap } ͂ ← & 4. for each do INSERT ( ) ƙ ͢ ͗ͣͧͨ ). -/ ƍ ͗ͣͧͨ3/-/ͯ$) ͪ ∈ ́ ͐ ͂, ͪ 5. while do - . ͯ 4 ͂ ƕ ∅ ƍ ͡ ͗ͣͧͨ 6. EXTRACT -MIN ( ) Observation: 7. forͩ ←each ͂ do Obtaining a worst-case bound for a ͪ ∈ ̻͘͞ ͩ 8. if then sequence of INSERTS , EXTRACT -MINS ͪ. ͘ Ƙ ͩ. ͘ ƍ ͫ0,1 9. DECREASE -KEY ( ) ͂, ͪ, ͩ. ͘ ƍ ͫ0,1 and DECREASE͢ -KEYS is ͢enough. 10. ͪ. ͘ ← ͩ. ͘ ƍ ͫ0,1 Amortized͡ bound per operation is ∴sufficient. Dijkstra’s SSSP Algorithm with a Min-Heap ( SSSP: Single-Source Shortest Paths ) Input: Weighted graph with vertex set and edge set , a weight function , and ́a source Ɣ ͐, ̿ vertex . ͐ ̿ Output: For all ͫ , is set to theͧ ∈ shortest ́ ͐ distance from to . ͪ ∈ ́ ͐ ͪ. ͘ ͧ ͪ Dijkstra-SSSP ( ) Let and ́ Ɣ ͐, ̿ , ͫ, ͧ 1. for each do Total͢ cost Ɣ ́ ͐ ͡ Ɣ ́ ̿ 2. ͪ ∈ ́ ͐ ͪ. ͘ ← ∞ 3. ͧ. ͘ ← 0 { empty min-heap } ͂ ← & 4. for each do INSERT ( ) ƙ ͢ ͗ͣͧͨ ). -/ ƍ ͗ͣͧͨ3/-/ͯ$) ͪ ∈ ́ ͐ ͂, ͪ 5. while do - . ͯ 4 ͂ ƕ ∅ ƍ ͡ ͗ͣͧͨ 6. EXTRACT -MIN ( ) Observation: 7. forͩ ←each ͂ do For ͪ ∈ ̻͘͞ ͩ 8. if then the best possible ). -/ bound 3/-/ͯ$)is Θ . ͪ. ͘ Ƙ ͩ. ͘ ƍ ͫ0,1 ͢ ͗ͣͧͨ ƍ ͗ͣͧͨ 9. DECREASE -KEY ( ) ͂, ͪ, ͩ. ͘ ƍ ͫ0,1 ( else violates sorting lower bound͢ log ) ͢ 10. 0,1 ͪ. ͘ ← ͩ. ͘ ƍ ͫ Perhaps can be improved͡ to͗ͣͧ ͨ - . .ͯ 4 o ͡ log ͢ Fibonacci Heaps from Binomial Heaps A Fibonacci heap can be viewed as an extension of Binomial heaps which supports DECREASE -KEY and DELETE operations efficiently. But the trees in a Fibonacci heap are no longer binomial trees as we will be cutting subtrees out of them. However, all operations ( except DECREASE -KEY and DELETE ) are still performed in the same way as in binomial heaps. The rank of a tree is still defined as the number of children of the root, and we still link two trees if they have the same rank. Implementing DECREASE -KEY ʚ ¤, Î, Á ʛ DECREASE -KEY ( ): One possible approach is to cut out the subtree rooted¤, at Î, Áfrom , reduce the value of to , and insert that subtree into the rootͬ list of͂ . ͬ ͟ ͂ Problem: If we cut out a lot of subtrees from a tree its size will no longer be exponential in its rank. Since our analysis of EXTRACT -MIN in binomial heaps was highly dependent on this exponential relationship, that analysis will no longer hold. Solution: Limit #cuts among the children of any node to 2. We will show that the size of each tree will still remain exponential in its rank. When a 2nd child is cut from a node , we also cut from its parent leading to a possible sequence of cutsͬ moving up toͬwards the root. Analysis of Fibonacci Heap Operations Recurrence for Fibonacci numbers : 0 ͚͝ ͢ Ɣ 0, ͚) Ɣ ʰ 1 ͚͝ ͢ Ɣ 1, ͚)ͯͥ ƍ ͚)ͯͦ ͙͙ͣͨͦͫͧ͜͝. We showed in a pervious lecture: , ͥ ) ) ͚) Ɣ ͩ & Ǝ&Ȩ where and are the roots . ͥͮ ͩ ͥͮ ͩ ͦ &Ɣ ͦ &Ȩ Ɣ ͦ ͮ Ǝ ͮ Ǝ 1 Ɣ 0 Analysis of Fibonacci Heap Operations Lemma 1: For all integers , .

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    26 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us