Fibonacci-Heaps

Fibonacci-Heaps - Chapter 19: Fibonacci Heap Many of the...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
Chapter 19: Fibonacci Heap Many of the slides are from Prof. Leong Hon Wai’s resources at National University of Singapore
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Priority Queue ADT Priority Queue is an ADT for maintaining a set S of elements, each with a key value and supports the following operations: I NSERT ( S , x ) inserts element x into S (also write as S S { x } M INIMUM ( S ) returns element in S with min key E XTRACT -M IN ( S ) removes and returns element in S with min key D ECREASE -K EY ( S , x , k ) decreases the value of element x ’s key to a new ( smaller ) value k .
Background image of page 2
PQ implementations… 1964 Binary Heap J. W. J. Williams 1972 Leftist Heap C. A. Crane 1978 Binomial Heap J. Vuillemin 1984 Fibonacci Heap M. L. Fredman, R. E. Tarjan 1985 Skew Heap D. D. Sleator R. E. Tarjan 1988 Relaxed Heap Driscoll, Gabow Shrairman, Tarjan Many data structures proposed for PQ
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Different Priority Queues Data Str I NSERT M IN Extract- M IN D-K EY D ELETE Union Binary H O (lg n ) O (1) O (lg n ) O (lg n ) O (lg n ) O(n) Binomial H O (lg n ) O (lg n ) O (lg n ) O (lg n ) O (lg n ) O (lg n ) Fibonacci O (1) O (1) O (lg n ) O (1) O (lg n ) O (1) Time Bounds for different PQ implementations n is the number of items in the PQ
Background image of page 4
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Binary Min-Heap (as in Heapsort) Binary min-heap is an array A [1. . n ] that can be viewed as a nearly complete binary tree Number the nodes using level order traversal L EFT ( i ) = 2 i and R IGHT ( i ) = 2 i +1 and P ARENT ( i ) = i /2 Height of tree lg n Heap Property: (Each node its parent node) A [P ARENT ( i )] A [ i ]
Background image of page 6
MinHeap – Two views 4 6 12 8 27 11 10 9 16 15 1 2 3 4 5 6 7 8 9 10 4 6 10 12 8 27 11 15 16 9 A [1. .10] 1 2 3 4 5 6 7 8 9 10 Left ( i ) = 2 i Right ( i ) = 2 i + 1 Parent ( i ) = i /2 Array index ::= level order traversal Heap Property: for all i A [Parent( i )] A [ i ]
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
MinHeap – Insert operation (1) 4 6 10 12 8 27 11 15 16 9 A [1. .10] 1 2 3 4 5 6 7 8 9 10 5 11 H EAP -I NSERT ( A , key ): insert at end of array S IFT -U P to restore HP Example: H EAP -I NSERT ( A , 5) 4 6 12 8 27 11 10 9 16 15 1 2 3 4 5 6 7 8 9 10 5 Restore heap property with S IFT -U P
Background image of page 8
MinHeap – Insert operation (2) 4 6 12 5 27 11 10 8 9 16 15 1 2 3 4 5 6 7 8 9 10 4 6 10 12 5 27 11 15 16 9 A [1. .10] 1 2 3 4 5 6 7 8 9 10 8 11 H EAP -I NSERT ( A , key ): insert at end of array S IFT -U P to restore HP Restore heap property with S IFT -U P Example: H EAP -I NSERT ( A , 5)
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
MinHeap – Insert operation (3) 4 5 12 6 27 11 10 8 9 16 15 1 2 3 4 5 6 7 8 9 10 4 5 10 12 6 27 11 15 16 9 A [1. .10] 1 2 3 4 5 6 7 8 9 10 H EAP -I NSERT ( A , key ): insert at end of array S IFT -U P to restore HP Restore heap property with S IFT -U P Example: H EAP -I NSERT ( A , 5) 8 11
Background image of page 10
MinHeap – Insert operation (4) 4 5 12 6 27 11 10 8 9 16 15 1 2 3 4 5 6 7 8 9 10 4 5 10 12 6 27 11 15 16 9 A [1. .10] 1 2 3 4 5 6 7 8 9 10 H EAP -I NSERT ( A , key ): insert at end of array S IFT -U P to restore HP Done! Example: H EAP -I NSERT ( A , 5) 8 11
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
MinHeap – Insert operation (5) H EAP -I NSERT ( A, key ) A is a heap (array) heap-size ( A ) heap-size ( A ) + 1 A [ heap-size ( A )] key S IFT -U P ( A , heap-size ( A )) S IFT -U P ( A, n ) key A [ n ] i n while i > 1 and A [P ARENT ( i )] > key do A [ i ] A [P ARENT ( i )] i P ARENT ( i ) A [ i ] key T HEAP-INSERT ( n ) = T SIFT-UP ( n ) + Θ (1) = O (lg n ) T SIFT-UP ( n ) = O ( h ) = O (lg n ) ( h
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 89

Fibonacci-Heaps - Chapter 19: Fibonacci Heap Many of the...

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online