UCS 732 PPT On Binomial Fibonacci Heaps PDF
UCS 732 PPT On Binomial Fibonacci Heaps PDF
Deliverables
Copyright @ gdeepak.Com
Binomial Heaps
Binomial Heap is collection of Binomial trees.
Binomial tree is defined recursively.
Binomial tree of order 0 is a single node.
Binomial tree of order 1 has a root node and a binomial tree of order 0 as its
children
Binomial tree of order 2 has a root node and roots of binomial trees of 0 and
1 as its children
Binomial tree of order k has a root node whose children are roots of
binomial trees of orders k1, k2, ..., 2, 1, 0
It uses a special tree structure to support quick merging of two heaps.
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
Copyright @ gdeepak.Com
Copyright @ gdeepak.Com
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
10
10
parent
key
degree
chil
d
10
10
10
10
10
10
sibling
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
Copyright @ gdeepak.Com
10
Copyright @ gdeepak.Com
11
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
12
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
13
Insert
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
14
Find Min
To find the minimum element of the heap, find minimum
among the roots of the binomial trees. This can be done
in O(log n) time, as there are just O(log n) trees and hence roots
to examine.
By using a pointer to the binomial tree that contains the
minimum element, the time for this operation can be reduced
to O(1). The pointer must be updated when performing any
operation other than Find minimum. This can be done
in O(log n) without raising the running time of any operation.
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
15
Delete Min
To delete the minimum element from the heap, first
find this element, remove it from its binomial tree, and
obtain a list of its subtrees.
Then transform this list of subtrees into a separate
binomial heap by reordering them from smallest to
largest order.
Then merge this heap with the original heap. Since
each tree has at most log n children, creating this new
heap is O(log n). Merging heaps is O(log n), so the
entire delete minimum operation is O(log n)
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
16
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
17
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
18
Decrease Key
Decreasing the key of an element may make it smaller
than the key of its parent, violating the minimum-heap
property.
In this case, exchange the element with its parent, and
possibly also with its grandparent, and so on, until the
minimum-heap property is no longer violated.
Each binomial tree has height at most log n, so this
takes O(log n) time.
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
19
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
20
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
21
Delete
To delete an element from the heap, decrease its key to
negative infinity (that is, some value lower than any
element in the heap) and then delete the minimum in the
heap.
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
22
Fibonacci Heaps
It is a collection of trees satisfying the minimum-heap property. This
implies that the minimum key is always at the root of one of the trees.
Copyright @ gdeepak.Com
23
Node Representation
Each node x in a Fibonacci heap contains:
Copyright @ gdeepak.Com
24
Fibonacci Heap
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
25
Fibonacci Heaps
Represent trees using left child, right sibling pointers
and circular doubly linked list that helps in quickly
splicing off sub trees
Roots of trees connected with circular doubly linked
list help in fast union
Pointer to root of tree with min element helps in fast
find min
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
26
Key quantities
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
27
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
28
Insert
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
29
Insert 21
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
30
Union
Concatenate two Fibonacci Heaps
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
31
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
32
Delete Min
Delete Min and concatenate its children into root list
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
33
Delete Min
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
34
Delete Min
Consolidate trees so that no two trees have same degree
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
35
Delete Min
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
36
Delete Min
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
37
Delete Min
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
38
Delete Min
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
39
Delete Min
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
40
Delete Min
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
41
Delete Min
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
42
Delete Min
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
43
Delete Min
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
44
Delete Min
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
45
Delete Min
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
46
Copyright @ gdeepak.Com
47
Decrease Key
Case 1: Min Heap Property is not violated
Decrease key x to K
Change heap min pointer if necessary
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
48
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
49
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
50
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
51
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
52
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
53
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
54
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
55
Marked Nodes
A node is marked if at least one of its children was cut since
this node was made a child of another node (all roots are
unmarked).
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
56
Copyright @ gdeepak.Com
57
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
58
Question 1
Using Fibonacci heaps for ______ improves the asymptotic
running time of important algorithms.
A)
B)
C)
D)
Priority Queues
Stacks
Link Lists
Binary Search Trees
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
59
Question 2
Binomial heap is a heap similar to a ______ but also supports
quickly merging two heaps
A) Fibonacci Heap
B) Binary Heap
C) Max Heap
D) Min Heap
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
60
Question 3
Show an valid Binomial Heap with the following nodes 3,
5, 7, 10, 12, 15.
3/2/2015 8:54 PM
Copyright @ gdeepak.Com
61