What is the maximum and minimum number of edges to be considered in krushkal's algorithm with an example for both cases.
What I thought was since the Krushkal's algorithm is for finding minimum spanning tree the maximum number of edges is (V-1) where V is the number of vertices. Adding one more edge would result in a cycle in the graph. How can we obtain at a minimum value ?
A tree of N vertices always has N-1 edges. Consequently you have to consider at least N-1 edges during Kruskal's algorithm. An example may be a graph which is a tree.
Kruskal's algorithm stops when you've added V - 1
edges to your MST, so this is the minimum that have to be considered. This happens when the lowest value V - 1
edges of your graph do not form a cycle, and they will be added one after the other by the algorithm, after which it will stop.
For example, consider a complete graph with edges with cost 1
, which is minimum in the graph, between node 1
and every other node. Make all the other edges have cost 2
.
The worst case is when you must inspect every edge (of which there are O(V^2)
) until you finally select V - 1
. This means that you have to force a lot of cycles to be created before the last edge is added.
Consider a complete graph again. Have the V - 2
edges between node 1
and V - 2
nodes have cost 1, which is minimum in the graph. These will be selected first. Now let node k
be the one that is not part of a selected edge, so that is left out of the graph. Have the edge between node k
and node 1
have the largest cost. This will cause it to be inspected and added to the MST last, forcing the algorithm to inspect all O(V^2)
edges before building the MST.
Remember the Kruskal's algorithm processes edges in increasing order of their cost, rejecting edges that would form a cycle if added to the MST we are building.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.