If we arrange array in ascending order, then we'll get Binary Heap. Is there any drawback of this advantage. If yes then what will be the reason of that?
Asked
Active
Viewed 33 times
0
-
The drawback is that sorting the array will take longer than using the traditional BuildHeap method. – Jim Mischel Dec 30 '16 at 17:12
1 Answers
0
"Arranging array in ascending order, then we'll get Binary Heap". This is correct.
Now it depends upon which algorithm you use to sort the array in ascending order. Best Sorting Algorithm perform with complexity O(NLogN)
.
While the algorithm Build_Heap
to just create a binary heap has complexity of O(N)
.
Unless and until you use non-comparison based sorting method like Counting Sort
your complexity for creating binary heap will be atleast O(NLogN)
and atmost O(N^2)
.
So traditional method of creating binary heap is favorable.
Although Counting Sort
will take O(N)
time but it will require extra space O(N)
, while traditional Build_Heap
will be create binary heap in-place.

sameerkn
- 2,209
- 1
- 12
- 13
-
You cannot do a comparison sort in O(N) time. Comparison sorting is O(N log N). Non-comparison methods (like radix sort) are potentially O(N), but require extra space. – Jim Mischel Dec 30 '16 at 17:09
-
@JimMischel: By-mistake wrote `Comparison` instead of `Counting`. Thanks for the correction. – sameerkn Jan 03 '17 at 06:15