in Interview Questions
526 views
1 vote
1 vote
#IITD_2011 which is better merge sort or heap. sort ?
in Interview Questions
526 views

3 Answers

2 votes
2 votes
if you have extra space you can go for merge sort. else you should have to remain happy with the heap sort . intuitively if you see, if an array is sorted  we are  to swap/assign a lot in merge sort but that's not the case in heap sort.you call heapify(A,i) you are not going to swap once also .

 

so better go for heap sort.....

1 comment

Too much space
0
0
1 vote
1 vote
MergerSort is better because for larger datasets, mergesort works faster and is stable. Also it can be parallelized. As for Heapsort , sorting is not stable also there is a overhead of maintaining heap.
by
0 votes
0 votes

Merge sort is better

Reason- it always have same complexity irrespective of input , so easier to analyse. While that is not the case in heap sort.

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true