Fibonacci-Heaps

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

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

Chapter 19: Fibonacci Heap Many of the slides are from Prof. Leong Hon Wai’s resources at National University of Singapore

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

View Full Document
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 .
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

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

View Full Document
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

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

View Full Document
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 ]
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 ]

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

View Full Document
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
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)

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

View Full Document
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
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

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

View Full Document
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
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 12/03/2011 for the course COT 5407 taught by Professor Staff during the Fall '08 term at FIU.

### 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
Ask a homework question - tutors are online