This algorithm was created by Joseph Kruskal and made its appearance in the 1956 proceedings of the American Mathematical Society. This algorithm can be best described and explained in three simple steps.
If you have a graph with n nodes and also the weight of each edge then:
- The first step is the selection of the arc which consists of the least weight of the graph, and add to the tree, by deleting it from the graph.
- Now out of the remaining, the edge with the least weight is selected but such that it is not from the cycle. Now the edge needs to be added in the tree and deleted from graph.
- The third step involves you repeating the second step.
Here the algorithm continues selecting the edge on every cycle, starting from the least weighted edge only.
Hence, in this algorithm the graph does not need to be connected.
Czech mathematician Vojtěch Jarník invented this algorithm in 1930 and later in 1957, it was developed further by Robert C. Prim who was a computer scientist. It was then rediscovered in 1959 by Edsger Dijkstra.
This algorithm can also be best understood in the following three steps:
In reference to a connected graph with n nodes and a given weight of every edge,
- The first step is to select any node right from the graph and add it in the tree which is to be the first node.
- Now select an edge with the minimum weight and which is also connected to the tree. The edge and the node need to be added at the other end of the tree after which remove the edge from the graph.
- You now need to repeat the second step till the time n-1 edges get added to the tree.
In this, the tree begins from a single node and then expands onwards on every cycle. Therefore, for the proper working of the algorithm it is vital that the graph is connected.