Heap Sort
Heap Sort
Similarly, there is a concept of Max Heap and Min Heap. Like trees
and arrays, there is another organized Data Structure called Heap
Data Structure. It is a complete binary tree that follows the rule that
all the root nodes are larger(for Max Heap) or smaller (for Min Heap)
than their child nodes. This process is called Heapify
Advantages and Disadvantages of using Heap Sort in Data
Structure
Advantages: Optimized performance, efficiency, and accuracy are
a few of the best qualities of this algorithm. The algorithm is also
highly consistent with very low memory usage. No extra memory
space is required to work, unlike the Merge Sort or recursive
Quick Sort.
Disadvantages: Heap Sort is considered unstable, expensive, and
not very efficient when working with highly complex data.
You might have come across Dijkstra’s algorithm
that finds the shortest path where Heap Sort is
implemented. Heap Sort in Data Structure is used
when the smallest (shortest) or highest (longest)
value is needed instantly. Other usages include
finding the order in statistics, dealing with priority
queues in Prim’s algorithm (also called the
minimum spanning tree) and Huffman encoding or
data compression.
Similarly, various operating systems use this
algorithm for jobs and process management as it’s
based on the priority queue.
To every type of sorting or searching algorithm,
advantages and disadvantages are always there.
With Heap Sorting algorithms, there are very few
disadvantages. There is no additional requirement
of memory space.
The other factor is time. It is found that the time
complexity is calculated as nlog(n), but the actual
Heap Sort is lesser than O(nlog(n)). The reason is
that reduction or extraction from the Heap Sort
reduces the size and takes much less time as the
process goes on.
Hence, Heap Sorting is considered one of the ”best”
sorting algorithms because of various reasons in the
world of Data Structure.
On which algorithm is heap sort based on?
a) Fibonacci heap
b) Binary tree
c) Priority queue
d) FIFO
Answer: b
Explanation: To perform deletion operation in a heap, we require 2 arrays and that
occupies extra memory space and hence increase in running time.
What is the time taken to copy elements to and from two arrays created for
deletion?
a) O(N)
b) O(N log N)
c) O(log N)
d) O(N2)
Answer: a
Explanation: The time taken to copy elements to and from the main array and
extra array is found to be O(N).