Vous êtes sur la page 1sur 31

FibonacciHeaps

FibonacciHeaps
FibonacciBinary
insertO(1)O(log(n))
findO(1)N/A
unionO(1)N/A
minimumO(1)O(1)
decreasekeyO(1)O(log(n))
deleteO(log(n)O(log(n))
deleteminimumO(log(n))N/A

FibonacciHeaps
BinomialTree:
Abinomialtreeoforder0isasinglenode
Abinomialtreeoforderkhasarootofdegreekanditschildren
arerootsofbinomialtreesofordersk1,k2,...,2,1,0(inorder).
Abinomialtreeoforderkhas2knodes

FibonacciHeaps
DataStructures:
Circulardoublylinkedlistofsiblings()
Allnodeshavepointerstotheirparents
Onepointertoachild

FibonacciHeaps
Forestofbinomialtreeskeyofnodeislessthankeysofchildren

FibonacciHeaps
Forestofbinomialtreeskeyofnodeislessthankeysofchildren
Nodewithminimumkeyisarootofoneofthetrees

FibonacciHeaps
Forestofbinomialtreeskeyofnodeislessthankeysofchildren
Nodewithminimumkeyisarootofoneofthetrees
Anodemayhavedegreegreater2butnolargerthanO(log(n))

FibonacciHeaps
Forestofbinomialtreeskeyofnodeislessthankeysofchildren
Nodewithminimumkeyisarootofoneofthetrees
Anodemayhavedegreegreater2butnolargerthanO(log(n))
SizeofasubtreerootedinnodeofdegreekisFk+2whereFk
isthekthFibonaccinumber

FibonacciHeaps
Forestofbinomialtreeskeyofnodeislessthankeysofchildren
Nodewithminimumkeyisarootofoneofthetrees
Anodemayhavedegreegreater2butnolargerthanO(log(n))
SizeofasubtreerootedinnodeofdegreekisFk+2whereFk
isthekthFibonaccinumber

MinimumNode
6

2
5

1
3

FibonacciHeaps
MinimumNode
6

2
5

1
3

Operation:FindMinimum
SimplelookupusingMinNodepointerO(1)

FibonacciHeaps
MinimumNode
6

2
5

1
3

Operation:Unionoftwoheaps
Attachhighernumberednodetosmaller
Removeformerrootfromlinkedlist
AddformerroottochildrenlinkedlistO(1)

FibonacciHeaps
MinimumNode
6

2
5

1
3

Operation:Unionoftwoheaps
Attachhighernumberednodetosmaller
Removeformerrootfromlinkedlist
AddformerroottochildrenlinkedlistO(1)

FibonacciHeaps
MinimumNode
6

10

1
3

Operation:Insert
Addnewnodeasaheap
AttachtotherootlinkedlistO(1)

FibonacciHeaps
MinimumNode
6

2
5

1
3

Operation:DeleteMinimum

FibonacciHeaps
MinimumNode
6

2
5

Operation:DeleteMinimum
Removeminimumnodeandmakechildrenroots

FibonacciHeaps
MinimumNode
6

2
5

Operation:DeleteMinimum
Removeminimumnodeandmakechildrenroots
Unionrootsofsamedegreeuntilallrootshavedifferentdegree

FibonacciHeaps
MinimumNode
6

Operation:DeleteMinimum
Removeminimumnodeandmakechildrenroots
Unionrootsofsamedegreeuntilallrootshavedifferentdegree

FibonacciHeaps
MinimumNode
6

Operation:DeleteMinimum
Removeminimumnodeandmakechildrenroots
Unionrootsofsamedegreeuntilallrootshavedifferentdegree

FibonacciHeaps
MinimumNode
6

Operation:DeleteMinimum
Removeminimumnodeandmakechildrenroots
Unionrootsofsamedegreeuntilallrootshavedifferentdegree
ResetMinimumNodepointer

FibonacciHeaps
MinimumNode
6

2
5

1
3

Operation:DecreaseKey

FibonacciHeaps
MinimumNode
6

2
5

1
3

Operation:DecreaseKey
Markednodesarethosehavinghadexactlyonechildpromoted
toarootpreviously

FibonacciHeaps
MinimumNode
6

2
5

1
3

Operation:DecreaseKey
Decreasethekey
ifviolation,cutfromthetree,
promoteittoaroot
markitsparentifitisunmarked
iftheparenthadbeenmarkedcutitfromitstree,
andpromoteittoaroot,andunmarkit.

FibonacciHeaps
MinimumNode
6

2
5

1
3

Operation:DecreaseKey
Decreasethekey
ifviolation,cutfromthetree,
promoteittoaroot
markitsparentifitisunmarked
iftheparenthadbeenmarkedcutitfromitstree,
andpromoteittoaroot,andunmarkit.

FibonacciHeaps
MinimumNode
6

2
5

1
3

Operation:DecreaseKey
Decreasethekey
ifviolation,cutfromthetree,
promoteittoaroot
markitsparentifitisunmarked
iftheparenthadbeenmarkedcutitfromitstree,
andpromoteittoaroot,andunmarkit.O(1)!!!

FibonacciHeaps
MinimumNode
6

2
5

1
3

Operation:DecreaseKey
Decreasethekey
ChangetheMinimumNodepointer

FibonacciHeaps
MinimumNode
6

2
5

1
3

Operation:Delete
Keyofnodetobedeletedchangedtominusinfinity
(decreasekeyoperation)
Followedbysimpledeleteminimum

FibonacciHeaps
MinimumNode
6

2
5

1
3

Operation:Delete
Keyofnodetobedeletedchangedtominusinfinity
(decreasekeyoperation)
Followedbysimpledeleteminimum

FibonacciHeaps
MinimumNode

1
3

Operation:Delete
Keyofnodetobedeletedchangedtominusinfinity
(decreasekeyoperation)
Followedbysimpledeleteminimum

FibonacciHeaps
MinimumNode
2
6

1
3

Operation:Delete
Keyofnodetobedeletedchangedtominusinfinity
(decreasekeyoperation)
Followedbysimpledeleteminimum

FibonacciHeaps
MinimumNode
2
6

1
3

Operation:Delete
Keyofnodetobedeletedchangedtominusinfinity
(decreasekeyoperation)
FollowedbysimpledeleteminimumO(log(n))

FibonacciHeaps
Result:
Complexityofalgorithmsusingpriorityqueuesisreduced!
Example:ShortestPathO((m+n)log(n))withbinaryheap
O(m+nlog(n))withFibonacciheap

Vous aimerez peut-être aussi