Fibonacci Heap - PowerPoint PPT Presentation

1 / 25
About This Presentation
Title:

Fibonacci Heap

Description:

Like a binomial heap, a Fibonacci heap is a collection of min-heap-ordered trees. The trees in a Fibonacci heap are not constrained to be binomial trees. – PowerPoint PPT presentation

Number of Views:719
Avg rating:3.0/5.0
Slides: 26
Provided by: csw78
Category:

less

Transcript and Presenter's Notes

Title: Fibonacci Heap


1
Fibonacci Heap
  • BHFH

2
Why BHFH -- ????
MaxPQ
MinPQ
Symmetric Max Data Structures
DEPQ
Min Heap
Deap
MinMax
Mergeable MinPQ
Min-Leftist
Min-Skew
Min-B-Heap
Min-F-Heap
Inheritance
ADT
????
3
Why BHFH -- ??
  • Server for one priority shuts down?
  • Efficient algorithms for Shortest-path problem
    and finding minimum spanning trees?(Improved
    network optimization)

4
Whats BHFH -- Definition
  • A binomial heap is a collection of binomial
    trees.
  • The binomial tree Bk is an ordered tree defined
    recursively. the binomial tree B0 consists of a
    single node. The binomial tree Bk consists of two
    binomial trees Bk-1 that are linked together the
    root of one is the leftmost child of the root
  • of the other.
  • Like a binomial heap, a Fibonacci heap is a
    collection of min-heap-ordered trees. The trees
    in a Fibonacci heap are not constrained to be
    binomial trees.

5
BH ??
6
FH??
7
?????
  • MakeHeap()
  • Insert(H,x)
  • Minimum(H)
  • Extract-min(H)
  • Union(H1,H2)
  • DecreaceKey(H,x,k)
  • Delete(H,x)
  • ????

Binary Min-Heap
Binomial Heap
Fibonacci Heap
8
How Fibonacci Insert
  • FIB-HEAP-INSERT(H, x)
  • 1 degreex ? 0
  • 2 px ? NIL
  • 3 childx ? NIL
  • 4 leftx ? x
  • 5 rightx ? x
  • 6 markx ? FALSE
  • 7 concatenate the root list containing x with
    root list H
  • 8 if minH NIL or keyx lt keyminH
  • 9 then minH ? x
  • 10 nH ? nH 1

9
Fibonacci Insert 21
10
How Fibonacci Union
  • FIB-HEAP-UNION(H1, H2)
  • 1 H ? MAKE-FIB-HEAP()
  • 2 minH ? minH1
  • 3 concatenate the root list of H2 with the root
    list of H
  • 4 if (minH1 NIL) or (minH2 ? NIL and
    minH2 lt minH1)
  • 5 then minH ? minH2
  • 6 nH ? nH1 nH2
  • 7 free the objects H1 and H2
  • 8 return H

11
How Fibonacci Extract-min
  • FIB-HEAP-EXTRACT-MIN(H)
  • 1 z ? minH
  • 2 if z ? NIL
  • 3 then for each child x of z
  • 4 do add x to the root list of H
  • 5 px ? NIL
  • 6 remove z from the root list of H
  • 7 if z rightz
  • 8 then minH ? NIL
  • 9 else minH ? rightz
  • 10 CONSOLIDATE(H)
  • 11 nH ? nH - 1
  • 12 return z

12
Extract-min 1
13
Extract-min 2
14
Extract-min 3
15
Extract-min Final
16
How Fibonacci Consolidate
  • CONSOLIDATE(H)
  • 1 for i ? 0 to D(nH)
  • 2 do Ai ? NIL
  • 3 for each node w in the root list of H
  • 4 do x ? w
  • 5 d ? degreex
  • 6 while Ad ? NIL
  • 7 do y ? Ad ? Another node with the
    same degree as x.
  • 8 if keyx gt keyy
  • 9 then exchange x ? y
  • 10 FIB-HEAP-LINK(H, y, x)
  • 11 Ad ? NIL
  • 12 d ? d 1
  • 13 Ad ? x
  • 14 minH ? NIL
  • 15 for i ? 0 to D(nH)
  • 16 do if Ai ? NIL
  • 17 then add Ai to the root list of H
  • 18 if minH NIL or
    keyAi lt keyminH

17
How Fibonacci Decrease-Key
  • FIB-HEAP-DECREASE-KEY(H, x, k)
  • 1 if k gt keyx
  • 2 then error "new key is greater than current
    key"
  • 3 keyx ? k
  • 4 y ? px
  • 5 if y ? NIL and keyx lt keyy
  • 6 then CUT(H, x, y)
  • 7 CASCADING-CUT(H, y)
  • 8 if keyx lt keyminH
  • 9 then minH ? x
  • CUT(H, x, y)
  • 1 remove x from the child list of y, decrementing
    degreey
  • 2 add x to the root list of H
  • 3 px ? NIL
  • 4 markx ? FALSE
  • CASCADING-CUT(H, y)
  • 1 z ? py
  • 2 if z ? NIL
  • 3 then if marky FALSE

18
Fibonacci Decrease-Key
19
How Fibonacci Delete
  • FIB-HEAP-DELETE(H, x)
  • 1 FIB-HEAP-DECREASE-KEY(H, x, -8)
  • 2 FIB-HEAP-EXTRACT-MIN(H)

20
How Binomial Delete
  • BINOMIAL-HEAP-DELETE(H, x)
  • 1 BINOMIAL-HEAP-DECREASE-KEY(H, x, -8)
  • 2 BINOMIAL-HEAP-EXTRACT-MIN(H)

21
Note -- Time Complexity
22
Note -- Difference
  • 1 Delete
  • DecreaseKey
  • 2 BinomialOrdered
  • FibonacciUnordered

23
Note -- Application
  • Shortest-path
  • Combine PQ

24
Fibonacci Heap
  • ??

25
  • 1.???????Fibonacci Heap,?
  • insert??????key???
  • 70?80?90?30?40?50?20?60
  • (hint insert?????????)
  • 2.extractMin
  • 3.?80?key,Decrease Key?10
  • 4.??Fibonacci Heap??,????Union
Write a Comment
User Comments (0)
About PowerShow.com