in Algorithms retagged by
1,267 views
2 votes
2 votes
what will be the change in time when quick sort is used over the heap sort  to sort the edges in order to find the MST using kruskal algorithm...no of edges = 16
in Algorithms retagged by
by
1.3k views

1 Answer

5 votes
5 votes
Best answer

If we consider strictly Kruskal's algorithm , then we require sorting of edges and if we consider the worst case,

Quicksort will give = O(E2) [Considering the worst case of quicksort and the fact that we need sorting of edges in Kruskal's algo]

Heapsort will give = O(ElogE)

Substituting E = 16 we have ,

using quicksort we have : 16= 256

and using heapsort =       16 log 16 = 64

Hence change in time = 256 - 64 = 192 time units

selected by

4 Comments

I am thinking why we are taking worst case TC of quick sort??

how it is O(E^2) can u plz explain

here we don't know how array will be divided by pivot and we know that TC of quick sort depends on partition of the array by pivot

TC of kruskal is O(ElogE) or O(ElogV)
0
0

Since in the question it is mentioned we use quicksort instead of heapsort so it is O(E2) since sort according to edge weights in kruskals ALGO first then we construct mst

0
0
@cse

since we dont know about the piovt position,,,better to go for worst case
1
1
edited by
ok..thanks:)
2
2

Related questions