Advanced Data structure

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

DATA STRUCTURES AND ALGORITHMS Lecture Notes 9 Prepared by İnanç TAHRALI.
COL 106 Shweta Agrawal and Amit Kumar
Heaps1 Part-D2 Heaps Heaps2 Recall Priority Queue ADT (§ 7.1.3) A priority queue stores a collection of entries Each entry is a pair (key, value)
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.
AVL Trees1 Part-F2 AVL Trees v z. AVL Trees2 AVL Tree Definition (§ 9.2) AVL trees are balanced. An AVL Tree is a binary search tree such that.
Rank-Pairing Heaps Robert Tarjan, Princeton University & HP Labs Joint work with Bernhard Haeupler and Siddhartha Sen, ESA
1 Theory I Algorithm Design and Analysis (9 – Priority queues: Fibonacci heaps) T. Lauer.
CS 315 March 24 Goals: Heap (Chapter 6) priority queue definition of a heap Algorithms for Insert DeleteMin percolate-down Build-heap.
Rank-Pairing Heaps Bernhard Haeupler, Siddhartha Sen, and Robert Tarjan, ESA
1 COSC 2P03 Lecture #5 – Trees Part III, Heaps. 2 Today Take up the quiz Assignment Questions Red-Black Trees Binary Heaps Heap sort D-Heaps, Leftist.
Nick Harvey & Kevin Zatloukal
CSE 373 Data Structures Lecture 12
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
Fibonacci Heap.
0 Course Outline n Introduction and Algorithm Analysis (Ch. 2) n Hash Tables: dictionary data structure (Ch. 5) n Heaps: priority queue data structures.
5.9 Heaps of optimal complexity
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.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2001 Lecture 11 Tuesday, 12/4/01 Advanced Data Structures Chapters.
Princeton University COS 423 Theory of Algorithms Spring 2002 Kevin Wayne Binary and Binomial Heaps These lecture slides are adapted from CLRS, Chapters.
Fundamental Structures of Computer Science March 02, 2006 Ananda Guna Binomial Heaps.
1 Binomial heaps, Fibonacci heaps, and applications.
PRIORITY QUEUES (HEAPS). Queues are a standard mechanism for ordering tasks on a first-come, first-served basis However, some tasks may be more important.
1 CS 6234 Advanced Algorithms: Splay Trees, Fibonacci Heaps, Persistent Data Structures.
Strict Fibonacci Heaps Gerth Stølting Brodal Aarhus University George Lagogiannis Robert Endre Tarjan Agricultural University of Athens Princeton University.
Chapter 9 Heap Structures
Binomial heaps, Fibonacci heaps, and applications
The Binary Heap. Binary Heap Looks similar to a binary search tree BUT all the values stored in the subtree rooted at a node are greater than or equal.
Lecture X Fibonacci Heaps
WEEK 3 Leftist Heaps CE222 Dr. Senem Kumova Metin CE222_Dr. Senem Kumova Metin.
1 Heaps (Priority Queues) You are given a set of items A[1..N] We want to find only the smallest or largest (highest priority) item quickly. Examples:
Chapter 2: Basic Data Structures. Spring 2003CS 3152 Basic Data Structures Stacks Queues Vectors, Linked Lists Trees (Including Balanced Trees) Priority.
Chapter 19: Fibonacci Heap Many of the slides are from Prof. Leong Hon Wai’s resources at National University of Singapore.
Change Keys in heaps Fibonacci heap Zhao Xiaobin.
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.
Data StructuresData Structures Priority Queue. Recall Queues FIFO:First-In, First-Out Some contexts where this seems right? Some contexts where some things.
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)
Mergeable Heaps David Kauchak cs302 Spring Admin Homework 7?
Fibonacci Heaps.
Fibonacci Heaps. Analysis FibonacciAnalysis.ppt Video  iew/cop5536sahni
1 Chapter 6 Heapsort. 2 About this lecture Introduce Heap – Shape Property and Heap Property – Heap Operations Heapsort: Use Heap to Sort Fixing heap.
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.
Data structures Binomial Heaps - Binomial Trees B0B0 BkBk B k-1.
Fibonacci Heap. p2. Procedure Binary heap (worst-case) Fibonacci heap (amortized) MAKE-HEAP  (1) INSERT  (lg n)  (1) MINIMUM  (1) EXTRACT-MIN  (lg.
Fibonacci Heap Fibonacci heapshave better asymptotic time bounds than binary heaps for the INSERT, UNION, and DECREASE-KEY operations, and they.
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))
Data Structures Binomial Heaps Fibonacci Heaps Haim Kaplan & Uri Zwick
Binomial heaps, Fibonacci heaps, and applications
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.
Bohyung Han CSE, POSTECH
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.
A simpler implementation and analysis of Chazelle’s
ערמות בינומיות ופיבונצ'י
Fundamental Structures of Computer Science
Strict Fibonacci Heaps
Fibonacci Heaps Remove arbitrary is useful in (for example) correspondence structures.
Binary and Binomial Heaps
Binomial heaps, Fibonacci heaps, and applications
Binomial heaps, Fibonacci heaps, and applications
Fibonacci Heaps.
Binomial heaps, Fibonacci heaps, and applications
Priority Queues Supports the following operations. Insert element x.
Presentation transcript:

Advanced Data structure Fibonacci Heaps Lecturer : Dr Ali Al Najjar 1435-1436 H

Priority Queues Performance Cost Summary Theorem. Starting from empty Fibonacci heap, any sequence of a1 insert, a2 delete-min, and a3 decrease-key operations takes O(a1 + a2 log n + a3) time. 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 main improvement: decrease-key is now O(1) we'll emphasize the first 5 ops n = number of elements in priority queue † amortized

Priority Queues Performance Cost Summary Hopeless challenge. O(1) insert, delete-min and decrease-key. Why? 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 Q. If O(1) insert and delete-min then O(n) sort. can only access the keys through pairwise comparisons n = number of elements in priority queue † amortized

Fibonacci Heaps History. [Fredman and Tarjan, 1986] Ingenious data structure and analysis. Original motivation: improve Dijkstra's shortest path algorithm from O(E log V ) to O(E + V log V ). Basic idea. Similar to binomial heaps, but less rigid structure. Binomial heap: eagerly consolidate trees after each insert. Fibonacci heap: lazily defer consolidation until next delete-min. V insert, V delete-min, E decrease-key also led to faster algorithms for Prim's MST algorithm and weighted bipartite matching (assignment problem) less rigid structure to support more efficient delete-min

Fibonacci Heaps: Structure Set of heap-ordered trees. Maintain pointer to minimum element. Set of marked nodes. each parent larger than its children roots heap-ordered tree set -> unordered 17 24 23 7 3 30 26 46 18 52 41 Heap H 35 39 44

Fibonacci Heaps: Structure Set of heap-ordered trees. Maintain pointer to minimum element. Set of marked nodes. find-min takes O(1) time min set -> unordered 17 24 23 7 3 30 26 46 18 52 41 Heap H 35 39 44

Fibonacci Heaps: Structure Set of heap-ordered trees. Maintain pointer to minimum element. Set of marked nodes. use to keep heaps flat (stay tuned) min set -> unordered 17 24 23 7 3 30 26 46 18 52 41 Heap H 35 marked 39 44

Fibonacci Heaps: Notation n = number of nodes in heap. rank(x) = number of children of node x. rank(H) = max rank of any node in heap H. trees(H) = number of trees in heap H. marks(H) = number of marked nodes in heap H. trees(H) = 5 marks(H) = 3 n = 14 rank = 3 min recall: with binomial heap, at most one tree of rank 0, 1, 2, 3, 4, … nodes only change mark in Decrease-Key Can basically ignore marks until then. marks are used to ensure size of heap is exponential in rank 17 24 23 7 3 30 26 46 18 52 41 Heap H 35 marked 39 44

Fibonacci Heaps: Potential Function (H)  = trees(H) + 2  marks(H) potential of heap H trees(H) = 5 marks(H) = 3 (H) = 5 + 23 = 11 min 17 24 23 7 3 30 26 46 18 52 41 Heap H 35 marked 39 44

Insert

Fibonacci Heaps: Insert Create a new singleton tree. Add to root list; update min pointer (if necessary). insert 21 21 min 17 24 23 7 3 30 26 46 18 52 41 Heap H 35 39 44

Fibonacci Heaps: Insert Create a new singleton tree. Add to root list; update min pointer (if necessary). insert 21 min lazy insert - don't consolidate trees when inserting into Fibonacci heap. If k consecutive inserts, the k 1-node trees are created. 17 24 23 7 21 3 30 26 46 18 52 41 Heap H 35 39 44

Fibonacci Heaps: Insert Analysis Actual cost. O(1) Change in potential. +1 Amortized cost. O(1) (H)  = trees(H) + 2  marks(H) potential of heap H min 17 24 23 7 21 3 30 26 46 18 52 41 Heap H 35 39 44

Delete Min extracting min is where the deferred work of consolidating the roots takes place

Linking Operation Linking operation. Make larger root be a child of smaller root. larger root smaller root still heap-ordered 15 3 3 56 24 18 52 41 15 18 52 41 77 39 44 56 24 39 44 tree T1 tree T2 77 tree T'

Fibonacci Heaps: Delete Min Delete min; meld its children into root list; update min. Consolidate trees so that no two roots have same rank. min 7 24 23 17 3 30 26 46 18 52 41 35 39 44

Fibonacci Heaps: Delete Min Delete min; meld its children into root list; update min. Consolidate trees so that no two roots have same rank. min 7 24 23 17 18 52 41 39 44 30 26 46 35

Fibonacci Heaps: Delete Min Delete min; meld its children into root list; update min. Consolidate trees so that no two roots have same rank. min current 7 24 23 17 18 52 41 39 44 30 26 46 35

Fibonacci Heaps: Delete Min Delete min; meld its children into root list; update min. Consolidate trees so that no two roots have same rank. rank 1 2 3 min current 7 24 23 17 18 52 41 39 44 30 26 46 35

Fibonacci Heaps: Delete Min Delete min; meld its children into root list; update min. Consolidate trees so that no two roots have same rank. rank 1 2 3 min current 7 24 23 17 18 52 41 39 44 30 26 46 35

Fibonacci Heaps: Delete Min Delete min; meld its children into root list; update min. Consolidate trees so that no two roots have same rank. rank 1 2 3 min 7 24 23 17 18 52 41 39 44 30 26 46 current 35

Fibonacci Heaps: Delete Min Delete min; meld its children into root list; update min. Consolidate trees so that no two roots have same rank. rank 1 2 3 min 7 24 23 17 18 52 41 current 39 44 30 26 46 35 link 23 into 17

Fibonacci Heaps: Delete Min Delete min; meld its children into root list; update min. Consolidate trees so that no two roots have same rank. rank 1 2 3 min 7 24 17 18 52 41 current 23 39 44 30 26 46 35 link 17 into 7

Fibonacci Heaps: Delete Min Delete min; meld its children into root list; update min. Consolidate trees so that no two roots have same rank. rank 1 2 3 current min 24 7 18 52 41 17 30 39 44 26 46 35 23 link 24 into 7

Fibonacci Heaps: Delete Min Delete min; meld its children into root list; update min. Consolidate trees so that no two roots have same rank. rank 1 2 3 current min 7 18 52 41 24 17 30 39 44 26 46 23 35

Fibonacci Heaps: Delete Min Delete min; meld its children into root list; update min. Consolidate trees so that no two roots have same rank. rank 1 2 3 current min 7 18 52 41 24 17 30 39 44 26 46 23 35

Fibonacci Heaps: Delete Min Delete min; meld its children into root list; update min. Consolidate trees so that no two roots have same rank. rank 1 2 3 current min 7 18 52 41 24 17 30 39 44 26 46 23 35

Fibonacci Heaps: Delete Min Delete min; meld its children into root list; update min. Consolidate trees so that no two roots have same rank. rank 1 2 3 current min 7 18 52 41 24 17 30 39 44 26 46 23 link 41 into 18 35

Fibonacci Heaps: Delete Min Delete min; meld its children into root list; update min. Consolidate trees so that no two roots have same rank. rank 1 2 3 current min 7 52 18 24 17 30 41 39 26 46 23 44 35

Fibonacci Heaps: Delete Min Delete min; meld its children into root list; update min. Consolidate trees so that no two roots have same rank. rank 1 2 3 current min 7 52 18 24 17 30 41 39 26 46 23 44 35

Fibonacci Heaps: Delete Min Delete min; meld its children into root list; update min. Consolidate trees so that no two roots have same rank. min 7 52 18 24 17 30 41 39 26 46 23 44 stop 35

Fibonacci Heaps: Delete Min Analysis Actual cost. O(rank(H)) + O(trees(H)) O(rank(H)) to meld min's children into root list. O(rank(H)) + O(trees(H)) to update min. O(rank(H)) + O(trees(H)) to consolidate trees. Change in potential. O(rank(H)) - trees(H) trees(H' )  rank(H) + 1 since no two trees have same rank. (H)  rank(H) + 1 - trees(H). Amortized cost. O(rank(H)) (H)  = trees(H) + 2  marks(H) potential function O(rank(H)) work adding min's children since at most rank(H) children of min O(rank(H) + trees(H)) work updating min since at most this many resulting root nodes O(rank(H) + trees(H)) to consolidate trees since number of roots decreases by 1 after each merging, and there at most rank(H) + trees(H) roots at beginning trees(H') <= rank(H) + 1 since at worst the roots have degrees 0, 1, 2, …, rank(H) can scale units in potential function to dominate cost hidden in O(trees(H)) number of marked nodes marked(H) does not increase [Note: you unmark a root y when it is linked to another root, though this case does not arise in the example]

Fibonacci Heaps: Delete Min Analysis Q. Is amortized cost of O(rank(H)) good? A. Yes, if only insert and delete-min operations. In this case, all trees are binomial trees. This implies rank(H)  lg n. A. Yes, we'll implement decrease-key so that rank(H) = O(log n). we only link trees of equal rank B0 B1 B2 B3 if no decrease-key, our data structure is a lazy version of a binomial queue decrease key will not preserve property that all trees are binomial trees, but it will be close enough to bound maximum degree by O(log n)

Decrease Key

Fibonacci Heaps: Decrease Key Intuition for deceasing the key of node x. If heap-order is not violated, just decrease the key of x. Otherwise, cut tree rooted at x and meld into root list. To keep trees flat: as soon as a node has its second child cut, cut it off and meld into root list (and unmark it). min 7 18 38 If decreasing the key of node i makes it violate heap order property, we can cutout subtree rooted at i and meld it into heap. To keep trees bushy, we limit the number of cuts among the children of any vertex to 2. Use the mark of a node to designate whether or not it has had one child cut off marked node: one child already cut 24 17 23 21 39 41 26 46 30 52 35 88 72

Fibonacci Heaps: Decrease Key Case 1. [heap order not violated] Decrease key of x. Change heap min pointer (if necessary). min 7 18 38 24 17 23 21 39 41 26 29 46 30 52 x 35 88 72 decrease-key of x from 46 to 29

Fibonacci Heaps: Decrease Key Case 1. [heap order not violated] Decrease key of x. Change heap min pointer (if necessary). min 7 18 38 24 17 23 21 39 41 26 29 30 52 x 35 88 72 decrease-key of x from 46 to 29

Fibonacci Heaps: Decrease Key Case 2a. [heap order violated] Decrease key of x. Cut tree rooted at x, meld into root list, and unmark. If parent p of x is unmarked (hasn't yet lost a child), mark it; Otherwise, cut p, meld into root list, and unmark (and do so recursively for all ancestors that lose a second child). min 7 18 38 24 17 23 21 39 41 p 26 29 15 30 52 x 35 88 72 decrease-key of x from 29 to 15

Fibonacci Heaps: Decrease Key Case 2a. [heap order violated] Decrease key of x. Cut tree rooted at x, meld into root list, and unmark. If parent p of x is unmarked (hasn't yet lost a child), mark it; Otherwise, cut p, meld into root list, and unmark (and do so recursively for all ancestors that lose a second child). min 7 18 38 24 17 23 21 39 41 p 26 15 30 52 x 35 88 72 decrease-key of x from 29 to 15

Fibonacci Heaps: Decrease Key Case 2a. [heap order violated] Decrease key of x. Cut tree rooted at x, meld into root list, and unmark. If parent p of x is unmarked (hasn't yet lost a child), mark it; Otherwise, cut p, meld into root list, and unmark (and do so recursively for all ancestors that lose a second child). x min 15 7 18 38 72 24 17 23 21 39 41 p 26 30 52 35 88 decrease-key of x from 29 to 15

Fibonacci Heaps: Decrease Key Case 2a. [heap order violated] Decrease key of x. Cut tree rooted at x, meld into root list, and unmark. If parent p of x is unmarked (hasn't yet lost a child), mark it; Otherwise, cut p, meld into root list, and unmark (and do so recursively for all ancestors that lose a second child). x min 15 7 18 38 72 24 24 17 23 21 39 41 p mark parent 26 30 52 35 88 decrease-key of x from 29 to 15

Fibonacci Heaps: Decrease Key Case 2b. [heap order violated] Decrease key of x. Cut tree rooted at x, meld into root list, and unmark. If parent p of x is unmarked (hasn't yet lost a child), mark it; Otherwise, cut p, meld into root list, and unmark (and do so recursively for all ancestors that lose a second child). min 15 7 18 38 72 24 24 17 23 21 39 41 p 26 30 52 decrease-key of x from 35 to 5 x 5 35 88

Fibonacci Heaps: Decrease Key Case 2b. [heap order violated] Decrease key of x. Cut tree rooted at x, meld into root list, and unmark. If parent p of x is unmarked (hasn't yet lost a child), mark it; Otherwise, cut p, meld into root list, and unmark (and do so recursively for all ancestors that lose a second child). min 15 7 18 38 72 24 24 17 23 21 39 41 p 26 30 52 decrease-key of x from 35 to 5 x 5 88

Fibonacci Heaps: Decrease Key Case 2b. [heap order violated] Decrease key of x. Cut tree rooted at x, meld into root list, and unmark. If parent p of x is unmarked (hasn't yet lost a child), mark it; Otherwise, cut p, meld into root list, and unmark (and do so recursively for all ancestors that lose a second child). min x 15 5 7 18 38 72 24 24 17 23 21 39 41 p 26 30 52 88 decrease-key of x from 35 to 5

Fibonacci Heaps: Decrease Key Case 2b. [heap order violated] Decrease key of x. Cut tree rooted at x, meld into root list, and unmark. If parent p of x is unmarked (hasn't yet lost a child), mark it; Otherwise, cut p, meld into root list, and unmark (and do so recursively for all ancestors that lose a second child). min x 15 5 7 18 38 72 24 24 17 23 21 39 41 second child cut p 26 30 52 88 decrease-key of x from 35 to 5

Fibonacci Heaps: Decrease Key Case 2b. [heap order violated] Decrease key of x. Cut tree rooted at x, meld into root list, and unmark. If parent p of x is unmarked (hasn't yet lost a child), mark it; Otherwise, cut p, meld into root list, and unmark (and do so recursively for all ancestors that lose a second child). min x p 15 5 26 7 18 38 72 88 24 24 17 23 21 39 41 30 52 decrease-key of x from 35 to 5

Fibonacci Heaps: Decrease Key Case 2b. [heap order violated] Decrease key of x. Cut tree rooted at x, meld into root list, and unmark. If parent p of x is unmarked (hasn't yet lost a child), mark it; Otherwise, cut p, meld into root list, and unmark (and do so recursively for all ancestors that lose a second child). min x p 15 5 26 7 18 38 72 88 p' 24 24 17 23 21 39 41 30 52 second child cut decrease-key of x from 35 to 5

Fibonacci Heaps: Decrease Key Case 2b. [heap order violated] Decrease key of x. Cut tree rooted at x, meld into root list, and unmark. If parent p of x is unmarked (hasn't yet lost a child), mark it; Otherwise, cut p, meld into root list, and unmark (and do so recursively for all ancestors that lose a second child). min x p p' p'' 15 5 26 24 7 18 38 Note: when a root is linked into another root (in delete-min consolidation phase), we unmark it Q. How can a root node ever be marked? A. In delete-min we delete a root node, but promote all of its (potentially) marked children to be roots. 72 88 don't mark parent if it's a root 17 23 21 39 41 30 52 decrease-key of x from 35 to 5

Fibonacci Heaps: Decrease Key Analysis Actual cost. O(c) O(1) time for changing the key. O(1) time for each of c cuts, plus melding into root list. Change in potential. O(1) - c trees(H') = trees(H) + c. marks(H')  marks(H) - c + 2.   c + 2  (-c + 2) = 4 - c. Amortized cost. O(1) (H)  = trees(H) + 2  marks(H) potential function When marked node y is cut by cascading cut, its mark bit is cleared (2 units of potential). One unit pays for cut, the other for unit increase in potential due to y becoming a root. marks(H') <= marks(H) - c + 2: each cut (except first) unmarks a node; last cut may or may not mark a node Can scale units of potential to dominate cost hidden in O(c) term

Analysis

Analysis Summary Insert. O(1) Delete-min. O(rank(H)) † Decrease-key. O(1) † Key lemma. rank(H) = O(log n). † amortized number of nodes is exponential in rank

Fibonacci Heaps: Bounding the Rank Lemma. Fix a point in time. Let x be a node, and let y1, …, yk denote its children in the order in which they were linked to x. Then: Pf. When yi was linked into x, x had at least i -1 children y1, …, yi-1. Since only trees of equal rank are linked, at that time rank(yi) = rank(xi)  i - 1. Since then, yi has lost at most one child. Thus, right now rank(yi)  i - 2. x y1 y2 … yk when yi was linked into x, x could have had more than i-1 children since some of them may have since been cut or yi would have been cut

Fibonacci Heaps: Bounding the Rank Lemma. Fix a point in time. Let x be a node, and let y1, …, yk denote its children in the order in which they were linked to x. Then: Def. Let Fk be smallest possible tree of rank k satisfying property. x y1 y2 … yk F0 F1 F2 F3 F4 F5 slightly non-standard definition of fibonacci with f0 = 1, f1 = 2 1 2 3 5 8 13

Fibonacci Heaps: Bounding the Rank Lemma. Fix a point in time. Let x be a node, and let y1, …, yk denote its children in the order in which they were linked to x. Then: Def. Let Fk be smallest possible tree of rank k satisfying property. x y1 y2 … yk F4 F5 F6 slightly non-standard definition of fibonacci with f0 = 1, f1 = 2 8 13 8 + 13 = 21

Fibonacci Heaps: Bounding the Rank Lemma. Fix a point in time. Let x be a node, and let y1, …, yk denote its children in the order in which they were linked to x. Then: Def. Let Fk be smallest possible tree of rank k satisfying property. Fibonacci fact. Fk  k, where  = (1 + 5) / 2  1.618. Corollary. rank(H)  log n . x y1 y2 … yk golden ratio

Fibonacci Numbers

Fibonacci Numbers: Exponential Growth Def. The Fibonacci sequence is: 1, 2, 3, 5, 8, 13, 21, … Lemma. Fk  k, where  = (1 + 5) / 2  1.618. Pf. [by induction on k] Base cases: F0 = 1  1, F1 = 2  . Inductive hypotheses: Fk  k and Fk+1  k + 1 slightly non-standard definition (definition) (inductive hypothesis) (algebra) (2 =  + 1) (algebra)

Fibonacci Numbers and Nature pinecone http://www.mcs.surrey.ac.uk/Personal/R.Knott/Fibonacci/fibnat.html cauliflower

Union

Fibonacci Heaps: Union Union. Combine two Fibonacci heaps. Representation. Root lists are circular, doubly linked lists. min min 23 24 17 7 3 21 30 26 46 18 52 41 Heap H' 35 Heap H'' 39 44

Fibonacci Heaps: Union Union. Combine two Fibonacci heaps. Representation. Root lists are circular, doubly linked lists. min 23 24 17 7 3 21 30 26 46 18 52 41 35 Heap H 39 44

Fibonacci Heaps: Union Actual cost. O(1) Change in potential. 0 Amortized cost. O(1) (H)  = trees(H) + 2  marks(H) potential function min 23 24 17 7 3 21 30 26 46 18 52 41 35 Heap H 39 44

Delete

Fibonacci Heaps: Delete Delete node x. decrease-key of x to -. delete-min element in heap. Amortized cost. O(rank(H)) O(1) amortized for decrease-key. O(rank(H)) amortized for delete-min. (H)  = trees(H) + 2  marks(H) potential function

Priority Queues Performance Cost Summary 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 main improvement: decrease-key is now O(1) we'll emphasize the first 5 ops union 1 n log n 1 1 find-min n 1 log n 1 1 n = number of elements in priority queue † amortized