Docsity

Fibonacci Heaps Structure - Analysis of Algorithm - Lecture Slides, Slides of Computer Science

Toggle sidebar
bg1
Fibonacci Heaps
0.
2
Priority Queues
make-heap
Operation
insert
find-min
delete-min
union
decrease-key
delete
1
Binary
log N
1
log N
N
log N
log N
1
Binomial
log N
log N
log N
log N
log N
log N
1
Fibonacci †
1
1
log N
1
1
log N
1
Relaxed
1
1
log N
1
1
log N
1
Linked List
1
N
N
1
1
N
is-empty 1 1 1 11
Heaps
this time
†amortized
3
Fibonacci Heaps
Fibonacci heap history. Fredman and Tarjan (1986)
■Ingenious data structure and analysis.
■Original motivation: O(m + n log n) shortest path algorithm.
–also led to faster algorithms for MST, weighted bipartite matching
■Still ahead of its time.
Fibonacci heap intuition.
■Similar to binomial heaps, but less structured.
■Decrease-key and union run in O(1) time.
■"Lazy" unions.
4
Fibonacci Heaps: Structure
Fibonacci heap.
■Set of min-heap ordered trees.
723
30
17
35
26 46
24
H39
41
18 52
3
44
min
marked
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Fibonacci Heaps Structure - Analysis of Algorithm - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

Fibonacci Heaps

Priority Queues

Operationmake-heap

insertfind-min delete-min

union decrease-key

delete

Binarylog N

log N

N

log Nlog N

Binomial

log Nlog Nlog Nlog Nlog Nlog N

Fibonacci

†

1 1 log N

log N

Relaxed

log N

log N

Linked List

1 N N 11 N

is-empty

Heaps

this time

† amortized

3

Fibonacci Heaps

Fibonacci heap history.

Fredman and Tarjan (1986)

n^

Ingenious data structure and analysis. n^

Original motivation: O(m + n log n) shortest path algorithm.^ –

also led to faster algorithms for MST, weighted bipartite matching n^

Still ahead of its time. Fibonacci heap intuition.^ n^

Similar to binomial heaps, but less structured. n^

Decrease-key and union run in O(1) time. n^

"Lazy" unions.

Fibonacci Heaps: Structure

Fibonacci heap.^ n^

Set of min-heap ordered trees.

7

23

17 30

26 35

24 46

H

39

41

18

(^352)

44

min

marked

Docsity.com

5

Fibonacci Heaps: Implementation

Implementation.^ n^

Represent trees using left-child, right sibling pointers and circular,doubly linked list.^ –

can quickly splice off subtrees n^

Roots of trees connected with circular doubly linked list.^ –

fast union n^

Pointer to root of tree with min element.^ –

fast find-min

7

23

17 30

26 35

24 46

H

39

41

18

(^352)

44

min

Fibonacci Heaps: Potential Function

Key quantities.^ n^

Degree[x] = degree of node x. n^

Mark[x] = mark of node x (black or gray). n^

t(H)

= # trees.

n^

m(H) = # marked nodes. n^

(H) = t(H) + 2m(H) = potential function.

7

23

17 30

26 35

24 46

H

t(H) = 5, m(H) = 3 Φ

(H) = 11

39

41

18

(^352)

44

min

degree = 3

7

Fibonacci Heaps: Insert

Insert.^ n^

Create a new singleton tree. n^

Add to left of min pointer. n^

Update min pointer.

7

23

17 30

26 35

24 46

H

39

41

18

(^352)

44

min

21

Insert 21

Fibonacci Heaps: Insert

Insert.^ n^

Create a new singleton tree. n^

Add to left of min pointer. n^

Update min pointer.

39

41

7

23

18

(^352)

17 30

26 35

24 46

44

min

H

21

Insert 21

Docsity.com

13

Fibonacci Heaps: Delete Min

Delete min.^ n^

Delete min and concatenate its children into root list. n^

Consolidate trees so that no two roots have same degree.

39

41

17

23

18

52

(^730)

26 35

24 46

44

current

min

Fibonacci Heaps: Delete Min

Delete min.^ n^

Delete min and concatenate its children into root list. n^

Consolidate trees so that no two roots have same degree.

39

41

17

23

18

52

(^730)

26 35

24 46

44

current

0

1

2

3

min

15

Fibonacci Heaps: Delete Min

Delete min.^ n^

Delete min and concatenate its children into root list. n^

Consolidate trees so that no two roots have same degree.

39

41

17

23

18

52

(^730)

26 35

24 46

44

current

0

1

2

3

min

Fibonacci Heaps: Delete Min

Delete min.^ n^

Delete min and concatenate its children into root list. n^

Consolidate trees so that no two roots have same degree.

39

41

17

23

18

52

(^730)

26 35

24 46

44

current

0

1

2

3

min

Docsity.com

17

Fibonacci Heaps: Delete Min

Delete min.^ n^

Delete min and concatenate its children into root list. n^

Consolidate trees so that no two roots have same degree.

39

41

17

23

18

52

(^730)

26 35

24 46

44

current

0

1

2

3

Merge 17 and 23 trees.

min

Fibonacci Heaps: Delete Min

Delete min.^ n^

Delete min and concatenate its children into root list. n^

Consolidate trees so that no two roots have same degree.

39

41

17 23

18

52

(^730)

26 35

24 46

44

current

0

1

2

3

Merge 7 and 17 trees.

min

19

Fibonacci Heaps: Delete Min

Delete min.^ n^

Delete min and concatenate its children into root list. n^

Consolidate trees so that no two roots have same degree.

39

41

(^730)

18

52

17

26 35

24 46

44

current

0

1

2

3

23

Merge 7 and 24 trees.

min

Fibonacci Heaps: Delete Min

Delete min.^ n^

Delete min and concatenate its children into root list. n^

Consolidate trees so that no two roots have same degree.

39

41

(^730)

18

52

17 23

26 35

24 46

44

current

0

1

2

3

min

Docsity.com

25

Fibonacci Heaps: Delete Min

Delete min.^ n^

Delete min and concatenate its children into root list. n^

Consolidate trees so that no two roots have same degree.

39

41

(^730)

18

52

17 23

26 35

24 46

44

current

0

1

2

3

min

Fibonacci Heaps: Delete Min

Delete min.^ n^

Delete min and concatenate its children into root list. n^

Consolidate trees so that no two roots have same degree.

39

41

(^730)

18

52

17 23

26 35

24 46

44

min

Stop.

27

Fibonacci Heaps: Delete Min Analysis

Notation.^ n^

D(n) = max degree of any node in Fibonacci heap with n nodes. n^

t(H)

= # trees in heap H.

n^

(H) = t(H) + 2m(H).

Actual cost.

O(D(n) + t(H))

n^

O(D(n)) work adding min’s children into root list and updating min.^ –

at most D(n) children of min node n^

O(D(n) + t(H)) work consolidating trees.^ –

work is proportional to size of root list since number of rootsdecreases by one after each merging – ≤

D(n) + t(H) - 1 root nodes at beginning of consolidation

Amortized cost. O(D(n))^ n^

t(H’)

D(n) + 1 since no two trees have same degree.

n^

(H)

D(n) + 1 - t(H).

Fibonacci Heaps: Delete Min Analysis

Is amortized cost of O(D(n)) good?^ n^

Yes, if only Insert, Delete-min, and Union operations supported.^ –

in this case, Fibonacci heap contains only binomial trees sincewe only merge trees of equal root degree – this implies D(n)

log

N 2

n^

Yes, if we support Decrease-key in clever way.^ –

we’ll show that D(n)

log

Nφ

, where

φ

is golden ratio

-^ φ

φ

-^ φ

-^ limiting ratio between successive Fibonacci numbers!

Docsity.com

29

Decrease key of element x to k.^ n^

Case 0: min-heap property not violated.^ –

decrease key of x to k – change heap min pointer if necessary

24 46

17 30

23

7

26 88

21 52

18 39

38 41

Decrease 46 to 45.

72

Fibonacci Heaps: Decrease Key

45

35

min

Decrease key of element x to k.^ n^

Case 1: parent of x is unmarked.^ –

decrease key of x to k – cut off link between x and its parent – mark parent – add tree rooted at x to root list, updating heap min pointer

24 45

17 30

23

7

26 88

21 52

18 39

38 41

Decrease 45 to 15.

72

Fibonacci Heaps: Decrease Key

15

35

min

31

Decrease key of element x to k.^ n^

Case 1: parent of x is unmarked.^ –

decrease key of x to k – cut off link between x and its parent – mark parent – add tree rooted at x to root list, updating heap min pointer

24 15

17 30

23

7

26 88

21 52

18 39

38 41

Decrease 45 to 15.

24 72

Fibonacci Heaps: Decrease Key

35

min

Decrease key of element x to k.^ n^

Case 1: parent of x is unmarked.^ –

decrease key of x to k – cut off link between x and its parent – mark parent – add tree rooted at x to root list, updating heap min pointer

24

17 30

23

7

26 88

21 52

18 39

38 41

Decrease 45 to 15.

24

Fibonacci Heaps: Decrease Key

35

min

15 72

Docsity.com

37

Notation.^ n^

t(H)

= # trees in heap H.

n^

m(H) = # marked nodes in heap H. n^

(H)

= t(H) + 2m(H).

Actual cost. O(c)^ n^

O(1) time for decrease key. n^

O(1) time for each of c cascading cuts, plus reinserting in root list. Amortized cost. O(1)^ n^

t(H’)

= t(H) + c

n^

m(H’)

m(H) - c + 2

-^

each cascading cut unmarks a node

-^

last cascading cut could potentially mark a node

n^

c + 2(-c + 2) = 4 - c.

Fibonacci Heaps: Decrease Key Analysis

Delete node x.^ n^

Decrease key of x to -

n^

Delete min element in heap. Amortized cost. O(D(n))^ n^

O(1) for decrease-key. n^

O(D(n)) for delete-min. n^

D(n) = max degree of any node in Fibonacci heap.

Fibonacci Heaps: Delete

39

Fibonacci Heaps: Bounding Max Degree

Definition. D(N) = max degree in Fibonacci heap with N nodes.Key lemma. D(N)

log

N, whereφ

φ

Corollary. Delete and Delete-min take O(log N) amortized time.Lemma. Let x be a node with degree k, and let y

,... , y 1

denote thek

children of x in the order in which they were linked to x. Then:Proof.^ n^

When y

is linked to x, yi

,... , y 1

i-

already linked to x,

degree(x) = i - 1 ⇒

degree(y

) = i - 1 since we only link nodes of equal degreei

n^

Since then, y

has lost at most one childi

-^ otherwise it would have been cut from x n^

Thus, degree(y

) = i - 1 or i - 2i

≥^

if

if

degree

i

i

i

y^ i

Fibonacci Heaps: Bounding Max Degree

Key lemma. In a Fibonacci heap with N nodes, the maximum degree ofany node is at most log

N, whereφ

φ

Proof of key lemma.^ n^

For any node x, we show that size(x)

≥ φ

degree(x)

-^ size(x) = # node in subtree rooted at x –^ taking base

φ^

logs, degree(x)

log

(size(x))φ

log

N.φ

n^

Let s

be min size of tree rooted at any degree k node.k^

-^ trivial to see that s

= 1, s 0

-^ s

monotonically increases with kk^

n^

Let x* be a degree k node of size s

,k^

and let y

,... , y 1

be children in orderk

that they were linked to x*.

Assume k

=^ − =

− = =^220

2 2

] deg[ 2

size

k i^

i k i

i k i

y

k i

i

k

s s s

y

x size

s

i

Docsity.com

41

Fibonacci Facts

Definition. The Fibonacci sequence is:^ n^

•^

Slightly nonstandard definition. Fact F1.

F^ k

≥ φ

k, where

φ

Fact F2.Consequence.

s^ k

F

k^

≥^

kφ

n^

This implies that size(x)

≥ φ

degree(x)

for all nodes x.

if

F

F

if

if

F

(^2) - k

(^1) - k

k

k k k

≥^

−^2 =^0

For

k i^

i

k^

F

F

k

=^ − =

− = =^220

2 2

] deg[ 2

size

k i^

i k i

i k i

y

k i

i

k

s s s

y

x size

s

i

Golden Ratio

Definition. The Fibonacci sequence is: 1, 2, 3, 5, 8, 13, 21,.. .Definition. The golden ratio

φ

n^

Divide a rectangle into a square and smaller rectangle such that thesmaller rectangle has the same ratio as original one.

Parthenon, Athens Greece

43

Fibonacci Facts

Fibonacci Numbers and Nature

Pinecone

Cauliflower

Docsity.com