Sunteți pe pagina 1din 27

Fibonacci Heaps: Structure

Fibonacci heap.

each parent larger than its children

Set of heap-ordered trees. 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 rank(x) rank(H)

= number of nodes in heap. = number of children of node x. = 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.

reate a ne! sin"leton tree. #dd to left of min pointer. $pdate min pointer.

Insert &)
&)

min

)% '( &+ '*

&, ,+

&'

'

)/

*&

,) ,,
6

'.

Fibonacci Heaps: Insert


Insert.

reate a ne! sin"leton tree. #dd to left of min pointer. $pdate min pointer.

Insert &)

min

)% '( &+ '*

&, ,+

&'

&)

'

)/

*&

,) ,,
7

'.

Fibonacci Heaps: Insert


Insert.

reate a ne! sin"leton tree. #dd to left of min pointer. $pdate min pointer.

0unnin" time. 1()) amorti2ed

#ctual cost = 1()). han"e in potential = 3). #morti2ed cost = 1()).

Insert &)

min

)% '( &+ '*

&, ,+

&'

&)

'

)/

*&

,) ,,
8

'.

Fibonacci Heaps: Union


$nion.

oncatenate t!o Fibonacci heaps. 0oot lists are circular4 doubly linked lists.

min

min

&'

&,

)%

'

&)

-5

'(

&+ '*

,+

)/ '.

*&

,) ,,

-5 5

Fibonacci Heaps: Union


$nion.

oncatenate t!o Fibonacci heaps. 0oot lists are circular4 doubly linked lists.

0unnin" time. 1()) amorti2ed

#ctual cost = 1()). han"e in potential = (. #morti2ed cost = 1()). min

&'

&,

)%

'

&)

-5

'(

&+ '*

,+

)/ '.

*&

,) ,,

-5 5

10

Fibonacci Heaps: Delete Min


6elete min.

6elete min and concatenate its children into root list. onsolidate trees so that no t!o roots ha7e same de"ree.

min
% &, &' )% '

'(

&+

,+

)/ '.

*&

,) ,,

'*

11

Fibonacci Heaps: Delete Min


6elete min.

6elete min and concatenate its children into root list. onsolidate trees so that no t!o roots ha7e same de"ree.

min

current

&,

&'

)%

)/

*&

,)

'(

&+

,+

'.

,,

'*

12

Fibonacci Heaps: Delete Min


6elete min.

6elete min and concatenate its children into root list. onsolidate trees so that no t!o roots ha7e same de"ree.

&

'

min

current

&,

&'

)%

)/

*&

,)

'(

&+

,+

'.

,,

'*

13

Fibonacci Heaps: Delete Min


6elete min.

6elete min and concatenate its children into root list. onsolidate trees so that no t!o roots ha7e same de"ree.

&

'

current min
% &, &' )% )/ *& ,)

'(

&+

,+

'.

,,

'*

14

Fibonacci Heaps: Delete Min


6elete min.

6elete min and concatenate its children into root list. onsolidate trees so that no t!o roots ha7e same de"ree.

&

'

min
% &, &' )% )/ *& ,)

'(

&+

,+

current

'.

,,

'*

15

Fibonacci Heaps: Delete Min


6elete min.

6elete min and concatenate its children into root list. onsolidate trees so that no t!o roots ha7e same de"ree.

&

'

min
% &, &' )% )/ *& ,)

'(

&+

,+

current

'.

,,

'*

Mer"e )% and &' trees.


16

Fibonacci Heaps: Delete Min


6elete min.

6elete min and concatenate its children into root list. onsolidate trees so that no t!o roots ha7e same de"ree.

&

'

min
% &, )%

current
)/ *& ,)

'(

&+

,+

&'

'.

,,

'*

Mer"e % and )% trees.


17

Fibonacci Heaps: Delete Min


6elete min.

6elete min and concatenate its children into root list. onsolidate trees so that no t!o roots ha7e same de"ree.

&

'

min
&, %

current
)/ *& ,)

&+

,+

)%

'(

'.

,,

'*

&'

Mer"e % and &, trees.


18

Fibonacci Heaps: Delete Min


6elete min.

6elete min and concatenate its children into root list. onsolidate trees so that no t!o roots ha7e same de"ree.

&

'

min
%

current
)/ *& ,)

&,

)%

'(

'.

,,

&+ '*

,+

&'

19

Fibonacci Heaps: Delete Min


6elete min.

6elete min and concatenate its children into root list. onsolidate trees so that no t!o roots ha7e same de"ree.

&

'

min
%

current
)/ *& ,)

&,

)%

'(

'.

,,

&+ '*

,+

&'

20

Fibonacci Heaps: Delete Min


6elete min.

6elete min and concatenate its children into root list. onsolidate trees so that no t!o roots ha7e same de"ree.

&

'

min
% )/

current
*& ,)

&,

)%

'(

'.

,,

&+ '*

,+

&'

21

Fibonacci Heaps: Delete Min


6elete min.

6elete min and concatenate its children into root list. onsolidate trees so that no t!o roots ha7e same de"ree.

&

'

min
% )/ *&

current
,)

&,

)%

'(

'.

,,

&+ '*

,+

&'

Mer"e ,) and )/ trees.


22

Fibonacci Heaps: Delete Min


6elete min.

6elete min and concatenate its children into root list. onsolidate trees so that no t!o roots ha7e same de"ree.

&

'

min
% *&

current
)/

&,

)%

'(

,)

'.

&+ '*

,+

&'

,,

23

Fibonacci Heaps: Delete Min


6elete min.

6elete min and concatenate its children into root list. onsolidate trees so that no t!o roots ha7e same de"ree.

&

'

min
% *&

current
)/

&,

)%

'(

,)

'.

&+ '*

,+

&'

,,

24

Fibonacci Heaps: Delete Min


6elete min.

6elete min and concatenate its children into root list. onsolidate trees so that no t!o roots ha7e same de"ree.

min
% *& )/

&,

)%

'(

,)

'.

&+ '*

,+

&'

,,

Stop.
25

Fibonacci Heaps: Delete


6elete node x.

6elete min element in heap.

#morti2ed cost. 1(6(n))

1()) for decrease-key. 1(6(n)) for delete-min. 6(n) = max de"ree of any node in Fibonacci heap.

26

8ime complexity 9inomial -eap Fibonacci -eap reation 1()) 1()) Findmin 1()) 1()) Insertion 1(lo"N) 1()) mer"e 1(lo"N) 1()) 6eleteMin 1(lo"N) 1(lo"N) 6ecrease-:ey 1(lo"N) 1()) 6elete 1(lo"N) 1(lo"N)

27

S-ar putea să vă placă și