minimum cost to make an undirected graph disconnected - algorithm

What is the minimum cost to make an undirected weighted(positive weight) graph disconnected.
i mean i have to find out those edges which removal disconnect the graph and their cost is minimized.
I have following ideas...
1.find out all the bridges of the graph . then the bridge edge of minimum weight wiil be the ans.
2.if there is no bridge that means all the nodes are in a cycle(i'm not sure about it). then i sort the edge according to their weight and the sum of the two minimum edge weight will be the ans.
The graph has no self loop.
Is this algo correct?

This question looks to be the same question answered by the study of "minimum cuts" in graphs. I would recommend the following reading here and here to learn more about why it works from a graph theoretic point of view - the link provides some pseudocode as well.
Regarding your proposed algorithm, finding the bridges in a graph may get tricky.. you would have to inspect both endpoints and their local structure to confirm the existence of a bridge.. using edge contraction perhaps would be simpler to implement.

Related

Finding strongly connected subgraph that contains no negative cycles

Is there an algorithm that solves the following decision problem:
Given a strongly connected weighted directed graph G, defined by its transition matrix, is there a strongly connected spanning subgraph of G that has no negative cycles?
A strongly connected spanning subgraph of G is a strongly connected subgraph of G that shares the same vertexes with G. You can look to this paper for the definition of strongly connected spanning subgraph. In this paper they present an approximation for the minimum strongly connected subgraph problem.
A naive approach to this problem is to find a negative cycle of the graph using the Ford-Bellman or Floyd-Warshall algorithm, deleting an edge from this cycle, and repeating while the graph is still strongly connected. But this naive approach has poor time complexity because we will potentially run the Ford-bellman algorithm and check for strong connectivity many times -- moreover I am unable to prove if this algorithm is correct in all instances.
I'm hoping to find experts here who can tell me if this decision problem can be solved in a polynomial time and what algorithm does so. Many thanks in advance.
Here is a naive solution that has a reasonable chance of finding a strongly connecting spanning subgraph with no negative cycles in polynomial time. But is emphatically not guaranteed to find one.
Turn all weights to their negatives. Now use Ford-Bellman or Floyd-Warshall to find a negative cycle. This is actually a positive cycle in the original graph.
Now we pick one vertex in the cycle, and contract the other vertices to it.
Edges that connect to/from removed vertices are replaced by ones representing traveling along that edge and around the cycle to the one we keep. If you wind up with multiple edges between two vertices, only keep the best one.
Repeat the exercise on the new, smaller, graph.
This algorithm runs in guaranteed polynomial time (each iteration runs in polynomial time and removes at least one vertex). If it manages to reduce your graph to a point, then you just walk the process backwards and find that you have in fact found a strongly connected spanning graph with no negative cycles.
However if it fails to do so, there is no guarantee that there isn't one. You just didn't find it.
(I suspect that a guaranteed algorithm will be NP-complete.)
This problem is NP hard in general, this can be proven by reducing Hamiltonian cycle into it.

How can I add resilience to a minimum spanning tree?

I have a complete, weighted, undirected graph. The edge weights are the cost of a connection between two nodes, so the minimum spanning tree is the subset of the edges with the lowest total cost such that the graph remains connected.
The MST must be connected at all times, but unfortunately the connections aren't very reliable, so I would like to add redundancy to this graph/network.
Is it possible to compute a subset of edges such that the total edge cost is minimised and edge-connectivity is over a certain minimum?
I can see how it would be possible by bruteforcing, but I was looking for something more practical. I haven't been able to find much about this problem, I think mainly because I don't posses the vocabulary necessary to search.
My current idea is:
Compute the MST
While the it is still below a certain connectivity
Find a node most below that connectivity
Activate that node's edge with the lowest weight
The reason I don't find all the nodes below a certain connectivity all at once is because activating an edge may give another one enough connectivity.
I'm pretty sure this does not yield 100% provably optimal networks, because with this method, it is possible to over-connect nodes (e.g. you activate k edges for a node, then another node activates more shared edges, making some of those k redundant). I hope that makes sense.
Any tips would be much appreciated!
The Wikipedia article on edge connected graphs ends with, A related problem: finding the minimum k-edge-connected spanning subgraph of G (that is: select as few as possible edges in G that your selection is k-edge-connected) is NP-hard for k >= 2. They then cite a 1979 paper that shows it.
Therefore I'd suggest taking a greedy approach, and tip-toeing away.

Make an undirected graph a strongly connected component (SCC)

Let G(V,E), an undirected, connected graph with no bridges at all. Describe an algorithm which direct the edges, so the new graph is an SCC.
My suggested algorithm
So we run DFS from an arbitrary vertex. We notice that since it's an undirected graph there are only tree-edges and back-edges (Right?). We connect edges accordingly (a tree-edge would be directed "down" and a back-edge would be directed "up").
A start of proof
We notice that the graph has no bridges. Therefore, every edge is part of some cycle. Therefore, the last edge to be discovered in some cycle must be a back-edge.
Now, I think the rest of the proof would need to show that we can always "climb" to the root, and so the graph is an SCC.
I'd be glad if you could help me connect the dots (or vertices XD)
Thanks
What you are looking for is a proof for Robbins' Theorem.
For a more formal proof you can look at this paper (See proof for theorem 2).
The below is not a formal proof but it's a way you can think of it:
As you already mentioned, since there are no bridges, every edge is a part of some cycle. Since you want your output graph to be SCC, a DFS on this output graph (from any vertex) must only have back-edges and tree-edges. It cannot have forward-edges or cross-edges.
Lets assume we have a forward-edge from s to t. This means that in the DFS we ran in order to build the graph, t was discovered in the sub-DFS (recursive call) of s and had no other gray or white adjacents. But this is not true because whenever we discover t in our DFS we would still have a gray adjacent.
Lets assume we have a cross-edge from s to t. This means that t's sub-DFS has ended before s was discovered. Again, this cannot happen in our DFS because either when discovering t first we would discover s in its sub-DFS or the opposite direction.
Here is a simple graph to help you see those cases.

Pairs of Vertices Unreachable from Each Other in a Directed Graph

I am requested to design an algorithm to determine whether there exists any pair of vertices unreachable from each other in a directed graph. The algorithm must run in O(|V| + |E|) time
Meaning: vertex i cannot reach vertex j, and vertex j cannot reach vertex i.
I have read about the method for finding strongly connected components, I wonder whether or not I can start from there and devise an algorithm usable under the current circumstance?
If you can find all strongly connected components in the linear O(V + E) time requested then you are done. This may seem a bit overkill but it solves the problem. To find all strongly connected components, assuming your graph is represented as an adjacency list, perhaps the simplest O(V + E) linear time algorithm is Kosaraju's, see e.g. http://en.wikipedia.org/wiki/Kosaraju%27s_algorithm
Once you find all strongly connected components, then it is fairly simple to test whether there is a pair of strongly connected components that is not connected by any path, by considering the condensed graph where nodes are strongly connected components and an edge exists if there is an edge between any two nodes chosen from the two connected components.
Here are a few hints to help you get started:
Try solving this problem first when the graph you're given is a DAG. What does the structure of the DAG have to be in order for any pair of nodes to be at least weakly connected?
If you compute the strongly-connected components of a graph, those SCCs themselves form a DAG. Could you use this observation, in conjunction with your algorithm for part (1), to form an algorithm that works on arbitrary graphs?
Hope this helps!
If you are able to find the strongly connected components then you conversely know the vertices that are not connected as well.
The wiki: http://en.wikipedia.org/wiki/Kosaraju%27s_algorithm is pretty instructive. I have implemented the algorithm and it is available here. Runs in O (v + E ). We are assuming that the graph is backed as an adjacency list.
Link for Kosaraju Implementation in Java
Try it out, hopefully you would find no bugs :-)

Minimal path - all edges at least once

I have directed graph with lot of cycles, probably strongly connected, and I need to get a minimal cycle from it. I mean I need to get cycle, which is the shortest cycle in graph, and every edge is covered at least once.
I have been searching for some algorithm or some theoretical background, but only thing I have found is Chinese postman algorithm. But this solution is not for directed graph.
Can anybody help me? Thanks
Edit>> All edges of that graph have the same cost - for instance 1
Take a look at this paper - Directed Chinese Postman Problem. That is the correct problem classification though (assuming there are no more restrictions).
If you're just reading into theory, take a good read at this page, which is from the Algorithms Design Manual.
Key quote (the second half for the directed version):
The optimal postman tour can be constructed by adding the appropriate edges to the graph G so as to make it Eulerian. Specifically, we find the shortest path between each pair of odd-degree vertices in G. Adding a path between two odd-degree vertices in G turns both of them to even-degree, thus moving us closer to an Eulerian graph. Finding the best set of shortest paths to add to G reduces to identifying a minimum-weight perfect matching in a graph on the odd-degree vertices, where the weight of edge (i,j) is the length of the shortest path from i to j. For directed graphs, this can be solved using bipartite matching, where the vertices are partitioned depending on whether they have more ingoing or outgoing edges. Once the graph is Eulerian, the actual cycle can be extracted in linear time using the procedure described above.
I doubt that it's optimal, but you could do a queue based search assuming the graph is guaranteed to have a cycle. Each queue entry would contain a list of nodes representing paths. When you take an element off the queue, add all possible next steps to the queue, ensuring you are not re-visiting nodes. If the last node is the same as the first node, you've found the minimum cycle.
what you are looking for is called "Eulerian path". You can google it to find enough info, basics are here
And about algorithm, there is an algorithm called Fleury's algorithm, google for it or take a look here
I think it might be worth while just simply writing which vertices are odd and then find which combo of them will lead to the least amount of extra time (if the weights are for times or distances) then the total length will be every edge weight plus the extra. For example, if the odd order vertices are A,B,C,D try AB&CD then AC&BD and so on. (I'm not sure if this is a specifically named method, it just worked for me).
edit: just realised this mostly only works for undirected graphs.
The special case in which the network consists entirely of directed edges can be solved in polynomial time. I think the original paper is Matching, Euler tours and the Chinese postman (1973) - a clear description of the algorithm for the directed graph problem begins on page 115 (page 28 of the pdf):
When all of the edges of a connected graph are directed and the graph
is symmetric, there is a particularly simple and attractive algorithm for
specifying an Euler tour...
The algorithm to find an Euler tour in a directed, symmetric, connected graph G is to first find a spanning arborescence of G. Then, at
any node n, except the root r of the arborescence, specify any order for
the edges directed away from n so long as the edge of the arborescence
is last in the ordering. For the root r, specify any order at all for the
edges directed away from r.
This algorithm was used by van Aardenne-Ehrenfest and de Bruin to
enumerate all Euler tours in a certain directed graph [ 1 ].

Resources