I have to use the MST algorithm(Prim or Kruskal) in a program I'm developing. I would be very grateful if someone could show me how to implement this algorithm.
I have to use the MST algorithm(Prim or Kruskal) in a program I'm developing. I would be very grateful if someone could show me how to implement this algorithm.
Code:Kruskal's algorithm: sort the edges of G in increasing order by length keep a subgraph S of G, initially empty for each edge e in sorted order if the endpoints of e are disconnected in S add e to S return S-PreludeCode:Prim's algorithm: let T be a single vertex x while (T has fewer than n vertices) find the smallest edge connecting T to G-T add it to T
My best code is written with the delete key.