CSE 548: Analysis of Algorithms. Lectures 14 & 15 ( Dijkstra s SSSP & Fibonacci Heaps )

Similar documents
Fibonacci Heaps. Structure. Implementation. Implementation. Delete Min. Delete Min. Set of min-heap ordered trees min

W4231: Analysis of Algorithms

Priority Queues. Meld(Q 1,Q 2 ) merge two sets

Chapter 5 Data Structures Algorithm Theory WS 2016/17 Fabian Kuhn

Analysis of Algorithms

Algorithm Theory, Winter Term 2015/16 Problem Set 5 - Sample Solution

CS711008Z Algorithm Design and Analysis

CS711008Z Algorithm Design and Analysis

Hollow Heaps. Aarhus University, Denmark. Tel Aviv University, Israel. Princeton University, USA. July 7, 2015

Sorting and Searching

Binary Heaps in Dynamic Arrays

18.3 Deleting a key from a B-tree

Sorting and Searching

CSE 613: Parallel Programming. Lecture 11 ( Graph Algorithms: Connected Components )

CLRS 19 Fibonacci Heaps

Rank-Pairing Heaps. Bernard Haeupler Siddhartha Sen Robert E. Tarjan. SIAM JOURNAL ON COMPUTING Vol. 40, No. 6 (2011), pp.

Algorithms and Theory of Computation. Lecture 7: Priority Queue

Chapter 6 Heapsort 1

CSE 638: Advanced Algorithms. Lectures 10 & 11 ( Parallel Connected Components )

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/27/17

Priority queue. Advanced Algorithmics (6EAP) MTAT Heaps. Binary heap. Heap/Priority queue. Binomial heaps:

V Advanced Data Structures

CSE548, AMS542: Analysis of Algorithms, Fall 2012 Date: October 16. In-Class Midterm. ( 11:35 AM 12:50 PM : 75 Minutes )

CSE 613: Parallel Programming. Lecture 6 ( Basic Parallel Algorithmic Techniques )

RANK-PAIRING HEAPS BERNHARD HAEUPLER 1, SIDDHARTHA SEN 2,4, AND ROBERT E. TARJAN 3,4

Are Fibonacci Heaps Optimal? Diab Abuaiadh and Jeffrey H. Kingston ABSTRACT

Let the dynamic table support the operations TABLE-INSERT and TABLE-DELETE It is convenient to use the load factor ( )

CSCE750 Analysis of Algorithms Fall 2018 Fibonacci Heaps

V Advanced Data Structures

A Comparison of Data Structures for Dijkstra's Single Source Shortest Path Algorithm. Shane Saunders

FIBONACCI HEAPS. preliminaries insert extract the minimum decrease key bounding the rank meld and delete. Lecture slides by Kevin Wayne

Decreasing a key FIB-HEAP-DECREASE-KEY(,, ) 3.. NIL. 2. error new key is greater than current key 6. CASCADING-CUT(, )

On the power of structural violations in priority queues

l Heaps very popular abstract data structure, where each object has a key value (the priority), and the operations are:

CSE 5311 Notes 4a: Priority Queues

Test 1 - Closed Book Last 4 Digits of Student ID # Multiple Choice. Write your answer to the LEFT of each problem. 3 points each

Advanced algorithms. binary heap, d-ary heap, binomial heap, amortized analysis, Fibonacci heap. Jiří Vyskočil, Radek Mařík 2013

Midterm solutions. n f 3 (n) = 3

Quake Heaps: A Simple Alternative to Fibonacci Heaps

Priority Queues and Binary Heaps

These are not polished as solutions, but ought to give a correct idea of solutions that work. Note that most problems have multiple good solutions.

EECS 477: Introduction to algorithms. Lecture 10

9. Which situation is true regarding a cascading cut that produces c trees for a Fibonacci heap?

arxiv: v2 [cs.ds] 9 Apr 2009

l So unlike the search trees, there are neither arbitrary find operations nor arbitrary delete operations possible.

Hollow Heaps. Thomas Dueholm Hansen Haim Kaplan Robert E. Tarjan Uri Zwick

CSci 231 Final Review

Breadth-First Search, 1. Slides for CIS 675 DPV Chapter 4. Breadth-First Search, 3. Breadth-First Search, 2

CSE 638: Advanced Algorithms. Lectures 18 & 19 ( Cache-efficient Searching and Sorting )

CS 6783 (Applied Algorithms) Lecture 5

Dictionaries. Priority Queues

Algorithms for Minimum Spanning Trees

Review of 4 comparison-based priority queues: Binary, Binomial, Fibonacci and Weak heap : Technical report LUSY-2012/01

Priority Queue: Heap Structures

D. Θ nlogn ( ) D. Ο. ). Which of the following is not necessarily true? . Which of the following cannot be shown as an improvement? D.

How many leaves on the decision tree? There are n! leaves, because every permutation appears at least once.

Self-Adjusting Heaps

Rank-Pairing Heaps. Some applications of heaps need either or both of the following additional operations.

Lecture 4: Advanced Data Structures

Lecture 6: Analysis of Algorithms (CS )

Course Review for Finals. Cpt S 223 Fall 2008

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

Representations of Weighted Graphs (as Matrices) Algorithms and Data Structures: Minimum Spanning Trees. Weighted Graphs

Lecture Notes for Advanced Algorithms

Lecture 5 Using Data Structures to Improve Dijkstra s Algorithm. (AM&O Sections and Appendix A)

Multi-Way Search Trees

( ) n 3. n 2 ( ) D. Ο

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

CSC 505, Fall 2000: Week 7. In which our discussion of Minimum Spanning Tree Algorithms and their data Structures is brought to a happy Conclusion.

logn D. Θ C. Θ n 2 ( ) ( ) f n B. nlogn Ο n2 n 2 D. Ο & % ( C. Θ # ( D. Θ n ( ) Ω f ( n)

( ) D. Θ ( ) ( ) Ο f ( n) ( ) Ω. C. T n C. Θ. B. n logn Ο

16 Greedy Algorithms

CS 380 ALGORITHM DESIGN AND ANALYSIS

) $ f ( n) " %( g( n)

Fundamental Algorithms

Minimum Spanning Trees

Properties of red-black trees

Lecture Summary CSC 263H. August 5, 2016

22 Elementary Graph Algorithms. There are two standard ways to represent a

n 2 C. Θ n ( ) Ο f ( n) B. n 2 Ω( n logn)

CSE 214 Computer Science II Heaps and Priority Queues

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi

COL351: Analysis and Design of Algorithms (CSE, IITD, Semester-I ) Name: Entry number:

How much space does this routine use in the worst case for a given n? public static void use_space(int n) { int b; int [] A;

2.1 Greedy Algorithms. 2.2 Minimum Spanning Trees. CS125 Lecture 2 Fall 2016

COP 4531 Complexity & Analysis of Data Structures & Algorithms

CSE 502 Class 16. Jeremy Buhler Steve Cole. March A while back, we introduced the idea of collections to put hash tables in context.

CSE 5311 Notes 10: Medians/Selection

Greedy Algorithms CSE 6331

Dijkstra s Single Source Shortest Path Algorithm. Andreas Klappenecker

CSCI2100B Data Structures Heaps

Outline. Computer Science 331. Heap Shape. Binary Heaps. Heap Sort. Insertion Deletion. Mike Jacobson. HeapSort Priority Queues.

22 Elementary Graph Algorithms. There are two standard ways to represent a

Outline. Definition. 2 Height-Balance. 3 Searches. 4 Rotations. 5 Insertion. 6 Deletions. 7 Reference. 1 Every node is either red or black.

CSE 100: GRAPH ALGORITHMS

SFU CMPT Lecture: Week 9

Priority Queues. T. M. Murali. January 29, 2009

CSE 431/531: Analysis of Algorithms. Greedy Algorithms. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo

LECTURE 18 AVL TREES

SKEW HEAPS: Self-Adjusting Heaps

Transcription:

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 heapcan be viewed as an extension of Binomial heaps which supports DECREASE-KEY and DELETE operations efficiently. Heap Operation Binary Heap ( worst-case ) Binomial Heap ( 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 heapcan be viewed as an extension of Binomial heaps which supports DECREASE-KEY and DELETE operations efficiently. Heap Operation Binary Heap ( worst-case ) Binomial Heap ( amortized) MAKE-HEAP Θ 1 Θ 1 INSERT Ο log Θ 1 MINIMUM Θ 1 Θ 1 EXTRACT-MIN Ο log Ο log UNION Θ Θ 1 DECREASE-KEY DELETE Ο log Ο log Ο log ( worst case ) Ο log ( worst case )

Fibonacci Heaps ( Fredman & Tarjan, 1984 ) A Fibonacci heapcan be viewed as an extension of Binomial heaps which supports DECREASE-KEY and DELETE operations efficiently. Heap Operation Binary Heap ( worst-case ) Binomial Heap ( amortized) Fibonacci Heap ( amortized ) MAKE-HEAP Θ 1 Θ 1 Θ 1 INSERT Ο log Θ 1 Θ 1 MINIMUM Θ 1 Θ 1 Θ 1 EXTRACT-MIN Ο log Ο log Ο log UNION Θ Θ 1 Θ 1 DECREASE-KEY Ο log Ο log ( worst case ) Θ 1 DELETE Ο log Ο log ( worst case ) Ο 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.. 0 3. { empty min-heap } 4. for each do INSERT(, ) 5. while do 6. EXTRACT-MIN( ) 7. for each do 8. if.., then 9. DECREASE-KEY(,,., ) 10...,

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.. 0 3. { empty min-heap } 4. for each do INSERT(, ) 5. while do 6. EXTRACT-MIN( ) 7. for each do 8. if.., then 9. DECREASE-KEY(,,., ) 10..., Let and # INSERTS # EXTRACT-MINS # DECREASE-KEYS Total cost

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.. 0 3. { empty min-heap } 4. for each do INSERT(, ) 5. while do 6. EXTRACT-MIN( ) 7. for each do 8. if.., then 9. DECREASE-KEY(,,., ) 10..., Let and For Binary Heap ( worst-case costs ): Ο log Ο log Ο log Total cost ( worst-case ) Ο 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.. 0 3. { empty min-heap } 4. for each do INSERT(, ) 5. while do 6. EXTRACT-MIN( ) 7. for each do 8. if.., then 9. DECREASE-KEY(,,., ) 10..., Let and For Binomial Heap ( amortized costs ): Ο 1 Ο log Ο log ( worst-case ) Total cost ( worst-case ) Ο 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.. 0 3. { empty min-heap } 4. for each do INSERT(, ) 5. while do 6. EXTRACT-MIN( ) 7. for each do 8. if.., then 9. DECREASE-KEY(,,., ) 10..., Let and Total cost Observation: Obtaining a worst-case bound for a sequence of INSERTS, EXTRACT-MINS and DECREASE-KEYSis enough. 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 (,,, ) 1. for each do. 2.. 0 3. { empty min-heap } 4. for each do INSERT(, ) 5. while do 6. EXTRACT-MIN( ) 7. for each do 8. if.., then 9. DECREASE-KEY(,,., ) 10..., Let and Total cost Observation: For the best possible bound is Θ log. ( else violates sorting lower bound ) Perhaps can be improved to o log.

Fibonacci Heaps from Binomial Heaps A Fibonacci heapcan 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-KEYand DELETE) are still performed in the same way as in binomial heaps. The rankof 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 subtreerooted at from, reduce the value of to, and insert that subtreeinto the root list of. Problem: If we cut out a lot of subtreesfrom a tree its size will no longer be exponential in its rank. Since our analysis of EXTRACT-MINin 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 towards 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 0, 1. Proof:By induction on. Base case: 1 1 0 1 1. Inductive hypothesis: 1 for 0 1. Then 1 1.

Analysis of Fibonacci Heap Operations Lemma 2:For all integers 0,. Proof:By induction on. Base case: 1 and 2. Inductive hypothesis: for 0 1. Then 1

Analysis of Fibonacci Heap Operations Lemma 3:Let be any node in a Fibonacci heap, and suppose that. Let,,, be the children of in the order in which they were linked to, from the earliest to the latest. Then max 0, 2 for 1. Proof:Obviously, 0. For 1, when was linked to, all of,,, were children of. So, 1. Because is linked to only if, we must have had 1at that time. Since then, has lost at most one child, and hence 2.

Analysis of Fibonacci Heap Operations Lemma 4:Let be any node in a Fibonacci heap with and. Then log. Proof:Let be the minimum possible size of any node of rank in any Fibonacci heap. Trivially, 1and 2. Since adding children to a node cannot decrease its size, increases monotonically with. Let be a node in any Fibonacci heap with and.

Analysis of Fibonacci Heap Operations Lemma 4:Let be any node in a Fibonacci heap with and. Then log. Proof ( continued ):Let,,, be the children of in the order in which they were linked to, from the earliest to the latest. Then 1 1, 2 We now show by induction on that for all integer 0. Base case: 1 and 2. Inductive hypothesis: for 0 1. Then 2 Hence log. 2 1.

Analysis of Fibonacci Heap Operations Corollary:The maximum degree of any node in an node Fibonacci heap is Ο log. Proof:Let be any node in the heap. Then from Lemma 4, log log Ο log.

Analysis of Fibonacci Heap Operations All nodes are initially unmarked. We mark a node when it loses its first child We unmark a node when it loses its second child, or becomes the child of another node ( e.g., LINKed ) We extend the potential function used for binomial heaps: Φ 2 3, where is the state of the data structure after the operation, is the number of trees in the root list, and is the number of marked nodes.

Analysis of Fibonacci Heap Operations We extend the potential function used for binomial heaps: Φ 2 3, where is the state of the data structure after the operation, is the number of trees in the root list, and is the number of marked nodes. DECREASE-KEY(,, ):Let #cascading cuts performed. Then the actual cost of cutting the tree rooted at is 1, and the actual cost of each of the cascading cuts is also 1. overall actual cost, 1

Fibonacci Heaps from Binomial Heaps Potential function: Φ 2 3 DECREASE-KEY(,, ): New trees: 1 tree rooted at, and 1 tree produced by each of the cascading cuts. 1 Marked nodes: 1 node unmarked by each cascading cut, and at most 1 node marked by the last cut/cascading cut. 1 Potential drop, Δ Φ Φ 2 3 2 1 3 1 5

Fibonacci Heaps from Binomial Heaps Potential function: Φ 2 3 DECREASE-KEY(,, ): Amortized cost, Δ 1 5 6 Ο 1

Fibonacci Heaps from Binomial Heaps Potential function: Φ 2 3 EXTRACT-MIN( ): Let be the max degree of any node in an -node Fibonacci heap. Cost of creating the array of pointers is 1. Suppose we start with trees in the doubly linked list, and perform link operations during the conversion from linked list to array version. So we perform work, and end up with trees. Cost of converting to the linked list version is. actual cost, 1 2 1 Since no node is marked, and each link reduces the #trees by 1, potential change, Δ Φ Φ 2

Fibonacci Heaps from Binomial Heaps Potential function: Φ 2 3 EXTRACT-MIN( ): actual cost, 1 2 1 potential change, Δ Φ Φ 2 amortized cost, Δ 2 1 But 1 ( as we have at most one tree of each rank ) So, 3 3 Ο log.

Fibonacci Heaps from Binomial Heaps Potential function: Φ 2 3 DELETE(, ): STEP1:DECREASE-KEY(,, ) STEP2:EXTRACT-MIN( ) amortized cost, amortized cost of DECREASE-KEY amortized cost of EXTRACT-MIN Ο 1 Ο log Ο log