
5 9 two weeks ⇡ 1 5 2 5 3 1 1 0 5 1 2 3 1 1 0 3 4 Finding Shortest Paths 1 s 3 4 Use of Amortized Analysis X D B B B B Amortized Analysis T T T T T PUSH(T) PUSH(B) PUSH(X) POP PUSH(D) MULTIPOP(3) min next week 58 30 10 43 41 33 70 32 Fibonacci Heaps 54 66 82 51 5.2 Fibonacci Heaps Frank Stajano Thomas Sauerwald Lent 2015 5.1: Amortized Analysis T.S. 2 Fibon. heap (1) O (1) O (1) O (log n) O (1) O (1) O (log n) O Priority Queues Overview Operation Linked list Binary heap Binomial heap MAKE-HEAP (1) (1) (1) O O O INSERT (1) (log n) (log n) O O O MINIMUM (n) (1) (log n) O O O EXTRACT-MIN (n) (log n) (log n) O O O MERGE (n) (n) (log n) O O O DECREASE-KEY (1) (log n) (log n) O O O DELETE (1) (log n) (log n) O O O 5.2: Fibonacci Heaps T.S. 2 Priority Queues Overview Operation Linked list Binary heap Binomial heap Fibon. heap MAKE-HEAP (1) (1) (1) (1) O O O O INSERT (1) (log n) (log n) (1) O O O O MINIMUM (n) (1) (log n) (1) O O O O EXTRACT-MIN (n) (log n) (log n) (log n) O O O O MERGE (n) (n) (log n) (1) O O O O DECREASE-KEY (1) (log n) (log n) (1) O O O O DELETE (1) (log n) (log n) (log n) O O O O 5.2: Fibonacci Heaps T.S. 2 actual cost amortized cost All these cost bounds hold if n is the size of the heap. Binomial Heap vs. Fibonacci Heap: Costs Operation Binomial heap Fibonacci heap MAKE-HEAP (1) (1) O O INSERT (log n) (1) O O MINIMUM (log n) (1) O O EXTRACT-MIN (log n) (log n) O O MERGE (log n) (1) O O DECREASE-KEY (log n) (1) O O DELETE (log n) (log n) O O 5.2: Fibonacci Heaps T.S. 3 All these cost bounds hold if n is the size of the heap. Binomial Heap vs. Fibonacci Heap: Costs Operation Binomial heap Fibonacci heap actual cost amortized cost MAKE-HEAP (1) (1) O O INSERT (log n) (1) O O MINIMUM (log n) (1) O O EXTRACT-MIN (log n) (log n) O O MERGE (log n) (1) O O DECREASE-KEY (log n) (1) O O DELETE (log n) (log n) O O 5.2: Fibonacci Heaps T.S. 3 Binomial Heap vs. Fibonacci Heap: Costs Operation Binomial heap Fibonacci heap actual cost amortized cost MAKE-HEAP (1) (1) O O INSERT (log n) (1) O O MINIMUM (log n) (1) O O EXTRACT-MIN (log n) (log n) O O MERGE (log n) (1) O O DECREASE-KEY (log n) (1) O O DELETE (log n) (log n) O O All these cost bounds hold if n is the size of the heap. 5.2: Fibonacci Heaps T.S. 3 All these cost bounds hold if n is the size of the heap. c = c = = c = (log n) 1 2 ··· k O Pk c = (k log n) ) i=1 i O Binomial Heap vs. Fibonacci Heap: Costs Operation Binomial heap Fibonacci heap actual cost amortized cost MAKE-HEAP (1) (1) O O INSERT (log n) (1) O O MINIMUM (log n) (1) O O EXTRACT-MIN (log n) (log n) O O MERGE (log n) (1) O O DECREASE-KEY (log n) (1) O O DELETE (log n) (log n) O O Binomial Heap: k=2 DECREASE-KEY + k=2 INSERT 5.2: Fibonacci Heaps T.S. 3 All these cost bounds hold if n is the size of the heap. Pk c = (k log n) ) i=1 i O Binomial Heap vs. Fibonacci Heap: Costs Operation Binomial heap Fibonacci heap actual cost amortized cost MAKE-HEAP (1) (1) O O INSERT (log n) (1) O O MINIMUM (log n) (1) O O EXTRACT-MIN (log n) (log n) O O MERGE (log n) (1) O O DECREASE-KEY (log n) (1) O O DELETE (log n) (log n) O O Binomial Heap: k=2 DECREASE-KEY + k=2 INSERT c = c = = c = (log n) 1 2 ··· k O 5.2: Fibonacci Heaps T.S. 3 All these cost bounds hold if n is the size of the heap. Binomial Heap vs. Fibonacci Heap: Costs Operation Binomial heap Fibonacci heap actual cost amortized cost MAKE-HEAP (1) (1) O O INSERT (log n) (1) O O MINIMUM (log n) (1) O O EXTRACT-MIN (log n) (log n) O O MERGE (log n) (1) O O DECREASE-KEY (log n) (1) O O DELETE (log n) (log n) O O Binomial Heap: k=2 DECREASE-KEY + k=2 INSERT c = c = = c = (log n) 1 2 ··· k O Pk c = (k log n) ) i=1 i O 5.2: Fibonacci Heaps T.S. 3 All these cost bounds hold if n is the size of the heap. c = c = = c = (1) e1 e2 ··· ek O Pk c Pk c = (k) ) i=1 i ≤ i=1 ei O Binomial Heap vs. Fibonacci Heap: Costs Operation Binomial heap Fibonacci heap actual cost amortized cost MAKE-HEAP (1) (1) O O INSERT (log n) (1) O O MINIMUM (log n) (1) O O EXTRACT-MIN (log n) (log n) O O MERGE (log n) (1) O O DECREASE-KEY (log n) (1) O O DELETE (log n) (log n) O O Binomial Heap: k=2 DECREASE-KEY Fibonacci Heap: k=2 + k=2 INSERT DECREASE-KEY + k=2 INSERT c = c = = c = (log n) 1 2 ··· k O Pk c = (k log n) ) i=1 i O 5.2: Fibonacci Heaps T.S. 3 All these cost bounds hold if n is the size of the heap. Pk c Pk c = (k) ) i=1 i ≤ i=1 ei O Binomial Heap vs. Fibonacci Heap: Costs Operation Binomial heap Fibonacci heap actual cost amortized cost MAKE-HEAP (1) (1) O O INSERT (log n) (1) O O MINIMUM (log n) (1) O O EXTRACT-MIN (log n) (log n) O O MERGE (log n) (1) O O DECREASE-KEY (log n) (1) O O DELETE (log n) (log n) O O Binomial Heap: k=2 DECREASE-KEY Fibonacci Heap: k=2 + k=2 INSERT DECREASE-KEY + k=2 INSERT c = c = = c = (log n) c = c = = c = (1) 1 2 ··· k O e1 e2 ··· ek O Pk c = (k log n) ) i=1 i O 5.2: Fibonacci Heaps T.S. 3 All these cost bounds hold if n is the size of the heap. Binomial Heap vs. Fibonacci Heap: Costs Operation Binomial heap Fibonacci heap actual cost amortized cost MAKE-HEAP (1) (1) O O INSERT (log n) (1) O O MINIMUM (log n) (1) O O EXTRACT-MIN (log n) (log n) O O MERGE (log n) (1) O O DECREASE-KEY (log n) (1) O O DELETE (log n) (log n) O O Binomial Heap: k=2 DECREASE-KEY Fibonacci Heap: k=2 + k=2 INSERT DECREASE-KEY + k=2 INSERT c = c = = c = (log n) c = c = = c = (1) 1 2 ··· k O e1 e2 ··· ek O Pk c = (k log n) Pk c Pk c = (k) ) i=1 i O ) i=1 i ≤ i=1 ei O 5.2: Fibonacci Heaps T.S. 3 Pk Pk i=1 eci i=1 ci Potential Potential 0, but should be ≥ also as small as possible Actual vs. Amortized Cost 14 (1) ·O 2 (1) ·O (1) O k 0 1 2 14 5.2: Fibonacci Heaps T.S. 4 Pk i=1 ci Potential Potential 0, but should be ≥ also as small as possible Actual vs. Amortized Cost Pk i=1 eci 14 (1) ·O 2 (1) ·O (1) O k 0 1 2 14 5.2: Fibonacci Heaps T.S. 4 Potential Potential 0, but should be ≥ also as small as possible Actual vs. Amortized Cost Pk Pk i=1 eci i=1 ci 14 (1) ·O 2 (1) ·O (1) O k 0 1 2 14 5.2: Fibonacci Heaps T.S. 4 Potential 0, but should be ≥ also as small as possible Actual vs. Amortized Cost Pk Pk i=1 eci i=1 ci 14 (1) ·O Potential 2 (1) ·O (1) O k 0 1 2 14 5.2: Fibonacci Heaps T.S. 4 Actual vs. Amortized Cost Pk Pk i=1 eci i=1 ci 14 (1) ·O Potential Potential 0, but should be 2 (1) ≥ ·O also as small as possible (1) O k 0 1 2 14 5.2: Fibonacci Heaps T.S. 4 Outline Structure Operations Glimpse at the Analysis 5.2: Fibonacci Heaps T.S. 5 MERGE: Merge two binomial heaps using Binary Addition Procedure INSERT: Add B(0) and perform a MERGE EXTRACT-MIN: Find tree with minimum key, cut it and perform a MERGE DECREASE-KEY: The same as in a binary heap Operations: Reminder: Binomial Heaps Binomial Trees B(0) B(1) B(2) B(3) B(k) B(k 1) − B(k 1) − Binomial Heaps Binomial Heap is a collection of binomial trees of different orders, each of which obeys the heap property 5.2: Fibonacci Heaps T.S. 6 MERGE: Merge two binomial heaps using Binary Addition Procedure INSERT: Add B(0) and perform a MERGE EXTRACT-MIN: Find tree with minimum key, cut it and perform a MERGE DECREASE-KEY: The same as in a binary heap Reminder: Binomial Heaps Binomial Trees B(0) B(1) B(2) B(3) B(k) B(k 1) − B(k 1) − Binomial Heaps Binomial Heap is a collection of binomial trees of different orders, each of which obeys the heap property Operations: 5.2: Fibonacci Heaps T.S.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages177 Page
-
File Size-