Here is an excise:
Consider the problem of finding a minimum weight connected subset T of edges from a weighted connected graph G. The weight of T is the sum of all the edge weights in T.Give an efficient algorithm to compute the minimum weight connected subset T.
Here are what I have got:
I have to assume the weights are mixed by both positive and negative ones. Only the mix of both kinds of weights can make sense for this excise.
I will sort the edges first, so the negative edges will come first.
I will consider utilise Kruskal's algorithm, but should be with some modifications
Because I welcome negative edges, I will try to add as many negative edges as possible.
In addition, some positive edges may be added to just in case that not all negative edges are connected and they may need some positive edges as bridges.
Ok, above is my thinking. But when I try to get my hands dirty, I get stuck.
How can I always record the possible minimum weights set?
For example,
{0, 1} is with weight -20
{2, 3} is with weight -10
if {1, 3} has weight of 11, then of course I don't want {1, 3}
or if {1, 3} has weight of 9, then I want
With what kind of data structure I can always keep the minimum weight and the vertices for that weight?
It is worth to note that the subset this excise seeks for aim at edges
.
Consider the problem of finding a minimum weight connected subset T of edges from a weighted connected graph G
This means that all vertices still need to be included.
Also it is more than a MST. Consider that if a vertex has two edges, one is -1, another is -2. In a normal MST algorithm, only edge of -2 will be taken. But in this excise, both -1 and -2 need to be taken to reduce the overall weight further.