algorithm,greedy,minimum-spanning-tree,kruskals-algorithm

What we do in Kruskal ? Firstly sort the edges according to their weight. Then we choose that edge which has minimal weight. We add that edge if it makes no cycle. Thus we go forward greedily. So it is greedy approach. :) The greedy approach is called greedy because,...

c++,algorithm,testing,big-o,kruskals-algorithm

To stress Kruskal's algorithm, you need a graph with as many redundant edges as possible, and at least one necessary edge that will be considered last (since Kruskal's algorithm sorts the edges by weight). Here's an example. The edges with weight 1 are necessary, and will be taken first. The...

algorithm,graph,kruskals-algorithm

You're not doing anything wrong. There's no guarantee that a MST preserves shortest distances between nodes. Eg: the three node complete graph ABC with edge weights 3, 2, 2 (with apologies for my ascii art): A --- 2 --- B | | 2 / | / C----3---/ The minimal spanning...