There is an easy way to partition the set of ss-tt paths in a graph GG. Fix an edge tt′tt′ in GG. Let P1P1 be the set of paths from ss to tt which use the edge tt′tt′, and let P2P2 be the set of paths from ss to tt in G−tt′G−tt′. Then P1capP2=emptysetP1capP2=emptyset and the set of ss-tt paths P=P1cupP2P=P1cupP2. Moreover, there is a one to one correspondence between the set of paths P1P1 and the set of ss-t′t′ paths in the graph G−tG−t.
Thus, we get an easy recursive algorithm to find the set of paths ss-tt paths in a graph GG. Pick an edge tt′tt′ incident the vertex tt and recursively calculate the sets P1P1 and P2P2. With a small amount of pre-processing, we can ensure that the runtime is O(m(p+1))O(m(p+1)) where mm is the number of edges and pp is the number of ss-tt paths.
To make the recurrence relation on the runtime work, consider the following. We can test in time O(m)O(m) if a given graph GG and pair of vertices ss and tt if GG has 0, exactly one, or at least two distinct ss-tt paths. To see this, simply find the block decomposition of the graph and, and check if there is any non-trivial block between ss and tt in the tree.
We can push this slightly farther. Given an instance of the problem GG and vertices ss and tt, we can reduce the problem in time O(m)O(m) to a graph barGbarG and vertices xx and yy such that for all edges xx′xx′ incident to xx, we have that
- xx′xx′ is in some yy-xx path,
- there exists a yy-x′x′ path in barG−xbarG−x.
To see this, again using the block decomposition, we contract any bridge in the graph and delete edges not contained in any ss-tt path. As above, this can be done in O(m)O(m) time.
We give an O(m(p−1))O(m(p−1)) time algorithm to find the set of ss-tt paths in a given graph GG with at least two ss-tt paths.
- We may assume, as above, that every edge tt′tt′ incident to tt is contained in some ss-tt path and that there exists at least one ss-t′t′ path in G−tG−t.
- Check if the number of ss-tt paths in G−tt′G−tt′ is at least two, and if not, let P1P1 be the set of the unique ss-tt path in G−tt′G−tt′. If there are at least two such paths, we recursively find the set of all such paths. Let p1=|P1|. By choice of tt′, p1ge1.
- Check if the number of s-t′ paths in G−t is at least two, and if not let P2 be the set of the unique s-t′ path in G−t. Otherwise, we recursively find the set P2 of s-t′ path in G−t. Let p2=|P2|, and as above, we again have p2ge1.
Step 1 can be performed in c′m operations for some constant c′. The initial check in steps 2 and 3 can be performed in c′(m−1) steps. If we must recursively run the algorithm, this will require another c(m−1)(pi−1) operations for i=1,2 in Steps 2 and 3, respectively. As pige1, we can bound the work in each of Steps 2 and 3 by c′m+cm(pi−1). Thus, the total number of operations is at most 3c′m+c(m)(p1+p2−2)lecm(p−1) if we choose cge3c′.
No comments:
Post a Comment