retagged by
17,461 views
37 votes
37 votes
Complexity of Kruskal’s algorithm for finding the minimum spanning tree of an undirected graph containing $n$ vertices and $m$ edges if the edges are sorted is _______
retagged by

10 Answers

0 votes
0 votes
IF EDGES ARE ALREADY SORTED, THEN IN WORST CASE WE HAVE TO TRAVERSE THE WHOLE EDGES TO GET MINIMUM SPANNING TREE. M EDGES WILL BE TRAVERSED AND WE HAVE TO DO UNION OPERATION WHICH TAKE O(LOGN) TIME, SO COMPLEXITY WILL BE Mlog(n).
0 votes
0 votes

Since the edges are sorted, we simply need to visit the vertex, and select an edge.

Now, Selecting an edge means, check if the edge creates a cycle or not and if not then insert. It does not consume a lot of time, we can assume it to be an O(1) operation.

So we need to visit all the vertices: O(n)

And we need to perform Select operation for m edges: O(m) (worst case).

So overall time complexity is O(m+n).

0 votes
0 votes

The Time complexity of Kruskal’s Algorithm is:

$O(E \cdot logE + E \cdot \alpha)$

Where the term:

$E \cdot logE$ $=>$ Time required for sorting the edges

$E \cdot \alpha$ $=>$ Time required to find the cycle (which is equal to $\alpha$) for each Edge $E$.

Interestingly there are two ways to find a cycle in a graph, which takes time as:

  1. DFS: where $\alpha = O(V+E)$
  2. Union-Find Structure: where $\alpha = O(1)$

Generally, since Union-Find Structure (its not there in GATE syllabus till now) outperforms DFS in this case, we use the same for detecting cycle in minimum time.

Therefore, our total time complexity becomes: $O(E \cdot logE + E)$

Now, it was given in the question that edges are already sorted.

Hence Time complexity will be: $O(E)$

Related questions

10 votes
10 votes
1 answer
1
Kathleen asked Sep 12, 2014
5,517 views
Maximum number of edges in a planar graph with $n$ vertices is _____
7 votes
7 votes
3 answers
2
Kathleen asked Sep 12, 2014
1,567 views
Macro expansion is done in pass one instead of pass two in a two pass macro assembler because _________
11 votes
11 votes
1 answer
3
Kathleen asked Sep 12, 2014
3,162 views
A simple and reliable data transfer can be accomplished by using the 'handshake protocol'. It accomplishes reliable data transfer because for every data item sent by the ...
7 votes
7 votes
4 answers
4
Kathleen asked Sep 12, 2014
3,099 views
Many of the advanced microprocessors prefetch instructions and store it in an instruction buffer to speed up processing. This speed up is achieved because ________