The Edge Set Grown in Kruskal's Algorithm [closed] - algorithm

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
Let G = (V, E) be a weighted, connected and undirected graph. Let T be the edge set that is grown in Kruskal's algorithm and stopped after k iterations (so T might contain less than |E|-1 edges). Let W(T) be the weighted sum of this set.
Let T’ be an acylic edge set such that |T| = |T’|. Prove that W(T) <= W(T’)
I understand the original proof of the algorithm and I’ve tried several approaches to tackle this, neither worked.
For example: I thought an induction on |T| might work.
For |T| = 1 it’s obvious.
We assume correctness for |T|=k and prove (or not…) for k+1. Assume by contradiction that there exists an edge set T’ such that |T’|=k+1 and W(T’) < W(T).
Let e be the last edge added by Kruskal algorithm. So for any edge f in T’, W(f) < W(e) (otherwise we remove the edges from the 2 sets and get a contradiction).
This can only happen if every edge in T’ is already in T or forms a cycle with T – {e}.
…
Note: It's not the same proof as in Kruskal's algorithm. We don't even know whether T' is connected.
I have no idea what to do next. I would really appreciate any help,
Thanks in advance

Let T’ be an edge set such that |T| = |T’|. Prove that W(T) <= W(T’).
You'll have a hard time doing that, since it's false in general.
Consider
1
A---B
2 \ / 3
C
| 4
D
Kruskal's algorithm produces the edge set T = { (A,B), (A,C), (C,D) }, which is the unique minimal spanning tree.
But the edge set T' = { (A,B), (A,C), (B,C) } has the same cardinality as T, and
W(T') = 6 < W(T) = 7
There's some condition missing in the problem statement (like that T' should connect the graph).
You're right. I forgot to mention that there is no cycle in T'
In that case, T' spans a tree(1). And since |T'| = |T| is assumed, the tree that T' spans connects the graph, i.e. is a spanning tree.
(1) From the absence of cycles, it follows directly that each connected component of T' is a tree. A tree with n vertices has n-1 edges. Thus if T' has k connected components, the number of vertices in the graph is
V = |T'| + k
But T is a spanning tree, and |T| = |T'|, hence
V = |T| + 1 = |T'| + 1
which implies k = 1.
Thus you are asked to simply prove the correctness of Kruskal's algorithm. You can find proofs in the literature easily, for example on wikipedia.
A proof of correctness (by induction on the number of vertices):
Lemma: Let G be a connected graph with N > 1 vertices, and T a minimal spanning tree of G. Let e be an edge in T.
Then T \ {e} projects to a minimal spanning tree of the graph G' obtained from G by identifying the two endpoints a and b of e. Conversely, if T' is a set of edges of G that projects to a minimal spanning tree of G', then T' ∪ {e} is a minimal spanning tree of G.
Proof: Let p : G -> G' be the projection identifying a and b.
Then p(T \ {e}) has no cycles.
Suppose p(T \ {e}) contained a cycle C. Then p^(-1)(C) must be a path connecting a and b. But then T would contain the cycle p^(-1)(C) ∪ {e}, contradicting the premise that T is a tree.
Thus p(T \ {e}) is a cycle-free set of edges of G' with cardinality N - 2, and that implies (see above) that it is a spanning tree.
Let T'' be a minimal spanning tree of G' and S = p^(-1)(T'').
Then S ∪ {e} has no cycles.
If there were a cycle in S, that would project to a cycle in T'', so every cycle in S ∪ {e} must contain e. Suppose C were a cycle in S ∪ {e}. Then C \ {e} is a path connecting a and b, thus C \ {e} projects to a cycle in G', since a and b project to the same vertex of G'. That contradicts the premise that T'' is a tree.
So S ∪ {e} is an edge set of cardinality N - 1 without cycles, and hence (see above) a spanning tree of G.
Then W(T) <= W(S ∪ {e}) since T is a minimal spanning tree, and thus
W(p(T \ {e})) = W(T \ {e}) <= W(S) = W(T'')
Since T'' is assumed to be a minimal spanning tree of G', it follows that equality holds, and that p(T \ {e}) is a minimal spanning tree of G', and that S ∪ {e} is a minimal spanning tree of G.
Now to the induction to prove the correctness of Kruskal's algorithm:
For a graph with at most two vertices, it is obvious that the algorithm produces a minimal spanning tree.
For n >= 2, assume the correctness of the algorithm for all connected graphs with at most n vertices. (Induction hypothesis)
Let G be a connected graph with n+1 vertices. Let e be the first edge chosen in the algorithm, and a and b its endpoints.
Let G' be the graph obtained from G by identifying a and b, and p :: G -> G' the projection.
Let T be the edge set selected by the algorithm.
Then p(T \ {e}) is the edge set selected by Kruskal's algorithm on G'. Thus, by the Lemma above, T is a minimal spanning tree of G.
(Okay, probably the proof in wikipedia is simpler, but I wanted to produce a different one.)

Related

Finding Minimum Spanning Tree (MST) in graph?

Given an Undirected graph G with with weight on its edges and 2 different minimal spanning trees: T, T'
Then I want to prove the following:
For every edge e in T that's not in T', there is an edge e' in T'
that's not in T such that if we replace e with e' in T (let's call
it T_new) then it's still a minimal spanning tree of G.
I think I am too close for finding the right algorithm but stuck a little:
I have proved that weight(e) must be exactly equal to weight(e').
Since T is a tree, deleting e will result in 2 separated components, then for T_new to be a tree it must use one of the edges connecting two vertices from those different components.
But, I wasn't able to know which edge e' exactly will work. Plus I wasn't able to prove that always there is such an edge (I just found some requirements for e' that is must satisfy).
Some notes: I know Kruskal algorithm, and familiar with an algorithm in which we can paint some edges in yellow and request it to generate minimal spanning trees with maximum yellow edges (In other words from all found minimal spanning trees return the one with maximum number of yellow edges)
Let T1 and T2 be the two connected components of T \ {e}. Consider the path P joining the endpoints of e in T'. Since e connects T1 and T2, so does P, and therefore there exists an edge e' in P that connects T1 and T2. The edge e' cannot be lighter than e, or else T would not be minimum (T \ {e} U {e'}). The edge e' cannot be heavier than e, or else T' would not be minimum (T' \ {e'} U {e}).

why when we change the cost of every edge in G as c'= log17(c),every MST in G is still an MST in G′ (and vice versa)?

remarks:c' is logc with base 17
MST means (minimum spanning tree)
it's easy to prove the conclusion is correct when we use linear function to transform the cost of every edge.
But log function is not a linear function ,I could not understand why this conclusion is correct。
Supplementary notes:
I did not consider specific algorithms, such as the greedy algorithm. I simply consider the relationship between the sum of the weights of the two trees after transformation.
Numerically if (a + b) > (c + d) , (log a + log b) maybe not > ( logc + logd) .
If a tree generated by G has two edge a and b ,another tree generated by G has c and d,a + b < c + d and the first tree is a MST,but in transformed graph G' ,the sum of weights of edges of second tree may be smaller.
Because of this, I want to construct a counterexample based on "if (a + b)> (c + d), (log a + log b) maybe not> (logc + logd) ", but I failed.
One way to characterize when a spanning tree T is a minimum spanning tree is that, for every edge e not in T, the cycle formed by e and edges of T (the fundamental cycle of e with respect to T) has no edge more expensive than e. Using this characterization, I hope you see how to prove that transforming the costs with any increasing function preserves minimum spanning trees.
There's a one line proof that this condition is necessary. If the fundamental cycle contained a more expensive edge, we could replace it with e and get a spanning tree that costs less than T.
It's less obvious that this condition is sufficient, since at first glance it looks like we're trying to prove global optimality from a local optimality condition. To prove this statement, let T be a spanning tree that satisfies the condition, let T' be a minimum spanning tree, and let G' be the graph whose edges are the union of the edges of T and T'. Run Kruskal's algorithm on G', breaking ties by favoring edges in T over edges not in T. Let T'' be the resulting minimum spanning tree in G'. Since T' is a spanning tree in G', the cost of T'' is not greater than T', hence T'' is a minimum spanning tree in G as well as G'.
Suppose to the contrary that T'' ≠ T. Then there exists an edge in T but not in T''. Let e be the first such edge considered by Kruskal's algorithm. At the time that e was considered, it formed a cycle C in the edges that had been selected from T''. Since T is acyclic, C \ T is nonempty. By the tie breaking criterion, we know that every edge in C \ T costs less than e. Observing that some edge e' in C \ T must have one endpoint in each of the two connected components of T \ {e}, we infer that the fundamental cycle of e' with respect to T contains e, which violates the local optimality condition. In conclusion, T = T'', hence is a minimum spanning tree in G.
If you want a deeper dive, this logic gets abstracted out in the theory of matroids.
Well, its pretty easy to understand...let's see if I can break it down for you:
c` = log_17(c) // here 17 is base
log may not be linear function...but we can say that:
log_b(x) > log_b(y) if x > y and b > 1 (and of course x > 0 and y > 0)
I hope you get the equation I've written...In words in means, consider a base "b" such that b > 1, then log_b(x) would be greater than log_b(y) if x > y.
So, if we apply this rule in your costs of MST of G, then we see that the edges those were selected for G, would still produce the least possible edges to construct MST G' if c' = log_17(c) // here 17 is base.
UPDATE: As I can see you've problem understanding the proof, I'm elaborating a bit:
I guess, you know MST construction is greedy. We're going to use kruskal's algo to proof why it is correct.(In case, you don't know, how kruskal's algo works, you can read it somewhere, or just google it, you'll find millions of resources). Now, Let me write some steps of kruskal's edge selection for MST of G:
// the following edges are sorted by cost..i.e. c_0 <= c_1 <= c_2 ....
c_0: A, F // here, edge c_0 connects A, F, we've to take the edge in MST
c_1: A, B // it is also taken to construct MST
c_2: B, R // it is also taken to construct MST
c_3: A, R // we won't take it to construct to MST, cause (A, R) already connected through A -> B -> R
c_4: F, X // it is also taken to construct MST
...
...
so on...
Now, when constructing MST of G', we've to select edges which are in the form c' = log_17(c) // where 17 is base
Now, if we convert the edges using log of base 17, then c_0 becomes c_0', c_1 becomes c_1' and so on...
But we, know that:
log_b(x) > log_b(y) if x > y and b > 1 (and of course x > 0 and y > 0)
So, we may say that,
log_17(c_0) <= log_17(c_1), cause c_0 <= c_1
in general,
log_17(c_i) <= log_17(c_j), where i <= j
And now, we may say:
c_0` <= c_1` <= c_2` <= c_3` <= ....
So, the edge selection process to construct MST of G' would be:
// the following edges are sorted by cost..i.e. c_0` <= c_1` <= c_2` ....
c_0`: A, F // here, edge c_0` connects A, F, we've to take the edge in MST
c_1`: A, B // it is also taken to construct MST
c_2`: B, R // it is also taken to construct MST
c_3`: A, R // we won't take it to construct to MST, cause (A, R) already connected through A -> B -> R
c_4`: F, X // it is also taken to construct MST
...
...
so on...
Which is same as MST of G...
That proves the theorem ultimately....
I hope you get it...if not ask me in the comment what is not clear to you...

Minimum Spanning tree of a Complete Graph

Assume G = (V,E) is a complete graph.
Let the vertices be a set of points in the plane and let the edges be line segments between the points. Let the weight of each edge [a, b] be the length of the segment 'ab'.
After reading about Prim's Algorithm and Kruskal's Algorithm, I have some sound knowledge that these greedy algorithms output the minimum spanning tree of a graph.
My Question is: After obtaining a minimum spanning tree of G, Is there a way to prove that the minimum spanning tree of G is a plane graph?
You can check if the minimum spanning tree is planar as any graph. There are a simple way to check if a graph is planar. The very known Euler formula
“If G is a connected planar graph with e edges and v vertices, where v >= 3, then e <= 3v - 6. Also G cannot have a vertex of degree exceeding 5.”
or you can rely on the following method:
Theorem – “Let G be a connected simple planar graph with e edges and v vertices. Then the number of faces f in the graph is equal to f = e-v+2.”
Euler also showed that for any connected planar graph, the following relationship holds:
v - e + f = 2.
Good lucky

Finding a New Minimum Spanning Tree After a New Edge Was Added to The Graph

Let G = (V, E) be a weighted, connected and undirected graph and let T be a minimum spanning tree. Let e be any edge not in E (and has a weight W(e)).
Prove or disprove:
T U {e} is an edge set that contains a minimum spanning tree of G' = (V, E U {e}).
Well, it sounds true to me, so I decided to prove it but I just get stuck every time...
For example, if e is the new edge with minimum weight, who can promise us that the edges in T weren't chosen in a bad way that would prevent us from obtaining a new minimum weight without the 'help' of other edges in E - T ?
I would appreciate any help,
Thanks in advance.
Let [a(1), a(2), ..., a(n-1)] be a sequence of edges selected from E to construct MST of G by Kruskal's algorithm (in the order they were selected - weight(a(i)) <= weight(a(i + 1))).
Let's now consider how Kruskal's Algorithm behaves being given as input E' = E U {e}.
Let i = min{i: weight(e) < weight(a(i))}. Firstly algorithm decides to choose edges [a(1), ..., a(i - 1)] (e hasn't been processed yet, so it behaves the same). Then it need to decide on e - if e is dropped, solution for E' will be the same as for E. So let's suppose that first i edges selected by algorithm are [a(1), ..., a(i - 1), e] - I will call this new sequence a'. Algorithm continues - as long as its following selections (for j > i) satisfy a'(j) = a(j - 1) we are cool. There are two scenarios that break such great streak (let's say streak breaks at index k + 1):
1) Algorithm selects some edge e' that is not in T, and weight(e') < weight(a(k+1)). By now a' sequence is:
[a(1), ..., a(i-1), e, a(i), a(i+1), ..., a(k-1), a(k), e']
But if it was possible to append e' to this list it would be also possible to append it to [a(1), ..., a(k-1), a(k)]. But Kruskal's algorithm didn't do it when looking for MST for G. That leads to contradiction.
2) Algorithm politely selected:
[a(1), ..., a(i-1), e, a(i), a(i+1), ..., a(k-1), a(k)]
but decided to drop edge a(k+1). But if e was not present in the list algorithm would decide to append a(k+1). That means that in graph (V, {a(1), ..., a(k)}) edge a(k+1) would connect the same components as edge e. And that means that after considering by algorithm edge a(k + 1) in case of both G and G' the division into connected components (determined by set of selected edges) is the same. So after processing a(k+1) algorithm will proceed in the same way in both cases.
When ever a edge is add to a graph without adding a node , then that edge creates a cycle in minimum spanning tree of graph, cycle length may vary from 2 to n where n= no of nodes in graph.
T = Minimum spanning tree of G
Now to find the MST for (T + added edge) , we have to just remove one edge from that cycle .. so remove that edge which has maximum weight.
So T' always comes from T U {e}.
And if you are thinking that this doesn't prove that new MST will be an edge set of T U {e} then analyse Kruskal algorithim for for new graph. i.e. if e is of minimum weight it must have been selected for MST acc to Kruskal algorithim and same here if it is minimum it can not be removed from cycle.

Use Dijkstra's to find a Minimum Spanning Tree?

Dijkstra's is typically used to find the shortest distance between two nodes in a graph. Can it be used to find a minimum spanning tree? If so, how?
Edit: This isn't homework, but I am trying to understand a question on an old practice exam.
The answer is no. To see why, let's first articulate the question like so:
Q: For a connected, undirected, weighted graph G = (V, E, w) with only nonnegative edge weights, does the predecessor subgraph produced by Dijkstra's Algorithm form a minimum spanning tree of G?
(Note that undirected graphs are a special class of directed graphs, so it is perfectly ok to use Dijkstra's Algorithm on undirected graphs. Furthermore, MST's are defined only for connected, undirected graphs, and are trivial if the graph is not weighted, so we must restrict our inquiry to these graphs.)
A: Dijkstra's Algorithm at every step greedily selects the next edge that is closest to some source vertex s. It does this until s is connected to every other vertex in the graph. Clearly, the predecessor subgraph that is produced is a spanning tree of G, but is the sum of edge weights minimized?
Prim's Algorithm, which is known to produce a minimum spanning tree, is highly similar to Dijkstra's Algorithm, but at each stage it greedily selects the next edge that is closest to any vertex currently in the working MST at that stage. Let's use this observation to produce a counterexample.
Counterexample: Consider the undirected graph G = (V, E, w) where
V = { a, b, c, d }
E = { (a,b), (a,c), (a,d), (b,d), (c,d) }
w = {
( (a,b) , 5 )
( (a,c) , 5 )
( (a,d) , 5 )
( (b,d) , 1 )
( (c,d) , 1 )
}
Take a as the source vertex.
Dijkstra's Algorithm takes edges { (a,b), (a,c), (a,d) }.
Thus, the total weight of this spanning tree is 5 + 5 + 5 = 15.
Prim's Algorithm takes edges { (a,d), (b,d), (c,d) }.
Thus, the total weight of this spanning tree is 5 + 1 + 1 = 7.
Strictly, the answer is no. Dijkstra's algorithm finds the shortest path between 2 vertices on a graph. However, a very small change to the algorithm produces another algorithm which does efficiently produce an MST.
The Algorithm Design Manual is the best book I've found to answer questions like this one.
Prim's algorithm uses the same underlying principle as Dijkstra's algorithm.
I'd keep to a greedy algorithm such as Prim's or Kruskal's. I fear Djikstra's won't do, simply because it minimizes the cost between pairs of nodes, not for the whole tree.
Of course, It's possible to use Dijkstra for minimum spanning tree:
dijsktra(s):
dist[s] = 0;
while (some vertices are unmarked) {
v = unmarked vertex with
smallest dist;
Mark v; // v leaves “table”
for (each w adj to v) {
dist[w] = min[ dist[w], dist[v] + c(v,w) ];
}
}
Here is an example of using Dijkstra for spanning tree:
You can find further explanation in Foundations of Algorithms book, chapter 4, section 2.
Hope this help

Resources