What Determines the Running Time of Kruskal's Algorithm?

In summary: The time complexity does not depend on the weight of the edges since the sorting algorithm used can handle different ranges of integers without affecting the overall time complexity.
  • #1
evinda
Gold Member
MHB
3,836
0
Hello! (Wave)

The Kruskal's algorithm is the following:
Code:
MST-KRUSKAL(G,w)
1. A={}
2. for each vertex v∈ G.V
3.      MAKE-SET(v)
4. sort the edges of G.E into nondecreasing order by weight w
5. for each edge (u,v) ∈ G.E, taken in nondecreasing order by weight w
6.      if FIND-SET(u)!=FIND-SET(v)   
7.         A=A U {(u,v)}  
8.         Union(u,v)
9. return A
According to my textbook:Initializing the set [m]A[/m] in line 1 takes $O(1)$ time, and the time to sort the edges in line 4 is $O(E \lg E)$. The for loop of lines 5-8 performs $O(E)$ FIND-SET and UNION operations on the disjoint-set forest. Along with the $|V|$ MAKE-SET operations, these take a total of $O((V+E)\alpha(V))$ time, where $\alpha$ is a very slowly growing function. Because we assume that $G$ is connected, we have $|E| \geq |V|-1$, and so the disjoint-set operations take $O(E \alpha(V))$ time. Moreover, since $\alpha(V)=O(\lg V)=O(\lg E)$, the total running time of Kruskal's algorithm is $O(E \lg E)$. Observing that $|E|<|V|^2$, we have $\lg |E|=O(\lg V)$, and so we can restate the running time of Kruskal's algorithm as $O(E \lg V)$.Could you expain me why we deduce that the time to sort the edges in line 4 is $O(E \lg E)$?
Also how do we get that the total time complexity is $O((V+E)\alpha(V))$ ?
In addition, suppose that all edge weights in a graph are integers from $1$ to $|V|$. How fast can you make Kruskal's algorithm run? What if the edges weights are integers in the range from $1$ to $W$ for some constant $W$?How does the time complexity depend on the weight of the edges?
 
Technology news on Phys.org
  • #2
For the first question, the time to sort the edges in line 4 is $O(E \lg E)$ because the sorting algorithm is using a comparison sort, which has a time complexity of $O(n \log n)$. For the second question, the total time complexity is $O((V+E)\alpha(V))$ because the disjoint-set operations take $O(E \alpha(V))$ time, and the MAKE-SET operations take $O(V)$ time.For the third question, if all edge weights are integers from 1 to |V|, then Kruskal's algorithm can be implemented to run in linear time, $O(E + V)$, using counting sort. If the edge weights are integers in the range from 1 to W for some constant W, then Kruskal's algorithm can still be implemented to run in linear time, $O(E + V)$, using bucket sort.
 

FAQ: What Determines the Running Time of Kruskal's Algorithm?

What is the definition of "running time of algorithm"?

The running time of an algorithm refers to the amount of time it takes for the algorithm to complete its task or solve a problem.

How is the running time of an algorithm measured?

The running time of an algorithm is typically measured in terms of the number of operations or steps it takes to complete its task. This can be expressed as a function of the input size.

Why is it important to analyze the running time of an algorithm?

Analyzing the running time of an algorithm helps us understand how efficient it is in terms of time. This is important because it allows us to compare different algorithms and choose the most efficient one for a given task.

What factors can affect the running time of an algorithm?

The running time of an algorithm can be affected by various factors such as the input size, the type of data being processed, and the efficiency of the algorithm's implementation.

How can the running time of an algorithm be improved?

The running time of an algorithm can be improved by optimizing the algorithm's implementation, finding more efficient algorithms, or improving the input data to reduce the number of operations required.

Similar threads

Replies
1
Views
1K
Replies
1
Views
1K
Replies
11
Views
3K
Replies
4
Views
2K
Replies
1
Views
1K
Replies
2
Views
1K
Replies
2
Views
1K
Back
Top