

















































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
fibonacci heap easy explanation
Typology: Essays (university)
1 / 89
This page cannot be seen from the preview
Don't miss anything!


















































































Copyright © 2013 Kevin Wayne
Ahead. O (1) INSERT and DECREASE-KEY, O (log n ) EXTRACT-MIN. Priority queues performance cost summary operation linked list binary heap binomial heap Fibonacci heap † MAKE-HEAP (^) O (1) O (1) O (1) O (1) IS-EMPTY O (1) O (1) O (1) O (1) INSERT (^) O (1) O (log n ) O (log n ) O (1) EXTRACT-MIN (^) O ( n ) O (log n ) O (log n ) O (log n ) DECREASE-KEY (^) O (1) O (log n ) O (log n ) O (1) DELETE (^) O (1) O (log n ) O (log n ) O (log n ) MELD (^) O (1) O ( n ) O (log n ) O (1) FIND-MIN (^) O ( n ) O (1) O (log n ) O (1) † amortized
Fibonacci heaps Theorem. [Fredman-Tarjan 1986] Starting from an empty Fibonacci heap, any sequence of m INSERT, EXTRACT-MIN, and DECREASE-KEY operations involving n INSERT operations takes O ( m + n log n ) time. History. Ingenious data structure and application of amortized analysis. Original motivation: improve Dijkstra's shortest path algorithm from O ( m log n ) to O ( m + n log n ). Also improved best-known bounds for all-pairs shortest paths, assignment problem, minimum spanning trees.
Set of heap-ordered trees. 23 7 30 17 35 26 46 24 39 18 52 41 3 44 Fibonacci heap: structure heap-ordered tree each child no smaller than its parent root heap H
Set of heap-ordered trees. Set of marked nodes. 23 7 30 17 35 26 46 24 39 18 52 41 3 44 Fibonacci heap: structure min used to keep trees bushy (stay tuned) 39 18 heap H^ marked 26
Node representation. Each node stores: A pointer to its parent. A pointer to any of its children. A pointer to its left and right siblings. Its rank = number of children. Whether it is marked. 23 7 30 17 35 26 46 24 39 18 52 41 3 44 Fibonacci heap: representation min 39 18 heap H children are in a circular doubly-linked list 26 rank = 3
Operations we can do in constant time: Determine rank of a node. Find the minimum element. Merge two root lists together. Add or remove a node from the root list. Remove a subtree and merge into root list. Link the root of a one tree to root of another tree. 23 7 30 17 35 26 46 24 39 18 52 41 3 44 Fibonacci heap: representation min 39 18 heap H 26 rank = 3
Potential function. 23 7 30 17 35 26 46 24 39 18 52 41 3 44 Fibonacci heap: potential function min 39 18 Φ(H) = 5 + 2 ⋅ 3 = 11 trees(H) = 5 marks(H) = 3 heap H Φ( H ) = trees( H ) + 2 ⋅ marks( H ) 26
Create a new singleton tree. Add to root list; update min pointer (if necessary). 23 7 30 17 35 26 46 24 39 18 52 41 3 44 Fibonacci heap: insert 21 insert 21 min heap H 39 18 26
Actual cost. ci = O (1). Change in potential. ∆Φ = Φ( Hi ) – Φ( Hi– 1 ) = +1. Amortized cost. ĉi = ci + ∆Φ = O (1). 23 7 30 17 35 26 46 24 39 18 52 41 3 44 Fibonacci heap: insert analysis min heap H 21 39 18 Φ( H ) = trees( H ) + 2 ⋅ marks( H ) 26 one more tree; no change in marks
Linking operation Useful primitive. Combine two trees T 1 and T 2 of rank k. Make larger root be a child of smaller root. Resulting tree T ' has rank k + 1. 39 18 52 41 3 77 44 56 24 15 tree T 1 tree T 2 39 18 52 41 3 44 77 56 24 15 tree T' still heap-ordered 33 33
Delete min; meld its children into root list; update min. Consolidate trees so that no two roots have same rank. Fibonacci heap: extract the minimum 39 18 52 41 3 44 23 17 30 7 35 26 46 24 min 2626