Docsity

Fibonacci Heaps: Data Structure and Operations, Slides of Computer Science

Partial preview of the text

Download Fibonacci Heaps: Data Structure and Operations and more Slides Computer Science in PDF only on Docsity!

Fibonacci Heaps

Priority Queues

2

make-heap

Operation

insert

find-min

delete-min

union

decrease-key

delete

Binary

log N

log N

N

log N

log N

Binomial

log N

log N

log N

log N

log N

log N

Fibonacci

†

log N

log N

Relaxed

log N

log N

Linked List

1 N N 1 1 N

is-empty 1 1 1 1 1

Heaps

this time

† amortized

Fibonacci Heaps: Structure

• Fibonacci heap.

– Set of min-heap ordered trees.

4

H 39

min

marked

Fibonacci Heaps: Implementation

• Implementation.

– Represent trees using left-child, right sibling

pointers and circular, doubly linked list.

• can quickly splice off subtrees

– Roots of trees connected with circular doubly

linked list.

• fast union

– Pointer to root of tree with min element.

• fast find-min

5

H 39

min

Fibonacci Heaps: Insert

• Insert.

– Create a new singleton tree.

– Add to left of min pointer.

– Update min pointer.

7

H 39

min

Insert 21

Fibonacci Heaps: Insert

• Insert.

– Create a new singleton tree.

– Add to left of min pointer.

– Update min pointer.

8

min

H

Insert 21

Fibonacci Heaps: Union

• Union.

– Concatenate two Fibonacci heaps.

– Root lists are circular, doubly linked lists.

10

min

H' H''

min

Fibonacci Heaps: Union

• Union.

– Concatenate two Fibonacci heaps.

– Root lists are circular, doubly linked lists.

• Running time. O(1) amortized

– Actual cost = O(1).

– Change in potential = 0.

– Amortized cost = O(1).

11

min

H' H''

Fibonacci Heaps: Delete Min

• Delete min.

– Delete min and concatenate its children into root

list.

– Consolidate trees so that no two roots have same

degree.

13

current

min

Fibonacci Heaps: Delete Min

• Delete min.

– Delete min and concatenate its children into root

list.

– Consolidate trees so that no two roots have same

degree.

14

current

0 1 2 3

min

Fibonacci Heaps: Delete Min

• Delete min.

– Delete min and concatenate its children into root

list.

– Consolidate trees so that no two roots have same

degree.

16

current

0 1 2 3

min

Fibonacci Heaps: Delete Min

• Delete min.

– Delete min and concatenate its children into root

list.

– Consolidate trees so that no two roots have same

degree.

17

current

0 1 2 3

Merge 17 and 23 trees.

min

Fibonacci Heaps: Delete Min

• Delete min.

– Delete min and concatenate its children into root

list.

– Consolidate trees so that no two roots have same

degree.

19

current

0 1 2 3 23

Merge 7 and 24 trees.

min

Fibonacci Heaps: Delete Min

• Delete min.

– Delete min and concatenate its children into root

list.

– Consolidate trees so that no two roots have same

degree.

20

current

0 1 2 3

min