Algorithm: Finding a MST of with edge-costs given by

Running time is where is number of vertices, edges respectively

  • while loop runs times
  • Inside each while loop we need to check of adding current edge creates a cycle time

Correctness of Kruskal’s algorithm

Assumption : All edge costs are distinct

Theorem

For any , let be the edge of minimum cost having one end-point in and other end-point in . Then, every MST contains the edge

  • Suppose Kruskal’s algorithm adds the edge at this step.
  • Let be set of all vertices to which had a path before this step.
  • Clearly
  • Before this step, by definition of , no edges from to have been added
  • Since and and Kruskal’s algorithm adds edges in increasing order of costs, it follows that is the cheapest edge with one end-point in and other end-point in .