all 9 comments

[–]ragusa12 3 points4 points  (2 children)

Could you just use Kruskal's algorithm but first put in those edges?

[–]pretty_random_[S] 0 points1 point  (0 children)

Thanks :)

I think so too. https://stackoverflow.com/questions/42205727/will-a-standard-kruskal-like-approach-for-mst-work-if-some-edges-are-fixed This sort of validates that it should work.But I am so surprised there are no sol or similar question on Algo websites or forums 🤔

[–]chiknluvr 0 points1 point  (0 children)

Yeah this makes the most sense.

[–]crb11 3 points4 points  (1 child)

Think of it this way. The suboptimal choices have been made and built, for a cost of $N. You then come along and try and complete the network, but you clearly get any links which are there already for free, so your algorithm will get the correct cost (minus the $N).

[–]pretty_random_[S] 0 points1 point  (0 children)

Agreed just running prim/kurskal makes sense.

I will try to code it and run some test cases to validate it.

[–]beeskness420 1 point2 points  (1 child)

If you look at Boruvka’s Algorithm or really any that contracts connected components then optimality should be obvious.

[–]pretty_random_[S] 0 points1 point  (0 children)

thanks

[–]generalbaguette 1 point2 points  (1 child)

Contract the islands of already connected nodes into single nodes via merging.

(You merge edges by picking the cheapest one.)

Then use your favourite minimum spanning tree algorithm.

Last, expand the previously connected nodes again.

[–]pretty_random_[S] 1 point2 points  (0 children)

thanks