Let's say there's Graph G such that it all its edges have weights that correspond to distinct integers. So no two edge has the same weight.
Let E be all the edges of G. Let emax be an edge in E with the maximum weight.
Another property of Graph G is that every edge e belongs to some cycle in G.
I have to prove that no minimum spanning tree of G contains the edge emax.
I can see why this is true, since all edges are distinct and every edge belongs to a cycle, the minimum spanning tree algorithm can simply choose the edge with lower weight in the cycle that contains emax.
But I'm not sure how to concretely prove it.
This is related to the Cycle Property of the Minimum Spanning Tree, which is basically saying that given a cycle in a graph the edge with the greatest weight does not belong in the MST (easily proven by contradiction in the link above). Thus since the edge emax belongs to a cycle it must not be in the MST.
Proof by contradiction works here. Suppose you have a minimum spanning tree including the maximum edge. If you remove that edge you have two components no longer connected from each other. Every vertex is in one component or the other. There is a cycle including the maximum edge. Start on a vertex at one side of the maximum edge and move along the cycle. Because you will eventually cycle round to the other side of the maximum edge in the other component you will find - before then - an edge which has one vertex in one of the disconnected components and one vertex in another of the disconnected components. Since the components are disconnected that edge is not in the minimum spanning tree. By adding it to the tree you reconnect the components and create a minimum spanning tree with smaller weight than you started with - so you original minimum spanning tree was not minimum.
Does a MST contain the maximum weight edge?
Sometimes, Yes.
It depends on the type of graph. If the edge with maximum weight is the only bridge that connects the components of a graph, then that edge must also be present in the MST.
Related
The origin problem is from the exercise of Introduction of Algorithm.
23.1-5 Let e be a maximum-weight edge on some cycle of connected graph G=(V, E). Prove that there is a minimum spanning tree of G'=(V, E - {e}) that is also a minimum spanning tree of G. That is, there is a minimum spanning tree of G that does not include e.
The question is that: I think the proposition that all the minimum spanning tree of G do not include e is right. The e is the only one maximum-weight edge on some cycle. Is it ?
Update: 2016-10-28 20:21
Add the restriction that e is the only one maximum-weight edge on some cycle.
One test case is when there are nodes labeled 0..n-1 and there are links only between node i and node (i + 1) mod n (that is, a ring). In this case the minimum spanning tree is created by leaving out just one of the links. If e is the unique maximum weight edge it is not in the unique spanning tree, which is all the other links. If there is more than one edge of maximum weight then there are as many different minimum spanning trees as there are edges of maximum weight, each one of them leaving out a different edge of maximum weight and keeping the other ones in.
Consider the case when there is just one edge of maximum weight. Supposing somebody hands you a minimum spanning tree that uses this edge. Delete it from the tree, giving you two disconnected components. Now try adding each of the other edges in the cycle, one at a time. If the edge doesn't connect the two components, delete it again. If any of the edges connect the two components, you have a spanning tree of smaller weight than before, so it can't have been a minimum spanning tree. Can it be the case that none of the edges connect the two components? Adding an edge that doesn't connect the two components doesn't increase the set of nodes reachable from either component, so if no single edge connected the two components, adding all of them at the same time won't. But we know that adding all of these edges adds a path that connects the two nodes connected by the previous maximum weight edge, so one of the edges must connect the components. So our original so-called minimum spanning tree wasn't, and an edge which is of unique maximum weight in a cycle can't be part of a minimum spanning tree.
Your guess is correct:
all the minimum spanning tree of G do not include e is right.
First we need to prove:
e is not a light edge crossing any cut of G.
Let C be any cut that cuts e, since e is in a cycle, so e is not a light edge for any of those cuts, and all the other cuts won't have the edge e crossing it, we won't have that the edge is light for any of those cuts either.
Then we need to prove:
if e is not a light edge crossing any cut of G, then all the minimum spanning tree of G do not include e.
Which is exactly the inverse proposition of 23.1-3.
So I have an exercise that I should prove or disprove that:
1) if e is a minimum weight edge in the connected graph G such that not all edges are necessarily distinct, then every minimum spanning tree of G contains e
2) Same as 1) but now all edge weights are distinct.
Ok so intuitively, I understand that for 1) since not all edge weights are distinct, then it's possible that a vertex has the path with edge e but also another edge e_1 such that if weight(e) = weight (e_1) then there is a spanning tree which does not contain the edge e since the graph is connected. Otherwise if both e_1 and e are in the minimum spanning tree, then there is a cycle
and for 2) since all edge weights are distinct, then of course the minimum spanning tree will contain the edge e since any algorithm will always choose the smaller path.
Any suggestions on how to prove these two though? induction? Not sure how to approach.
Actually in your first proof when you say that if both e and e_1 are in G, then there's a cycle, that's not true, because they're minimal edges, so there doesn't have to be a cycle, and you do need to include them both into the MST, because if |E| > 1 and |V| > 2 then they both have to be there.
Anyways, a counter example for the first one is a complete graph with all edges of the same weight as e, the MST will contain only |V|-1 edges, but you didn't include all the other edges of that same weight, hence you have a contradiction.
As for the second one, if all edges are distinct, then if you remove the minimum edge and want to reconstruct the MST, the only way to go about this is to add a an edge connecting the 2 disjoint sets that were broken up by that minimum-weight edge.
Now suppose that you didn't remove that minimum-weight edge, and added that other edge, now you've created a cycle, and since all edges are distinct the cycle-creating edge will be greater than all of them, hence if you remove any former MST edge from that cycle, it will only increase the size of the MST. Which means that pretty much all former MST edges are critical when all edges have distinct weights.
We have a graph G and wish to add edges between every vertex pair, that are as light as possible without affecting the minimum spanning tree.
Given the minimum spanning tree and a pair of vertices, how would one compute the weight of the lightest edge that can be added between them without affecting the MST?
Thought adding an edge that is heavier than every other edge the two vertices have would work but it appears to be erroneous in trials I've conducted.
The number of edges of a spanning tree is determined by the number of vertices. Hence, if you add an edge to the MST, you need to remove another in order to get a spanning tree. However, you cannot remove any edge. Obviously, removing an edge that is not on the path between the two vertices disconnects the graph. Therefore, you can only remove an edge on this path. If you want to find the minimum spanning tree, you would remove the heaviest edge, of course.
This new spanning tree is heavier than the original one iff the new edge's weight is greater than the heaviest edge weight on the old path. Therefore, the new edge must be heavier than this edge in order to keep the original MST.
Just to recapture and explain it in my own words (after accepting the answer):
To find the minimal weight for a newly added edge e between v and u (vertices in graph G), such that it does not improve (lighten) G's minimum spanning tree's weight, do the following:
Find the path between v and u on the tree (there is only one such path).
Find the heaviest edge(s) on that path.
Make the newly added edge as heavy or heavier than that weight.
This will not affect the total weight of the tree.
I have the following problem on my homework:
Give an O(n+m) algorithm to find that whether an edge e would be a part of the MST of a graph
(We are allowed to get help from others on this assignment, so this isn't cheating.)
I think that I could do a BFS and find if this edge is a edge between two layers and if so whether this edge was the smallest across those layers. But what could I say when this edge is not a tree edge of the BFS tree?
As a hint, if an edge is not the heaviest edge in any cycle that contains it, there is some MST that contains that edge. To see this, consider any MST. If the MST already contains the edge, great! We're done. If not, then add the edge into the MST. This creates a cycle in the graph. Now, find the heaviest edge in that cycle and remove it from the graph. Everything is now still connected (because if two nodes used to be connected by a path that went across that edge, now they can be connected by just going around the cycle the other way). Moreover, since the cost of the edge was deleted wasn't any smaller than the cost of the edge in question (because the edge isn't the heaviest edge in the cycle), the cost of this tree can't be any greater than before. Since we started with an MST, we must therefore end with an MST.
Using this property, see if you can find whether the edge is the heaviest edge on any cycle in linear time.
We will solve this using MST cycle property, which says that, "For any cycle C in the graph, if the weight of an edge e of C is larger than the weights of all other edges of C, then this edge cannot belong to an MST."
Now, run the following O(E+V) algorithm to test if the edge E connecting vertices u and v will be a part of some MST or not.
Step 1
Run dfs from one of the end-points(either u or v) of the edge E considering only those edges that have weight less than that of E.
Step 2
Case 1
If at the end of this dfs, the vertices u and v get connected, then edge E cannot be a part of some MST. This is because in this case there definitely exists a cycle in the graph with the edge E having the maximum weight and it cannot be a part of the MST(from the cycle property).
Case 2
But if at the end of the dfs u and v stay disconnected, then edge E must be the part of some MST as in this case E is never the maximum weight edge of the cycles that it is a part of.
Find if there are any paths that are cheaper than the current one (u,v) that creates a cycle to u and v. If yes, then (u,v) is not on the mst. Otherwise it is. This can be proved by the cut property and the cycle property.
Does the opposite of Kruskal's algorithm for minimum spanning tree work for it? I mean, choosing the max weight (edge) every step?
Any other idea to find maximum spanning tree?
Yes, it does.
One method for computing the maximum weight spanning tree of a network G –
due to Kruskal – can be summarized as follows.
Sort the edges of G into decreasing order by weight. Let T be the set of edges comprising the maximum weight spanning tree. Set T = ∅.
Add the first edge to T.
Add the next edge to T if and only if it does not form a cycle in T. If
there are no remaining edges exit and report G to be disconnected.
If T has n−1 edges (where n is the number of vertices in G) stop and
output T . Otherwise go to step 3.
Source: https://web.archive.org/web/20141114045919/http://www.stats.ox.ac.uk/~konis/Rcourse/exercise1.pdf.
From Maximum Spanning Tree at Wolfram MathWorld:
"A maximum spanning tree is a spanning tree of a weighted graph having maximum weight. It can be computed by negating the weights for each edge and applying Kruskal's algorithm (Pemmaraju and Skiena, 2003, p. 336)."
If you invert the weight on every edge and minimize, do you get the maximum spanning tree? If that works you can use the same algorithm. Zero weights will be a problem, of course.
Although this thread is too old, I have another approach for finding the maximum spanning tree (MST) in a graph G=(V,E)
We can apply some sort Prim's algorithm for finding the MST. For that I have to define Cut Property for the maximum weighted edge.
Cut property: Let say at any point we have a set S which contains the vertices that are in MST( for now assume it is calculated somehow ). Now consider the set S/V ( vertices not in MST ):
Claim: The edge from S to S/V which has the maximum weight will always be in every MST.
Proof: Let's say that at a point when we are adding the vertices to our set S the maximum weighted edge from S to S/V is e=(u,v) where u is in S and v is in S/V. Now consider an MST which does not contain e. Add the edge e to the MST. It will create a cycle in the original MST. Traverse the cycle and find the vertices u' in S and v' in S/V such that u' is the last vertex in S after which we enter S/V and v' is the first vertex in S/V on the path in cycle from u to v.
Remove the edge e'=(u',v') and the resultant graph is still connected but the weight of e is greater than e' [ as e is the maximum weighted edge from S to S/V at this point] so this results in an MST which has sum of weights greater than original MST. So this is a contradiction. This means that edge e must be in every MST.
Algorithm to find MST:
Start from S={s} //s is the start vertex
while S does not contain all vertices
do
{
for each vertex s in S
add a vertex v from S/V such that weight of edge e=(s,v) is maximum
}
end while
Implementation:
we can implement using Max Heap/Priority Queue where the key is the maximum weight of the edge from a vertex in S to a vertex in S/V and value is the vertex itself. Adding a vertex in S is equal to Extract_Max from the Heap and at every Extract_Max change the key of the vertices adjacent to the vertex just added.
So it takes m Change_Key operations and n Extract_Max operations.
Extract_Min and Change_Key both can be implemented in O(log n). n is the number of vertices.
So This takes O(m log n) time. m is the number of edges in the graph.
Let me provide an improvement algorithm:
first construct an arbitrary tree (using BFS or DFS)
then pick an edge outside the tree, add to the tree, it will form a cycle, drop the smallest weight edge in the cycle.
continue doing this util all the rest edges are considered
Thus, we'll get the maximum spanning tree.
This tree satisfies any edge outside the tree, if added will form a cycle and the edge outside <= any edge weights in the cycle
In fact, this is a necessary and sufficient condition for a spanning tree to be maximum spanning tree.
Pf.
Necessary: It's obvious that this is necessary, or we could swap edge to make a tree with a larger sum of edge weights.
Sufficient: Suppose tree T1 satisfies this condition, and T2 is the maximum spanning tree.
Then for the edges T1 ∪ T2, there're T1-only edges, T2-only edges, T1 ∩ T2 edges, if we add a T1-only edge(x1, xk) to T2, we know it will form a cycle, and we claim, in this cycle there must exist one T2-only edge that has the same edge weights as (x1, xk). Then we can exchange these edges will produce a tree with one more edge in common with T2 and has the same sum of edge weights, repeating doing this we'll get T2. so T1 is also a maximum spanning tree.
Prove the claim:
suppose it's not true, in the cycle we must have a T2-only edge since T1 is a tree. If none of the T2-only edges has a value equal to that of (x1, xk), then each of T2-only edges makes a loop with tree T1, then T1 has a loop leads to a contradiction.
This algorithm taken from UTD professor R. Chandrasekaran's notes. You can refer here: Single Commodity Multi-terminal Flows
Negate the weight of original graph and compute minimum spanning tree on the negated graph will give the right answer. Here is why: For the same spanning tree in both graphs, the weighted sum of one graph is the negation of the other. So the minimum spanning tree of the negated graph should give the maximum spanning tree of the original one.
Only reversing the sorting order, and choosing a heavy edge in a vertex cut does not guarantee a Maximum Spanning Forest (Kruskal's algorithm generates forest, not tree). In case all edges have negative weights, the Max Spanning Forest obtained from reverse of kruskal, would still be a negative weight path. However the ideal answer is a forest of disconnected vertices. i.e. a forest of |V| singleton trees, or |V| components having total weight of 0 (not the least negative).
Change the weight in a reserved order(You can achieve this by taking a negative weight value and add a large number, whose purpose is to ensure non-negative) Then run your family geedy-based algorithm on the minimum spanning tree.