retagged by
288 views
1 votes
1 votes
array has n elements and we need to sort them in non decreasing order as follows. first find minimum, remove this element from the array and find minimum of remaining elements, remove this element  and so on until array becomes emplty . In best case how many comparisons needed
retagged by

1 Answer

0 votes
0 votes
This will be done by heap sort.

1.First we create a min heap using build heap method ......................O(n)

2.Then (remove min) +(min heapify)

.......................O(1) +O(log n)=O(logn)

After this we get first minimum as well as the remaining elements already forms a min heap... So no need to apply build heap again.

Instead second step will be repeated for all n elements until finally we get a sorted array.......n*O(logn)=O(nlogn)

Overall: O(n) + O(nlogn)=O(nlogn)

Related questions

0 votes
0 votes
1 answer
1
0 votes
0 votes
1 answer
2
Rohan Mundhey asked Nov 9, 2016
504 views
Consider an array contains n integers, each integer belongs to {-1, 0, 1}. What is the best case time complexity to sort an array?
1 votes
1 votes
1 answer
3
admin asked Jan 6
149 views
Which of the following is true for a sorted list with ' $n$ ' elements?Insertion in a sorted array takes constant time.Insertion in a sorted linear linked list takes cons...