I am revising for a test and came across two questions relating to minimal spanning trees in graphs that I am unsure of and want to test my answers against.
The first one asks: if a graph has multiple minimal spanning trees, will Kruskal and Prim’s minimal spanning tree algorithms generate the same tree? I am thinking that they won’t necessarily because the algorithms are different. Kruskal relies on the edges being sorted by weight, whilst Prim doesn’t, so they could start at different vertices, thus generating different trees.
The second question asks: if a graph has multiple minimal spanning trees, how should Kruskal’s algorithm be adapted to generate all of these? I am thinking that one needs to allow for either a looping structure through the vertices so that the start vertex changes each time because the edges values may be the same. Thus generate trees by taking each of the vertices in turn as start vertex. In other words, sort by vertex numbering as well, not by edge weight alone.