retagged by
322 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

323
views
1 answers
0 votes
528
views
1 answers
0 votes
Rohan Mundhey asked Nov 9, 2016
528 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?
212
views
1 answers
1 votes
admin asked Jan 6
212 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 ... sorted linear linked list can be done in $\mathrm{O}(\log n)$ time.
518
views
1 answers
0 votes
rsansiya111 asked Sep 10, 2022
518 views
Let A be a sorted array of distinct integers of length n. Design an algorithm to find an index i such that A[i] = i if such ... fastest algorithm for this problem, assuming the array is already available, is Θ ______________________________