views:

159

answers:

2

Does anyone know an algorithm for the following problem:

Given a undirected connected graph find the number of ways in which 2 distinct edges can be cut such that the graph becomes disconnected.

I think a part of the problem (which i know an algorithm for) is calculating the number of ways in which 1 line can be cut so that it becomes disconnected. Then computing how these can be grouped with other lines gets the value (M-K)K + K(K-1)/2, M = no. of edges, K = no. of 1 edge cuts.

The part that i don't know how to do is finding the number of other ways to cut 2 line, for example in the graph that has only the cycle 1 - 2 - 3 - 1 any combination of the edges is a valid way of cutting lines to make the graph disconnected.

I coded the part of the program that finds all the 1 edge cuts and then I split the graph into biconnected components by removing those edges. I tried writing something for the second part, made 2 versions for that, but none of them got the right answer on every test.

The number of edges is < 100 000 , and the number of vertexes is < 2000. The program should run maximum 2 seconds on any graph with the above restrictions. Also there can be multiple edges between 2 vertexes.

I can do the first part in O(N+M). I guess the complexity for the second part should be maximum O(N*M).

A: 

The trivial solution: for all pairs of edges remove them from the graph and see if it is still connected. It's O(n^3) but should work.

Marcin
I would need something faster, the number of edges is < 100000 and the number of vertexes is < 2000
Razvi
How do you know you need something faster? Implement this first and see how it works. It is clear that you need at least O(n^2), otherwise you will fail to consider some pair of vertices and we could construct a graph where that particular pair of vertices disconnects the graph.Since you also have to determine connectivity I bet the O(N^3) is close to optimal if not optimal.
Larry Watanabe
How much do you think the program will run for the number of edges = 100 000?
Razvi
Well, 100 000^3 = 1 000 000 000 000 000 = 10^15. Assuming "1" is equal to a microsecond (not a bad assumption) that gives your 31 years. I guess you need something faster.
Marcin
+7  A: 

You are looking for all edge cuts containing two edges. Such edge cuts only exist if the graph is at most 2-edge-connected.

The paper "Efficient algorithm for finding all minimal edge cuts of a nonoriented graph" by Karzanov and Timofeev contains an algorithm for computing all minimal edge cuts of a graph. From a brief look, it seems to me as if the algorithm can also be used to find cuts with a specified number of edges (for example, 2 edges). The complexity of the algorithm is O(lambda n^2), where lambda is the number of edges in the desired cuts (in your case, 2) and n is the number of vertices.

Martin B
N^2 would be a very good complexity for the problem. I'll read about that algorithm :).
Razvi