0% found this document useful (0 votes)
35 views37 pages

Fibonacci Heaps 1

Fibonacci Heaps 1 pdf

Uploaded by

piyush sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views37 pages

Fibonacci Heaps 1

Fibonacci Heaps 1 pdf

Uploaded by

piyush sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 37

Fibonacci Heaps

Fibonacci Heaps
• 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.
• Unlike trees within binomial heaps, which are ordered, trees
within Fibonacci heaps are rooted but unordered.
Fibonacci Heaps
• each node x contains a pointer p[x] to its parent and a pointer
child[x] to any one of its children.
• The children of x are linked together in a circular, doubly
linked list, which we call the child list of x.
• Each child y in a child list has pointers left[y] and right[y] that
point to y’s left and right siblings, respectively.
Fibonacci Heaps
• If node y is an only child, then left[y] = right[y] = y.
• The order in which siblings appear in a child list is arbitrary.
• The number of children in the child list of node x is stored in
degree[x].
• The boolean-valued field mark[x] indicates whether node x
has lost a child since the last time x was made the child of
another node.
• Newly created nodes are unmarked, and a node x becomes
unmarked whenever it is made the child of another node.
• A given Fibonacci heap H is accessed by a pointer min[H] to
the root of a tree containing a minimum key; this node is
called the minimum node of the Fibonacci heap.
• If a Fibonacci heap H is empty, then min[H] = NIL.
• The roots of all the trees in a Fibonacci heap are linked
together using their left and right pointers into a circular,
doubly linked list called the root list of the Fibonacci heap.
Fibonacci Heaps: Structure of a node

• Each node x stores parent


– key[x]
– degree[x] (also rank(x))
– mark[x]
– p[x] key, degree 10 1 FALSE
mark
– child[x]
– left[x] left right
– right [x]
(4 pointers per node) child
Fibonacci Heaps: Example
Fibonacci Heaps: Advantage of Circular, doubly
linked list

• Circular, doubly linked lists have two dvantages for


use in Fibonacci heaps.
• First, we can remove a node from a circular, doubly
linked list in O(1) time.
• Second, given two such lists, we can concatenate
them (or “splice” them together) into one circular,
doubly linked list in O(1) time.
Properties and Potential Function
• Properties of FIB-HEAP H:
– Mark(x) = TRUE (marked, black in slide),
FALSE (yellow in slide)
– n[H] = number of nodes in H
– t(H) = number of trees in H
– m(H) = number of marked notes in H

Potential Function for Amortized Analysis


min[H]
(H) = t(H) + 2 m(H) .
7 24 23 17 3

n[H] = 14
30 26 46
t(H) = 5 18 52 41
m(H) = 3
35
H 39 44
Maximum Degree

• There is a upper bound D(n) on the maximum


degree of any node in an n-node Fibonacci
heap. D(n) ≤ lg n Why?
Reason
• Each Fibonacci heap is simply a collection of
“unordered” binomial trees. An unordered binomial
tree is like a binomial tree, and it, too, is defined
recursively. The unordered binomial tree U0 consists of a
single node, and an unordered binomial tree Uk consists
of two unordered binomial trees Uk−1 for which the root
of one is made into any child of the root of the other. For
the unordered binomial tree Uk , the root has degree k,
which is greater than that of any other node. The
children of the root are roots of subtrees U0,U1, . . . ,Uk−1
in some order. Thus, if an n-node Fibonacci heap is a
collection of unordered binomial trees, then D(n) = lg n.
Creating a new Fibonacci heap
Inserting a node
Inserting a node: Example
Insertion Analysis
Finding the minimum node

• The minimum node of a Fibonacci heap H is given by


the pointer min[H], so we can find the minimum
node in O(1) actual time.
• Because the potential of H does not change, the
amortized cost of this operation is equal to its O(1)
actual cost.
Uniting two Fibonacci heaps
Cost of Union
Extracting the minimum node
Extracting the minimum node
Consolidation
Linking Step

• FIB-HEAP-LINK (H, y, x)
Linking step x
y x
y

Assume x  y

FIB-HEAP-LINK (H, y, x) ⊳ Assume x  y


remove y from the root list of H
make y a child of x, incrementing degree[x]
mark[y]  FALSE

Constant time O(1)


Algorithm for Consolidation
Consolidation: Example
Consolidation: Example
Consolidation: Example
Consolidation: Example
Consolidation: Example
Consolidation: Example
Complexity Of Extract Min
Decreasing a key
Decreasing a key
Decreasing a key: Example

(a) The initial Fibonacci heap.

(a) The node with key 46 has its key decreased to 15. The node becomes a
root, and its parent (with key 24), which had previously been unmarked,
becomes marked.
Decreasing a key: Example

(b)The initial Fibonacci heap.


(c) The node with key 35 has its key decreased to 5.
Decreasing a key: Example
Deleting a node
Time Complexity of Decrease Key
Fibonacci Heaps (Summary)
• MINIMUM(H) O(1)
• UNION(H1, H2) O(1)
• INSERT(H, x) O(1)
• EXTRACT-MIN(H) O(lg n)*
• DECREASE-KEY (H, x, k) O(1)*
• DELETE (H, x) O(lg n)*

You might also like