Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fibonacci Heaps & Doubled-Ended Heap Structures

Similar presentations


Presentation on theme: "Fibonacci Heaps & Doubled-Ended Heap Structures"— Presentation transcript:

1 Fibonacci Heaps & Doubled-Ended Heap Structures
James Rhodes

2 Introduction After search trees, heaps are the second most studied type of data structure Also, called priority queues, as they keep track of a set of objects using a key value (priority) Supports the following operations: insert (insert an object), find_min (find object with minimum key), and delete_min (delete object with minimum key) Minimum or maximum can be used to create a min_heap or max_heap, respectively A double-ended heap provides both minimum and maximum operations Most important applications are event queues Examples: sweeps in computational geometry, discrete event systems, schedulers, and shortest path

3 Amortized Analysis Cost of operations are amortized
Time to perform a sequence of operations is averaged over all operations Cost of an operation can be small when averaged over a sequence even if single operation is expensive Differs from average-case analysis because probability is not involved Guarantees the average performance of each operation in the worst case

4 Structure Viewed as a binary tree or an array
Each node has a key and an object Parent(i) = Floor(i/2) Left(i) = 2i Right(i) = 2i + 1 Heap Order Property Heap(Parent(i)) <= Heap(i) for min_heap and Heap(Parent(i)) >= Heap(i) for max_heap Half order property no restriction for the left subtree

5 Fibonacci Heap The Fibonacci heap data structure serves a dual purpose
It supports a set of operations that constitutes what is known as a “mergeable heap” Several Fibonacci-heap operations run in constant amortized time, which makes this data structure well suited for applications that invoke these operations frequently The oldest and best known structure that performs the decrease_key operation in constant time Each node n has an integer field n->rank, as well as a state n->state (complete or deficient)

6 Fibonacci Heap Defining properties:
For any node n with n->rank > 1, or n->rank = 1 and n->state = complete, holds n->right = NULL, and If n->state = complete, then on the left path below n->right there are n->rank nodes, which have rank at least n->rank − 1, n->rank − 2, , 0, in some sequence. If n->state = deficient, then on the left path below n->right there are n->rank − 1 nodes, which have rank at least n->rank − 2, n->rank − 3, , 0, in some sequence. For any node n with n->rank = 0, or n->rank = 1 and n->state = deficient, holds n->right = NULL

7 Fibonacci Heap If deficient nodes are not allowed, strictly decreasing rank along the leftmost path is demanded, and the first rule is strengthened to: For any node n of with n->rank > 0, holds n->right = NULL, and on the left path below n->right, there are n->rank nodes, which have rank exactly n->rank − 1, n->rank − 2, , 0, in decreasing sequence. Then that will be a binomial heap structure, thus the Fibonacci heap is a structural relaxation of the binomial heap

8 Fibonacci Heap Fibonacci Heap Structure: The Nodes Are Labeled by Rank and Deficiency Status

9 Fibonacci Heap The minimum number f (k) of nodes in a block of rank k satisfies the recursion f (k) = f (k − 2) + f (k − 3)+· · ·+f (1) + f (0) + 1 Using f (k − 1) = f (k − 3)+· · ·+f (1) + f (0) + 1, the recursion can be rewritten as f (k) = f (k − 1) + f (k − 2) This is the recurrence equation for the Fibonacci sequence which is where the structure gets its name The starting values are f (0) = f (1) = 1

10 If the equation is solved we get
Fibonacci Heap If the equation is solved we get

11 Fibonacci Heap Theorem.
The Fibonacci heap structure supports the operations find_min, insert, merge, delete_min, and decrease key, with find min, insert, and merge in O(1) time, decrease key in amortized O(1) time, and delete_min in amortized O(log n) time.

12 Operations: insert find_min merge delete_min decrease_key
Fibonacci Heap Operations: insert find_min merge delete_min decrease_key

13 Fibonacci Heap n = number of elements in priority queue †amortized
Operation Linked List Binary Heap Binomial Heap Fibonacci Heap † Relaxed Heap make-heap 1 1 1 1 1 is-empty 1 1 1 1 1 insert 1 log n log n 1 1 delete-min n log n log n log n log n decrease-key n log n log n 1 1 delete n log n log n log n log n union 1 n log n 1 1 find-min n 1 log n 1 1 n = number of elements in priority queue †amortized

14 Double-ended Heap A min and max heap combined
Each element is inserted into both heaps Insert requires 2 operations Delete requires a delete_min or delete_max in the corresponding heap and arbitrary delete in the other Theorem. There is a double-ended heap that supports insert , find-min , find-max, merge in O(1) ; and delete-min , delete-max in O(log n) worst-case .

15 References Advanced Data Structures, Peter Brass, Cambridge University Press, 2008 Introduction to Algorithms, Thomas H Cormen, Charles E Leiserson, Ronald L Rivest, Clifford Stein MIT Press, 2001 Wikipedia, Wikimedia Foundation, 2018, accessed 14 Feb 2019.

16 Questions

17 Thank You


Download ppt "Fibonacci Heaps & Doubled-Ended Heap Structures"

Similar presentations


Ads by Google