Does minimum spanning tree works for situation like this: If I want to go from A to B and I do not have to go to E, but the direct distance between A and B is larger than distance_AE + distanceEB, so I can go E first and then go to B. I'm not sure if the normal implementation of mst also works for this kind of graph. So if I want to find the mst of ABCD, but E is not included in this graph, how can I solve this?
I believe that you're confused about the basic problem: what you've posted is a contradiction. If E is not in the graph, then by definition dist(A, E) is undefined; for algorithmic purposes, it's Inf (infinity).
Yes, the MST algorithms work fine for this: the entire universe consists of (A, B, C, D).
Related
Assume you have an undirected-weighted graph G, with different edges weighs but for only two edges: w(e1)=w(e2)
I have to prove that G has at most one minimum spanning tree which includes e1.
Also I have to prove that G has at most one minimum spanning tree which doesnt include e1.
I only need a solution for the first one and will solve the second one alone.
Thanks
For solving part 1:
Consider the graph you get by removing e1 from G (and possibly one of it's vertices, if it's now not connected to the rest of the graph), let's call it G'.
In this graph (G') , all the edge weights are different.
Now suppose G has more than 1 MST which includes e1 - they would both be different MSTs for G'.
Now the trick is that there's a theorem that in this kind of graph (all edges are different), the MST is unique. see the proof(s) here.
edit: You can probably just take the proof from the link and edit it slightly for your case.
I am trying self-study Graph Theory, and now trying to understand how to find SCC in a graph. I have read several different questions/answers on SO (e.g., 1,2,3,4,5,6,7,8), but I cant find one with a complete step-by-step example I could follow.
According to CORMEN (Introduction to Algorithms), one method is:
Call DFS(G) to compute finishing times f[u] for each vertex u
Compute Transpose(G)
Call DFS(Transpose(G)), but in the main loop of DFS, consider the vertices in order of decreasing f[u] (as computed in step 1)
Output the vertices of each tree in the depth-first forest of step 3 as a separate strong connected component
Observe the following graph (question is 3.4 from here. I have found several solutions here and here, but I am trying to break this down and understand it myself.)
Step 1: Call DFS(G) to compute finishing times f[u] for each vertex u
Running DFS starting on vertex A:
Please notice RED text formatted as [Pre-Vist, Post-Visit]
Step 2: Compute Transpose(G)
Step 3. Call DFS(Transpose(G)), but in the main loop of DFS, consider the vertices in order of decreasing f[u] (as computed in step 1)
Okay, so vertices in order of decreasing post-visit(finishing times) values:
{E, B, A, H, G, I , C, D, F ,J}
So at this step, we run DFS on G^T but start with each vertex from above list:
DFS(E): {E}
DFS(B): {B}
DFS(A): {A}
DFS(H): {H, I, G}
DFS(G): remove from list since it is already visited
DFS(I): remove from list since it is already visited
DFS(C): {C, J, F, D}
DFS(J): remove from list since it is already visited
DFS(F): remove from list since it is already visited
DFS(D): remove from list since it is already visited
Step 4: Output the vertices of each tree in the depth-first forest of step 3 as a separate strong connected component.
So we have five strongly connected components: {E}, {B}, {A}, {H, I, G}, {C, J, F, D}
This is what I believe is correct. However, solutions I found here and here say SCCs are {C,J,F,H,I,G,D}, and {A,E,B}. Where are my mistakes?
Your steps are correct and your answer is also correct, by examining the other answers you provided you can see that they used a different algorithm: First you run DFS on G transposed and then you run an undirected components algorithm on G processing the vertices in decreasing order of their post numbers from the previous step.
The problem is they ran this last step on G transposed instead of in G and thus got an incorrent answer. If you read Dasgupta from page 98 onwards you will see a detailed explanation of the algorithm they (tried) to use.
Your answers is correct. As per CLRS, "A strongly connected component of a directed graph G = (V,E) is a maximal set of vertices C, such that for every pair of vertices u and v, we have both u ~> v and v ~> u, i.e. vertices v and u are reachable from each other."
In case you assume {C, J, F, H, I, G, D} as correct, there is no way to reach from D to G (amongst many other fallacies), and same with other set, there is no way to reach from A to E.
Hi so i'm doing some test prep and i need to figure out parts b and c. I know part a is true and i can prove it, but finding the algorithms for part b and c is currently eluding me.
Solve the following for a minimum bottleneck tree where the edge with the maximum cost is referred to as the bottleneck.
(a) Is every minimum-bottleneck
spanning tree of G a minimum-spanning tree of G? Prove your claim.
(b) For a given cost c, give an O(n+m)-time algorithm to
find if the bottleneck cost of a minimum-bottleneck spanning tree
of G is not more than c.
(c) Find an algorithm to find a minimum-bottleneck
spanning tree of G.
thanks in advance to anyone who can help me out
For (b):
Erase every edge in G that costs more than c, then check if the left graph is still connected.
For (c):
Do a binary search on c, using the algorithm that solved (b) as the dividing condition.
Proof of (b):
Let's say the graph we got after deleting edges cost more than c from G is G' .
Then:
If G' is connected, then there must be a spanning tree T in G'. Since no edge in G' costs more than c, we can tell for sure that no edge in T costs more than c. Therefore T is a spanning tree for G' and also G whose bottle neck is at most c
If G' is not connected, then there's no spanning tree in G' at all. Since we know every edge in G- G' costs more than c, and we know that any spanning tree of G will contains at least one edge of G- G', therefore we know there's no edge spanning tree of G whose bottle neck <= c
And of course detecting if a graph is connected costs O(n+m)
Proof of (c):
Say, the algorithm we used in (b) is F(G,c) .
Then we have
If F(G,c) = True for some c, then F(G,c') = True for all c' that have c'>=c
If F(G,c) = False for some c, then F(G,c') = False for all c' that have c'<=c
So we can binary search on c :)
Ans. a)False,every minimum bottleneck spanning tree of graph G is not a minimum spanning tree of G.
b)To check whether the value of minimum bottleneck spanning tree is atmost c,you can apply depth first search by selecting any vertex from the set of vertices in graph G.
***Algorithm:***
check_atmostvalue(Graph G,int c)
{
for each vertex v belongs to V[G] do {
visited[v]=false;
}
DFS(v,c); //v is any randomly choosen vertex in Graph G
for each vertex v belongs to V[G] do {
if(visited[v]==false) then
return false;
}
return true;
}
DFS(v,c)
{
visited[v]=true;
for each w adjacent to v do {
if(visited[w]=false and weight(v,w)<=c) then
DFS(w,c);
}
visited[w]=true;
}
This algorithm works in O(V+E) in the worst case as running timr for depth first search DFS is O(V+E).
This problem can be solved by simply finding the MST of the graph. This based on the following claim:
MST is a MBST for a connected graph.
For a MST, choose the maximum edge e in the MST and the edge e divides the MST into two sets S and T. Then from the cut property, edge e must be the minimum weight among those edges that connects S and T.
Then for a MBST, there must be some edge e' that connect S and T. Then w(e') must be no less than w(e). Thus we know that MST must be a MBST.
However, there is another way to determine the minimum bottleneck. We don't need to computer the MBST. In your question, you actually implies the monotocity of the minimum bottleneck. Therefor we can use binary search combined with the connectivity algorithm to find the minimum bottle neck. I haves seen the use of monocity in other cases. I am a bit amazed that the similar technique can be used here!
I have been given a question on an assignment that has got me stumped. I may just be thinking too hard about it... The question follows.
Give a linear time algorithm to determine the longest unweighed path in an acyclic undirected graph (that is, a tree).
My first intention is to go with a DFS. But it seems like a DFS would only give me the longest path from the node I start at to another vertex; however, the problem asks for the longest path in the tree... not the longest path from the node I start at. Could someone set me straight?
Thanks.
One such method is to pick any node, A, and in linear time compute distances to all other nodes. Suppose B is most distant from A. In step 2, find the node most distant from B.
Let d(P,Q) denote distance from P to Q. Note that if E is the lowest common ancestor of A, B, C, then d(A,B) = d(A,E)+d(E,B) and also note that d(E,B) ≥ d(E,C).
Edit 1: The algorithm or method – find B most distant from any A; find C most distant from B; claim that d(B,C) is maximal over all vertex pairs in the graph – seems to be sound, but the above does not prove it.
On one hand, it need not be that d(E,B) ≥ d(E,C), and on another, that alone would not be quite enough to establish d(B,C) ≥ d(F,G) where F, G are any nodes in the tree. ...
What would the following algorithm look like:
a linear-time algorithm which, given an undirected graph G, and a particular edge e in it, determines whether G has a cycle containing e
I have following Idea:
for each v that belongs to V,
if v is a descendant of e and (e,v) has not been traversed then check following:
if we visited e before v and left v before we left e then
the graph contains cycle
I am not sure if this is your homework so I'll just give a little hint - use the properties of breadth-first search tree (with root in any of the two vertices of the edge e), its subtrees which are determined by neighbors of the root and the edges between those subtrees.
Per comingstorm's hint, an undirected edge is itself a cycle. A<->B back and forth as many times as you like.