A Paradox in graph theory? - algorithm

I was reading minimum spanning trees in CLRS and came across the following corollary which is basis of algorithms to compute minimum spanning tree:
Corollary 23.2
Let G = (V,E) be a connected, undirected graph with a real-valued weight function w defined on E. Let A be a subset of E that is included in some minimum
spanning tree for G, and let C = (V_C,E_C) be a connected component (tree) in the forest G_A = (V,A). If (u,v) is a light edge connecting C to some other component in G_A, then (u,v) is safe for A.
Proof The cut (V_C, V-V_C) respects A, and (u,v) is a light edge for this cut. Therefore, it is safe for A.
I find some inconsistency. Why? Let me show you:
Some Statements skimmed from Corollary
These are the statements copied from the Same Corollary and its proof in the text:
STATEMENT 1 - G_A = (V, A)
STATEMENT 2 - (u,v) is a light edge connecting C to some other component in G_A.
STATEMENT 3 - The cut (V_C, V - V_C) respects A
STATEMENT 4 - (u,v) is a light edge for this cut.
Lemma 1
Statement 1 and 2 imply (u,v) is in A
Proof
For purpose of contradiction lets assume that it does not belong to A. As (u,v) connects two components of graph G_A it must be an edge in graph G_A. As Set of edge is given by A in graph G_A it must belong to A which contradict our assumption.
Inconsistency
Now Lemma 1 implies (u,v) belongs to A . Statement 3 implies the cut respects (u,v) which further implies (u,v) cannot cross the cut. Since it cannot cross the cut, it cannot be a light edge which contradicts Statement 4.
Does this imply the algorithms are incorrect. According to me G_A should be changed to G. Am I wrong?
EDIT
Other Possible Change
Well then Edge should belong to E as it cannot be any edge that is light. Let say we have edge set F superset of E that contains edge lighter than (u,v). Than upon finishing we will have MST not spanning G. An example has been attached to clarify the statement. Go to Example. Sorry for the shadowing. Stack Overflow wasnot uploading the image - I tried numerous times.
So shouldn't the last line of corollary be changed to (u,v) belongs to E and is a light edge for G_A for clarification purposes?

Related

Finding if a graph is still strongly connected after edge removal

A strongly connected digraph is a directed graph in which for each two vertices 𝑢 and 𝑣,
there is a directed path from 𝑢 to 𝑣 and a direct path from 𝑣 to 𝑢. Let 𝐺 = (𝑉, 𝐸) be a
strongly connected digraph, and let 𝑒 = (𝑢, 𝑣) ∈ 𝐸 be an edge in the graph.
Design an efficient algorithm which decides whether 𝐺
′ = (𝑉, 𝐸 ∖ {𝑒}), the graph
without the edge 𝑒 is strongly connected. Explain its correctness and analyze its running
time.
So what I did is run BFS and sum the labels, once on the original graph from 𝑢 and then again in G' without the edge (again from 𝑢)
and then : if second sum (in G') < original sum (in G) then the graph isn't strongly connected.
P.S this is a question from my exam which I only got 3/13 points and I'm wondering if i should appeal..
As Sneftel points out, the distance labels can only increase. If u no longer has a path to v, then I guess v's label will be infinite, so the sum of labels will change from finite to infinite. Yet the sum can increase without the graph losing strong connectivity, e.g.,
u<----->v
\ /|
\| /
w
where v's label increases from 1 to 2 because of the indirect path through w.
Since the graph G is strongly connected, G' is strongly connected if and only if there is a path from u to v (this path would replace the edge e).
You can use any path finding algorithm to solve this problem.

Find all edges in min-cut

Let (G,s,t,{c}) be a flow network, and let F be the set of all edges e for which there exists at least one minimum cut (A,B) such that e goes from A to B. Give a polynomial time algorithm that finds all edges in F.
NOTE: So far I know I need to run Ford-Fulkerson so each edges has a flow. Furthermore I know for all edges in F, the flow f(e) = c(e). However not all edges in a graph G which respects that constraint will be in a min-cut. I am stuck here.
Suppose you have computed a max flow on a graph G and you know the flow through every edge in the graph. From the source vertex s, perform a Breadth First Search OR Depth First Search on the original graph and only traverse those edges that have flow less than the capacity of the edge. Denote the set of vertices reachable in this traversal as S, and unreachable vertices as T.
To obtain the minimum cut C, we simply find all edges in the original graph G which begin at some vertex in S and end at some vertex in T.
This tutorial in Topcoder provides an explanation / proof of the above algorithm. Look at the section beginning with the following text:
A cut in a flow network is simply a partition of the vertices in two sets, let's call them A and B, in such a way that the source vertex is in A and the sink is in B.
I shall attempt to provide an explanation of the corresponding section in the Topcoder tutorial (just for me to brush up on this as well).
Now, suppose that we have computed a max flow on a graph G, and that we have computed the set of edges C using the procedure outlined above. From here, we can conclude several facts.
Fact 1: Source vertex s must be in set S, and sink vertex t must be in set T.
Otherwise, vertices s and t must be in the same set, which means that we must have found a path from s to t consisting only of edges that have flow less than capacity. This means that we can push more flow from s to t, and therefore we have found an augmenting path! However, this is a contradiction, since we have already computed a max flow on the graph. Hence, it is impossible for source vertex s and sink vertex t to be connected, and they must be in different sets.
Fact 2: Every edge beginning at set S and ending at set T must have flow == capacity
Again we prove this by contradiction. Suppose that there is a vertex u in S and a vertex v in T, such that edge (u,v) in the residual network has flow less than capacity. By our algorithm above, this edge will be traversed, and vertex v should be in set S. This is a contradiction. Therefore, such an edge must have flow == capacity.
Fact 3: Removing the edges in C from graph G will mean that there is no path from any vertex in set S to any vertex in set T
Suppose that this is not the case, and there is some edge (u,v) that connects vertex u in set S to vertex v in set T. We can separate this into 2 cases:
Flow through edge (u,v) is less than its capacity. But we know this will cause vertex v to be part of set S, so this case is impossible.
Flow through edge (u,v) is equal to its capacity. This is impossible since edge (u,v) will be considered as part of the edge set C.
Hence both cases are impossible, and we see that removing the edges in C from the original graph G will indeed result in a situation where there is no path from S to T.
Fact 4: Every edge in the original graph G that begins at vertex set T but ends at vertex set S must have a flow of 0
The explanation on the Topcoder tutorial may not be obvious on first reading and the following is an educated guess on my part and may be incorrect.
Suppose that there exists some edge (x,y) (where x belongs to vertex set T and y belongs to vertex set S), such that the flow through (x,y) is greater than 0. For convenience, we denote the flow through (x,y) as f. This means that on the residual network, there must exist a backward edge (y,x) with capacity f and flow 0. Since vertex y is part of set S, the backward edge (y,x) has flow 0 with capacity f > 0, our algorithm will traverse the edge (y,x) and place vertex x as part of vertex set S. However, we know that vertex x is part of vertex set T, and hence this is a contradiction. As such, all edges from T to S must have a flow of 0.
With these 4 facts, along with the Max-flow min-cut theorem, we can conclude that:
The max flow must be less than or equal to the capacity of any cut. By Fact 3, C is a cut of the graph, so the max flow must be less than or equal to the capacity of cut C.
Fact 4 allows us to conclude that there is no "back flow" from T to S. This along with Fact 2 means that the flow consists entirely of "forward flow" from S to T. In particular, all the forward flow must result from the cut C. This flow value happens to be the max flow. As such, by the Max-flow min-cut theorem, we know that C must be a minimum cut.

spanning tree including maximum weight [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
Let G be a weighted undirected graph and e be an edge with maximum weight in G.Suppose there is a minimum weight spanning tree in G containing the edge e.Which of the following statements is always TRUE?
a.There exists a cut in g having all edges of maximum weight
b.There exists a cycle in G having all edges of maximum weight
c.Edge e can not be contained in a cycle
d.All edges in G have the same weight
Is a previous year exam questing .i am having trouble to under stand it can any one explain it to me .
The bottom three are false, and the following simple graph is a counter-example to all three:
1
a --- b
| /
2 | /
| / 2
| /
c
Any minimum-weight spanning tree contains either the edge <a,c> or the edge <b,c>. In either case, it is easy to check that (b), (c), and (d) all fail.
Edit: (a) is true. Here is a proof:
Let e be an edge of M which is of maximum weight in G, and let M be a minimum-weight spanning tree for G containing the edge e. If the edge e cuts the graph G, then (a) is obviously true. So, let G' be obtained from G by removing the edge e, and suppose G' is connected.
Let M' be obtained from M by removing the edge e. Now we know that M' consists of two components, because M is a tree, and removing one edge from a tree disconnects it into two components. Furthermore every vertex of G' belongs to M', and G' is connected, so we can obtain a spanning tree of G' by adding a single edge of G' to M'. I claim that every such edge is of maximum weight in G.
To see why, suppose there is an edge e' in G' which connects the two components of M', but is of sub-maximal weight in G. Then, we could remove the edge e from M (our original spanning tree), add this edge e' to M to obtain a new spanning tree of G, but it would be of total weight less than that of M, contradicting the minimal-weight of M.
So, consider the set of all edges of G' which connect the two components of M'. These edges together with e form an edge-cut-set of G, and all must be of maximal weight in G.
Let's start from the simple ones - d is wrong - take any MST, and reduce one of the weights to some unique new value in some edge (not e) - it's still an MST, but not all edges have the same weight
c is false - if e was heavier that any other edge it would have been true because if it was in a cycle, you could have removed e from the MST (and if required for connectivity - pick any other edge instead and receive a lighter MST). However, e can be in a cycle if the alternative edges are all of the same weight.
b is false - say e is the heaviest, but not in a cycle, just connects the graph to some remote vertice (that isn't connected otherwise).
a - i'm not sure if you meant that the cut is max weight or all the edges of max weight are there (that's not the same thing), please clarify

Directed maximum weighted bipartite matching allowing sharing of start/end vertices

Let G (U u V, E) be a weighted directed bipartite graph (i.e. U and V are the two sets of nodes of the bipartite graph and E contains directed weighted edges from U to V or from V to U). Here is an example:
In this case:
U = {A,B,C}
V = {D,E,F}
E = {(A->E,7), (B->D,1), (C->E,3), (F->A,9)}
Definition: DirectionalMatching (I made up this term just to make things clearer): set of directed edges that may share the start or end vertices. That is, if U->V and U'->V' both belong to a DirectionalMatching then V /= U' and V' /= U but it may be that U = U' or V = V'.
My question: How to efficiently find a DirectionalMatching, as defined above, for a bipartite directional weighted graph which maximizes the sum of the weights of its edges?
By efficiently, I mean polynomial complexity or faster, I already know how to implement a naive brute force approach.
In the example above the maximum weighted DirectionalMatching is: {F->A,C->E,B->D}, with a value of 13.
Formally demonstrating the equivalence of this problem to any other well known problem in graph theory would also be valuable.
Thanks!
Note 1: This question is based on Maximum weighted bipartite matching _with_ directed edges but with the extra relaxation that it is allowed for edges in the matching to share the origin or destination. Since that relaxation makes a big difference, I created an independent question.
Note 2: This is a maximum weight matching. Cardinality (how many edges are present) and the number of vertices covered by the matching is irrelevant for a correct result. Only the maximum weight matters.
Note 2: During my research to solve the problem I found this paper, I think it would be helpful to others trying to find a solution: Alternating cycles and paths in edge-coloured
multigraphs: a survey
Note 3: In case it helps, you can also think of the graph as its equivalent 2-edge coloured undirected bipartite multigraph. The problem formulation would then turn into: Find the set of edges without colour-alternating paths or cycles which has maximum weight sum.
Note 4: I suspect that the problem might be NP-hard, but I am not that experienced with reductions so I haven't managed to prove it yet.
Yet another example:
Imagine you had
4 vertices: {u1, u2} {v1, v2}
4 edges: {u1->v1, u1->v2, u2->v1, v2->u2}
Then, regardless of their weights, u1->v2 and v2->u2 cannot be in the same DirectionalMatching, neither can v2->u2 and u2->v1. However u1->v1 and u1->v2 can, and so can u1->v1 and u2->v1.
Define a new undirected graph G' from G as follows.
G' has a node (A, B) with weight w for each directed edge (A, B) with weight w in G
G' has undirected edge ((A, B),(B, C)) if (A, B) and (B, C) are both directed edges in G
http://en.wikipedia.org/wiki/Line_graph#Line_digraphs
Now find a maximal (weighted) independent vertex set in G'.
http://en.wikipedia.org/wiki/Vertex_independent_set
Edit: stuff after this point only works if all of the edge weights are the same - when the edge weights have different values its a more difficult problem (google "maximum weight independent vertex set" for possible algorithms)
Typically this would be an NP-hard problem. However, G' is a bipartite graph -- it contains only even cycles. Finding the maximal (weighted) independent vertex set in a bipartite graph is not NP-hard.
The algorithm you will run on G' is as follows.
Find the connected components of G', say H_1, H_2, ..., H_k
For each H_i do a 2-coloring (say red and blue) of the nodes. The cookbook approach here is to do a depth-first search on H_i alternating colors. A simple approach would be to color each vertex in H_i based on whether the corresponding edge in G goes from U to V (red) or from V to U (blue).
The two options for which nodes to select from H_i are either all the red nodes or all the blue nodes. Choose the colored node set with higher weight. For example, the red node set has weight equal to H_i.nodes.where(node => node.color == red).sum(node => node.w). Call the higher-weight node set N_i.
Your maximal weighted independent vertex set is now union(N_1, N_2, ..., N_k).
Since each vertex in G' corresponds to one of the directed edges in G, you have your maximal DirectionalMatching.
This problem can be solved in polynomial time using the Hungarian Algorithm. The "proof" by Vor above is wrong.
The method of structuring the problem for the above example is as follows:
D E F
A # 7 9
B 1 # #
C # 3 #
where "#" means negative infinity. You then resolve the matrix using the Hungarian algorithm to determine the maximum matching. You can multiply the numbers by -1 if you want to find a minimum matching.

How to proof by induction that a strongly connected directed graph has at most 2n -2 edges?

I have a directed graph which is strongly connected, but that removing any edge from it makes the graph no longer strongly connected.
How can I prove that such a graph has no more than 2n − 2 edges? (where n ≥ 3)
I've been searching literature for a couple of days but it seems such a proof never been made. Any hints are appreciated.
Here's one outline (details omitted to avoid completely spoiling an exam question).
Prove that the graph G has a simple cycle C.
Prove that every arc in G whose tail and head belong to V(C) belongs to C.
Prove that G/C (graph obtained from G by contracting every arc in C) is strongly connected and that, for all arcs e in G/C, the subgraph G/C - e is not strongly connected.
Conclude by strong induction that G has at most 2|V(G)| - 2 arcs.
To my understanding, you can prove it constructively using a very simple algorithm, and maybe this can help shed some light on a possible proof by induction.
You first pick up an arbitrary node r and run BFS from it - what you get is a directed tree with exactly n-1 edges and n vertices (all reachable from r).
Now, obtain the transposed graph (G^T) from the original, and again run BFS from r - what you get is a directed tree with exactly n-1 edges and n vertices (all reachable from r).
At last, examine each edge in the later tree and add it (reversed) to the first tree (only if not already in it). This step guarantees that r is reachable from every vertex in the graph, and as every vertex is reachable from r - what you get is a strongly connected spanning sub-graph.
Note that we have added at most n-1 edges to the first tree with n-1 to begin with - and hence there are at most n-1 + n-1 = 2n-2 edges in the resulting graph.
This is untrue. Proof by counter-example.
Graph has nodes A, B, and C
A -> B
B -> A
A -> C
B -> C
C -> B
This is strongly connected.
If I removed C->B, then C is isolated (you cannot get to anything from it) and is not strongly connected. Thus I have provided a graph that:
Is strongly connected
Has more than 2n-2 nodes
If I remove one edge, it is no longer strongly connected

Resources