retagged by
1,818 views
5 votes
5 votes

Complexity of Kruskal's algorithm for finding minimum spanning tree of an undirected graph containing $n$ vertices and $m$ edges if the edges are sorted is:

  1. $O(mn)$
  2. $O(m)$
  3. $O(m+n)$
  4. $O(n)$
retagged by

2 Answers

5 votes
5 votes

Option B O(m)

Implementation of Kruskal's algorithm should be implemented in 2 steps:
Step1: Sorting of edges takes $O(E*log(E))$ time.
Step2: After sorting, we iterate through all edges and apply find union algorithm.

The find and union operations can take at most $O(1)$ time if you use Disjoint set. So overall complexity is$ O(Elog(E) + E)$ time.
Given the edges are already sorted, so we need to do only second step i.e.,we iterate through all edges and apply find-union algorithm. The find and union operations can take at most $O(1)$ time. So, the total time complexity will be $O(E)$.

https://www.youtube.com/watch?v=fAuF0EuZVCk

0 votes
0 votes
O(m) is the answer , as the edges are already sorted we donot need to sort them , therefore union operation takes O(E) time , where E is the no. of edges  .
Answer:

Related questions

0 votes
0 votes
1 answer
1
admin asked Mar 31, 2020
1,855 views
What is the type of the algorithm used in solving the $4$ Queens problem?GreedyBranch and BoundDynamicBacktracking
1 votes
1 votes
4 answers
2
admin asked Mar 31, 2020
4,396 views
Selection sort, quick sort is a stable sorting methodTrue,TrueFalse,FalseTrue,FalseFalse,True
3 votes
3 votes
2 answers
3
admin asked Mar 31, 2020
3,920 views
Which of the following sorting procedures is the slowest?Quick SortMerge SortShell SortBubble Sort
1 votes
1 votes
4 answers
4