0% found this document useful (0 votes)
11 views

DAA Case Study

Uploaded by

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

DAA Case Study

Uploaded by

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

C.V.

RAMAN GLOBAL
UNIVERSITY
BHUBANESWAR, ODISHA

Case Study on :
STRUCTURE OF A FIBONACCI HEAP AND
MERGEABLE OPERATIONS
GUIDED BY:
Dr Supriya Panigrahy
Dept. of Computer Science and
Engineering
Submitted by:
2301020203 YASH SHARMA
2301020219 ADITYA KUMAR SAHOO
2301020226 ANUSHKA MAHARANA
2301020228 ARPEET BARIK
2301020230 ASHUTOSH NAYAK
2301020231 AYUSH ACHARYA
2301020247 ISTA RANJAN BARAL
2301020295 SUBRAT KUMAR BEHERA
2301020309 AKANKSHYA PRADHAN
2301020320 SRILIP SAHOO
INTRODUCTION
A Fibonacci heap is a data structure used for
implementing priority queues. It is a type of heap data
structure, but with several improvements over the
traditional binary heap and binomial heap data
structures. The key advantage of a Fibonacci heap over
other heap data structures is its fast amortized running
time for operations such as insert, merge and extract-
min, making it one of the most efficient data structures
for these operations. The running time of these
operations in a Fibonacci heap is for insert, for extract-
min and amortized for merge. A Fibonacci heap is a
collection of trees, where each tree is a heap-ordered
multi-tree, meaning that each tree has a single root
node with its children arranged in a heap-ordered
manner. The trees in a Fibonacci heap are organized in
such a way that the root node with the smallest key is
always at the front of the list of trees. In a Fibonacci
heap, when a new element is inserted, it is added as a
singleton tree. When two heaps are merged, the root
list of one heap is simply appended to the root list of
the other heap. When the extract-min operation is
performed, the tree with the minimum root node is
removed from the root list and its children are added to
the root list. One unique feature of a Fibonacci heap is
the use of lazy consolidation, which is a technique for
improving the efficiency of the merge operation. In lazy
consolidation, the merging of trees is postponed until it
is necessary, rather than performed immediately. This
allows for the merging of trees to be performed more
efficiently in batches, rather than one at a time. A
Fibonacci heap is a highly efficient data structure for
implementing priority queues, with fast amortized
running times for operations such as insert, merge and
extract-min. Its use of lazy consolidation and its multi-
tree structure make it a superior alternative to
traditional binary and binomial heaps in many
applications.

Components And Properties


1. It is a set of min heap-ordered trees. (i.e. The parent is
always smaller than the children.)
2. A pointer is maintained at the minimum element node.
3. It consists of a set of marked nodes. (Decrease key
operation)
4. The trees within a Fibonacci heap are unordered
but rooted

 Min-heap property: The key of a node is greater than


or equal to the key of its parent. This ensures that the
minimum key is always at the root of one of the trees.
 Root list: A linked list that connects the roots of the
rooted trees.
 Min pointer: Keeps track of the minimum element so it
can be retrieved in constant time.
 Child list: A doubly linked list that maintains the
elements in each level. This allows for constant-time
insertion and deletion in any position in the list.
 Node pointers: Each node has pointers to its parent,
left node, right node, and child.
 Node variables: Each node has variables that record
the node's degree, key, and marking.

Memory Representation Of
Fibonacci Heap
 Key: the value of the node.
 Degree: the number of children the node has.
 Parent: a pointer to the parent node.
 Child: a pointer to the first child node.
 Left: a pointer to the node to the left of the current
node in the doubly linked list.
 Right: a pointer to the node to the right of the current
node in the doubly linked list.

The nodes in a Fibonacci heap are organized as a


collection of trees, with each tree having a root node
that is linked in a circular doubly linked list with the
other roots there are two main advantages of using a
circular doubly linked list.
FIBONACCI HEAP OPERATIONS

Insert(x):
 Inserts node x into the heap
 Time complexity: O(1)
Find-min():
 Returns the node with the smallest key
 Time complexity: O(1)
Union(H1, H2):
 Merges two heaps, let’s say H1 and H2
 Time complexity: O(1)
Extract-min():
 Removes and returns the minimum node
 Time complexity: O(log n)
Decrease-key(x, k):
 Decreases the key of node x to k
 Time complexity: O(1)
Delete(x):
 Removes node x from the heap
 Time complexity: O(log n)

INSERTION
ALGORITHMS
1. insert(H, x)
2. degree[x] = 0
3. p[x] = NIL
4. child[x] = NIL
5. left[x] = x
6. right[x] = x
7. mark[x] = FALSE
8. Concatenate the root list containing x with root list H
9. if min[H] == NIL or key[x] < key[min[H]]
then min[H] = x
10.n[H] = n[H] + 1
 Inserting a node into an already existing heap follows the steps
below.
 Create a new node for the element.
 Check if the heap is empty.
 If the heap is empty, set the new node as a root node and mark
it min.
 Else, insert the node into the root list and update min.

Union

Union of two Fibonacci heaps consists of following


steps:
1.Concatenate the roots of both the heaps.
2.Update min by selecting a minimum key from the
new root lists.
Extract Min
It is the most important operation on a fibonacci heap. In
this operation, the node with minimum value is removed
from the heap and the tree is re-adjusted.
The following steps are followed:
1.Delete the min node.
2.Set the min-pointer to the next root in the root list.
3.Create an array of size equal to the maximum
degree of the trees in the heap before deletion.
4.Do the following (steps 5-7) until there are no
multiple roots with the same degree.
5.Map the degree of current root (min-pointer) to the
degree in the array.
6.Map the degree of next root to the degree in array.
7.If there are more than two mappings for the same
degree, then apply union operation to those roots
such that the min-heap property is maintained (i.e.
the minimum is at the root).

An implementation of the above steps can be understood in


the example below.
1. We will perform an extract-min operation on the heap
below.
2. Delete the min node, add all its child nodes to the root
list and set the min-pointer to the next root in the root
list.

3. The maximum degree in the tree is 3. Create an array


of size 4 and map degree of the next roots with the
array.
4. Here, 23 and 7 have the same degrees, so unite them.

5.Again, 7 and 17 have the same degrees, so unite them


as well.
6.Again 7 and 24 have the same degree, so unite them.

7.Map the next nodes.


8.Again, 52 and 21 have the same degree, so unite them.

9.Similarly, unite 21 and 18.


10. Map the remaining root.

11.The final heap is


DELETION
This process makes use of decrease-key and extract-min
operations. The following steps are followed :
1.Let k be the node to be deleted.
2.Apply decrease-key operation to decrease the
value of k to the lowest possible value (i.e. -∞).
3.Apply extract-min operation to remove this
node.
SOURCE CODE
OUTPUT
ADVANTAGES
Advantages of Fibonacci Heap are as follows :
1. Fast amortized running time: The running time of
operations such as insert, extract-min and merge in a
Fibonacci heap is O(1) for insert, O(log n) for extract-
min and O(1) amortized for merge, making it one of the
most efficient data structures for these operations.
2. Lazy consolidation: The use of lazy consolidation allows
for the merging of trees to be performed more
efficiently in batches, rather than one at a time,
improving the efficiency of the merge operation.
3. Efficient memory usage: Fibonacci heaps have a
relatively small constant factor compared to other data
structures, making them a more memory-efficient
choice in some applications.

Disadvantages of Fibonacci Heap


1. Increased complexity: The structure and operations of a
Fibonacci heap are more complex than those of a
binary or binomial heap, making it a less intuitive data
structure for some users.
2. Less well-known: Compared to other data structures,
Fibonacci heaps are less well-known and widely used,
making it more difficult to find resources and support
for implementation and optimization.
CONCLUSION
Fibonacci heaps provide a highly efficient data structure
for priority queue operations, particularly when used in
algorithms where frequent merging, insertion, and
decrease-key operations are needed, such as Dijkstra's
shortest path algorithm and Prim's minimum spanning
tree algorithm. With their unique structure of heap-
ordered trees and amortized constant-time complexity
for most operations, Fibonacci heaps offer significant
performance benefits over traditional heaps in complex
applications.
As a mergeable heap, the Fibonacci heap stands out for
its ability to efficiently merge two heaps in constant
time, an operation that is costly in other heap types like
binary heaps. This efficient merging capability, along
with other operations like insertions and decrease-key in
constant amortized time, makes Fibonacci heaps a
powerful choice for handling large datasets in
competitive and high-performance computing contexts.
Research paper
 Fredman, Michael L., and Robert Endre Tarjan.
"Fibonacci heaps and their uses in improved
optimization algorithms." Journal of the ACM
(JACM) 34.3 (1987): 596-615.

 Ding, Y., & Weiss, M. A. (1993). The relaxed min-max


heap: a mergeable double-ended priority queue.
Acta Informatica, 30, 215 231.

 Gambosi, G., Nardelli, E., & Talamo, M. (1989, July).


A pointer-free data structure for merging heaps and
min-max heaps. In International Colloquium on
Automata, Languages, and Programming (pp. 405-
422). Berlin, Heidelberg: Springer Berlin Heidelberg.

 Schoenmakers, L. A. M. (1992). Data structures and


amortized complexity in a functional setting.

 Bardiovský, V. (2012). Implementation of operations


in double ended heaps.
THANK YOU

You might also like