Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 27

Fibonacci Heaps: Structure

Fibonacci heap. Set of heap-ordered trees.


each parent larger than its children

Maintain pointer to minimum element.

Set of marked nodes.

roots

heap-ordered tree

17

24

23

30

26

46

18

52

41

Heap H

35

39

44
1

Fibonacci Heaps: Structure


Fibonacci heap. Set of heap-ordered trees.

Maintain pointer to minimum element.

Set of marked nodes. find-min takes O(1) time

min

17

24

23

30

26

46

18

52

41

Heap H

35

39

44
2

Fibonacci Heaps: Structure


Fibonacci heap. Set of heap-ordered trees.

Maintain pointer to minimum element. Set of marked nodes. use to keep heaps flat (stay tuned)

min

17

24

23

30

26

46

18

52

41

Heap H

35

marked

39

44
3

Fibonacci Heaps: Notation


Notation. n

= number of nodes in heap. = number of children of node x.

rank(x)

rank(H)

= max rank of any node in heap H.

trees(H) = number of trees in heap H. marks(H) = number of marked nodes in heap H.

trees(H) = 5

marks(H) = 3

n = 14

rank = 3

min

17

24

23

30

26

46

18

52

41

Heap H

35

marked

39

44
4

Fibonacci Heaps: Potential Function


(H) = trees(H) + 2 marks(H) potential of heap H

trees(H) = 5

marks(H) = 3

(H) = 5 + 23 = 11

min

17

24

23

30

26

46

18

52

41

Heap H

35

marked

39

44
5

Fibonacci Heaps: Insert


Insert. Create a new singleton tree.

Add to left of min pointer.

Update min pointer.

Insert 21
21

min

17

24

23

30

26 35

46

18

52

41 44
6

39

Fibonacci Heaps: Insert


Insert. Create a new singleton tree.

Add to left of min pointer.

Update min pointer.

Insert 21

min

17

24

23

21

30

26 35

46

18

52

41 44
7

39

Fibonacci Heaps: Insert


Insert. Create a new singleton tree.

Add to left of min pointer.

Update min pointer.

Running time. O(1) amortized Actual cost = O(1).


Insert 21

Change in potential = +1.


Amortized cost = O(1). min

17

24

23

21

30

26 35

46

18

52

41 44
8

39

Fibonacci Heaps: Union


Union. Concatenate two Fibonacci heaps.

Root lists are circular, doubly linked lists.

min

min

23

24

17

21

H'
30 26 35 46 18 52 41 44

H''

39

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).


min

23

24

17

21

H'
30 26 35 46 18 52 41 44

H''

39

10

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.

min
7 24 23 17 3

30

26

46

18 39

52

41 44

35

11

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.

current

min
7 24 23 17 18 52 41

30

26

46

39

44

35

12

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.

current

min
7 24 23 17 18 52 41

30

26

46

39

44

35

13

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.

current min
7 24 23 17 18 52 41

30

26

46

39

44

35

14

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.

min
7 24 23 17 18 52 41

30

26

46

current

39

44

35

15

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.

min
7 24 23 17 18 52 41

30

26

46

current

39

44

35

Merge 17 and 23 trees.


16

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.

min
7 24 17

current

18

52

41

30

26

46

23

39

44

35

Merge 7 and 17 trees.


17

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.

min
24 7

current

18

52

41

26

46

17

30

39

44

35

23

Merge 7 and 24 trees.


18

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.

min
7

current

18

52

41

24

17

30

39

44

26

46

23

35
19

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.

min
7

current

18

52

41

24

17

30

39

44

26

46

23

35
20

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.

min
7 18

current

52

41

24

17

30

39

44

26

46

23

35
21

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.

min
7 18 52

current

41

24

17

30

39

44

26

46

23

Merge 41 and 18 trees.


35
22

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.

min
7 52

current

18

24

17

30

41

39

26

46

23

44

35
23

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.

min
7 52

current

18

24

17

30

41

39

26

46

23

44

35
24

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.

min
7 52 18

24

17

30

41

39

26

46

23

44

Stop.
35
25

Fibonacci Heaps: Delete


Delete node x. Delete min element in heap.

Amortized cost. O(D(n)) O(1) for decrease-key.


O(D(n)) for delete-min. D(n) = max degree of any node in Fibonacci heap.

26

Time complexity Binomial Heap Fibonacci Heap Creation O(1) O(1) Findmin O(1) O(1) Insertion O(logN) O(1) merge O(logN) O(1) DeleteMin O(logN) O(logN) Decrease-Key O(logN) O(1) Delete O(logN) O(logN)

27

You might also like