Binomial heaps, Fibonacci heaps, and applications

Slides:



Advertisements
Similar presentations
Fibonacci Heaps Especially desirable when the number of calls to Extract-Min & Delete is small (note that all other operations run in O(1) This arises.
Advertisements

Priority Queues  MakeQueuecreate new empty queue  Insert(Q,k,p)insert key k with priority p  Delete(Q,k)delete key k (given a pointer)  DeleteMin(Q)delete.
Advanced Data structure
Rank-Pairing Heaps Robert Tarjan, Princeton University & HP Labs Joint work with Bernhard Haeupler and Siddhartha Sen, ESA
1 Pertemuan 20 Binomial Heap Matakuliah: T0026/Struktur Data Tahun: 2005 Versi: 1/1.
1 Minimize average access time Items have weights: Item i has weight w i Let W =  w i be the total weight of the items Want the search to heavy items.
Dijkstra/Prim 1 make-heap |V| insert |V| delete-min |E| decrease-key Priority Queues make-heap Operation insert find-min delete-min union decrease-key.
Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.
Fibonacci Heaps. Single Source All Destinations Shortest Paths
Binomial Heaps Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University.
Princeton University COS 423 Theory of Algorithms Spring 2002 Kevin Wayne Fibonacci Heaps These lecture slides are adapted from CLRS, Chapter 20.
Fundamental Structures of Computer Science March 02, 2006 Ananda Guna Binomial Heaps.
1 Binomial heaps, Fibonacci heaps, and applications.
Binomial heaps, Fibonacci heaps, and applications
Data Structures Week 8 Further Data Structures The story so far  Saw some fundamental operations as well as advanced operations on arrays, stacks, and.
Lecture X Fibonacci Heaps
1 Trees 4: AVL Trees Section 4.4. Motivation When building a binary search tree, what type of trees would we like? Example: 3, 5, 8, 20, 18, 13, 22 2.
Chapter 19: Fibonacci Heap Many of the slides are from Prof. Leong Hon Wai’s resources at National University of Singapore.
1 Biased 2-b trees (Bent, Sleator, Tarjan 1980). 2 Goal Keep sorted lists subject to the following operations: find(x,L) insert(x,L) delete(x,L) catenate(L1,L2)
1 Binomial Tree Binomial tree. n Recursive definition: B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4.
Four different data structures, each one best in a different setting. Simple Heap Balanced Heap Fibonacci Heap Incremental Heap Our results.
Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another.
1 Fat heaps (K & Tarjan 96). 2 Goal Want to achieve the performance of Fibonnaci heaps but on the worst case. Why ? Theoretical curiosity and some applications.
CMSC 341 Binomial Queues and Fibonacci Heaps. Basic Heap Operations OpBinary Heap Leftist Heap Binomial Queue Fibonacci Heap insertO(lgN) deleteMinO(lgN)
Fibonacci Heaps. Analysis FibonacciAnalysis.ppt Video  iew/cop5536sahni
1 Fibonacci heaps: idea List of multiway trees which are all heap-ordered. Definition: A tree is called heap-ordered if the key of each node is greater.
Fibonacci Heap Fibonacci heapshave better asymptotic time bounds than binary heaps for the INSERT, UNION, and DECREASE-KEY operations, and they.
Heaps and Heap Sort. Sorting III / Slide 2 Background: Complete Binary Trees * A complete binary tree is the tree n Where a node can have 0 (for the leaves)
Fibonacci Heaps. Fibonacci Binary insert O(1) O(log(n)) find O(1) N/A union O(1) N/A minimum O(1) O(1) decrease key O(1) O(log(n)) delete O(log(n) O(log(n))
CSE332: Data Abstractions Lecture 7: AVL Trees
Analysis of Algorithms
Data Structures Binomial Heaps Fibonacci Heaps Haim Kaplan & Uri Zwick
Lecture 15 AVL Trees Slides modified from © 2010 Goodrich, Tamassia & by Prof. Naveen Garg’s Lectures.
Binomial heaps, Fibonacci heaps, and applications
Chapter 11: Multiway Search Trees
Priority Queues © 2010 Goodrich, Tamassia Priority Queues 1
Binomial Heaps On the surface it looks like Binomial Heaps are great if you have no remove mins. But, in this case you need only keep track of the current.
Heaps Binomial Heaps Lazy Binomial Heaps 1.
Binomial heaps, Fibonacci heaps, and applications
Heaps © 2010 Goodrich, Tamassia Heaps Heaps
Heap Sort Example Qamar Abbas.
Insert in amortized cost O(1), Merge in O(lgn) DeleteMax in O(lgn)
Binomial Heaps Chapter 19.
Binomial Tree Adapted from: Kevin Wayne Bk-1 B0 Bk
Priority Queues MakeQueue create new empty queue
Fibonacci Heaps Remove arbitrary is useful in (for example) correspondence structures and may also be used to do an increase key in a min structure (remove.
Data Structures Lecture 4 AVL and WAVL Trees Haim Kaplan and Uri Zwick
Pairing Heaps Actual Complexity.
A simpler implementation and analysis of Chazelle’s
Lecture 29 Heaps Chapter 12 of textbook Concept of heaps Binary heaps
© 2013 Goodrich, Tamassia, Goldwasser
Binomial Heap.
Fibonacci Heap.
ערמות בינומיות ופיבונצ'י
CS 583 Analysis of Algorithms
Fundamental Structures of Computer Science
§3 Worst-Case vs. Amortized
Strict Fibonacci Heaps
CS 583 Analysis of Algorithms
Fibonacci Heaps Remove arbitrary is useful in (for example) correspondence structures.
21장. Fibonacci Heaps 숭실대학교 인공지능 연구실 석사 2학기 김완섭.
Binary and Binomial Heaps
Binomial heaps, Fibonacci heaps, and applications
Fibonacci Heaps.
Binomial heaps, Fibonacci heaps, and applications
Priority Queues Supports the following operations. Insert element x.
B-Trees.
Pairing Heaps Actual Complexity
A Heap Is Efficiently Represented As An Array
CS210- Lecture 13 June 28, 2005 Agenda Heaps Complete Binary Tree
Presentation transcript:

Binomial heaps, Fibonacci heaps, and applications

Binomial trees B0 B1 Bi B(i-1) B(i-1)

Binomial trees Bi . . . . . . B0 B(i-1) B(i-2) B1

Properties of binomial trees 1) | Bk | = 2k 2) degree(root(Bk)) = k 3) depth(Bk) = k ==> The degree and depth of a binomial tree with at most n nodes is at most log(n). Define the rank of Bk to be k

Binomial heaps (def) A collection of binomial trees at most one of every rank. Items at the nodes, heap ordered. 5 6 1 8 2 9 10 Possible rep: Doubly link roots and children of every node. Parent pointers needed for delete.

Binomial heaps (operations) Operations are defined via a basic operation, called linking, of binomial trees: Produce a Bk from two Bk-1, keep heap order. 1 6 4 11 6 9 5 10 2 9 5 8 5 10

Binomial heaps (ops cont.) Basic operation is meld(h1,h2): Like addition of binary numbers. B5 B4 B2 B1 h1: B4 B3 B1 B0 + h2: B4 B3 B0 B5 B4 B2

Binomial heaps (ops cont.) Findmin(h): obvious Insert(x,h) : meld a new heap with a single B0 containing x, with h deletemin(h) : Chop off the minimal root. Meld the subtrees with h. Update minimum pointer if needed. delete(x,h) : Bubble up and continue like delete-min decrease-key(x,h,) : Bubble up, update min ptr if needed All operations take O(log n) time on the worst case, except find-min(h) that takes O(1) time.

Binomial heaps - amortized ana.  (collection of heaps) = #(trees) Amortized cost of insert O(1) Amortized cost of other operations still O(log n)

Binomial heaps + lazy meld Allow more than one tree of each rank. Meld (h1,h2) : Concatenate the lists of binomial trees. Update the minimum pointer to be the smaller of the minimums O(1) worst case and amortized.

Binomial heaps + lazy meld As long as we do not do a delete-min our heaps are just doubly linked lists: 9 11 4 6 9 5 Delete-min : Chop off the minimum root, add its children to the list of trees. Successive linking: Traverse the forest keep linking trees of the same rank, maintain a pointer to the minimum root.

Binomial heaps + lazy meld Possible implementation of delete-min is using an array indexed by rank to keep at most one binomial tree of each rank that we already traversed. Once we encounter a second tree of some rank we link them and keep linking until we do not have two trees of the same rank. We record the resulting tree in the array Amortized(delete-min) = = (#links + max-rank) - #links = O(log(n))

Fibonacci heaps (Fredman & Tarjan 84) Want to do decrease-key(x,h,) faster than delete+insert. Ideally in O(1) time. Why ?

Suggested implementation for decrease-key(x,h,): If x with its new key is smaller than its parent, cut the subtree rooted at x and add it to the forest. Update the minimum pointer if necessary.

5 6 2 3 8 9 10 5 6 2 1 8 9 10

Decrease-key (cont.) Does it work ? Obs1: Trees need not be binomial trees any more.. Do we need the trees to be binomial ? Where have we used it ? In the analysis of delete-min we used the fact that at most log(n) new trees are added to the forest. This was obvious since trees were binomial and contained at most n nodes.

Decrease-key (cont.) 5 6 2 3 9 Such trees are now legitimate. So our analysis breaks down.

Fibonacci heaps (cont.) We shall allow non-binomial trees, but will keep the degrees logarithmic in the number of nodes. Rank of a tree = degree of the root. Delete-min: do successive linking of trees of the same rank and update the minimum pointer as before. Insert and meld also work as before.

Fibonacci heaps (cont.) Decrease-key (x,h,): indeed cuts the subtree rooted by x if necessary as we showed. in addition we maintain a mark bit for every node. When we cut the subtree rooted by x we check the mark bit of p(x). If it is set then we cut p(x) too. We continue this way until either we reach an unmarked node in which case we mark it, or we reach the root. This mechanism is called cascading cuts.

2 4 20 5 8 11 9 6 14 10 16 12 15 9 16 5 6 14 7 12 15 4 8 11 2 20

Fibonacci heaps (delete) Delete(x,h) : Cut the subtree rooted at x and then proceed with cascading cuts as for decrease key. Chop off x from being the root of its subtree and add the subtrees rooted by its children to the forest If x is the minimum node do successive linking

Fibonacci heaps (analysis) Want everything to be O(1) time except for delete and delete-min. ==> cascading cuts should pay for themselves  (collection of heaps) = #(trees) + 2#(marked nodes) Actual(decrease-key) = O(1) + #(cascading cuts) (decrease-key) = O(1) - #(cascading cuts) ==> amortized(decrease-key) = O(1) !

Fibonacci heaps (analysis) What about delete and delete-min ? Cascading cuts and successive linking will pay for themselves. The only question is what is the maximum degree of a node ? How many trees are being added into the forest when we chop off a root ?

Fibonacci heaps (analysis) Lemma 1 : Let x be any node in an F-heap. Arrange the children of x in the order they were linked to x, from earliest to latest. Then the i-th child of x has rank at least i-2. x 2 1 Proof: When the i-th node was linked it must have had at least i-1 children. Since then it could have lost at most one.

Fibonacci heaps (analysis) Corollary1 : A node x of rank k in a F-heap has at least k descendants, where  = (1 + 5)/2 is the golden ratio. Proof: Let sk be the minimum number of descendants of a node of rank k in a F-heap. By Lemma 1 sk  i=0si + 2 k-2 x s0=1, s1= 2

Fibonacci heaps (analysis) Proof (cont): Fibonnaci numbers satisfy Fk+2 = i=2Fi + 2, for k  2, and F2=1 so by induction sk  Fk+2 It is well known that Fk+2  k k It follows that the maximum degree k in a F-heap with n nodes is such that k  n so k  log(n) / log() = 1.4404 log(n)