Знаходження принаймні двох шляхів однакової довжини у спрямованому графіку


20

Припустимо, у нас є спрямований графік та два вузлиG=(V,E)A and B. I would like to know if there are already algorithms for calculating the following decision problem:

Are there at least two paths between A and B of the same length?

How about the complexity? Can I solve it in polynomial time?


I would like to add a new constrain on the graph, maybe the problem is more solvable. On adjacency matrix, every column is not empty. So, every node has at least one arrow on input and there is also at least one node connected to itself. So if the node is the i-th node, then (i,i) is an edge in the graph.


Did you mean simple paths? (visiting each node at most one time), Also are they allowed to have a common internal node?

1
no, there are no restriction on paths. you may loop, if you want.
Paolo Parisen T.

Easy observation is this: if there is just one simple path between A,B, and this simple path is connected to at most one loop, you could simply say No, If there is at least two loops of different length connected to this simple path, you could say yes, .... (I think similar things are useful and you could prove it), But in the case of disjoint simple paths (if during prove of this you encountered to disjoint simple paths), it's NPC.

1
@mrm: I don't see this as a duplicate. Asking for all walks is a massively time consuming operation (in general, there are an infinite number of walks), whereas the OP is asking for two (simple) paths, not all walks.
Dave Clarke

Відповіді:


10

Consider a graph G, we want to know if there are two different paths from A to B of the same length. What to do? Simple: code two paths in one. Define graph G with vertices V×V×{0,1}. You make a step in G by making two independent steps in G. The additional bit tells you whether the two paths have already split from each other.

Formally, there is an edge (i,j,e)(i,j,e) in G iff ii, jj in G and e=e(i,i)(j,j).

The algorithm checks if there is a path (A,A,0) to (B,B,1) in G, which is O(V4), or something like O((V+E)2).

If you agree this algorithm is correct then, as a consequence, the path in G is of length at most 2n2, therefore potential "path collisions" must occur latest at that length. You can get a O(VωlogV) algorithm from this observation, where ω is matrix multiplication complexity (ask if you need a spoiler...).

I strongly feel there is a O(V+E) algorithm, which uses more of the structure of the problem.


3
That's elegant.
Raphael

4

Probably i've an answer for this problem, but i'm not sill sure that it works.

It is not important to "find" the two path, the only important thing is to "know" if they exist or not. I don't think that this is an NP complete problem.

So, take the adjacency matrix A. We can easily suppose that it is filled with 0,1 value. (0 = no edge; 1 = there is an edge) Let's use the following algebra with 3 values (0,1,2), where everything works as usual except: 2+<something>=2; 2<whatever greater than 0>=2

So, if there are two paths of same length from i,j i'm expecting that there is a value p such that (Ap)i,j=2.

Let n is the number of vertex in the graph (or, let's say, that A has dimension n×n). I don't know the value of p, but if i iterate A by multiplying with itself for at most n2 i should find the answer. (so, p<n2) (the sense is that i check A, then i check A2, then i check A3 and so on...)

here is my argumentation:

  • if the two paths are simple paths, well, it works; if there are, at most i have to iterate n times.
  • If there is at least one neasted cycle or there is a path with two cycles, well, i have to find the least common multiple (LCM). n2 is a bigger value for sure and in less than n2 times if there is i should have to find them.
  • If the two paths are two distinct paths, both with one cycle, then it's more or less similar to finding a solution for this two equation: α+βm=γ+δk, where m and k are the length of these two distinct cycles. Matrix multiplication Aq, as defined above, says "is there a path from i to j whose length is q?" So, if Aq is grater than 1 it means that there are more paths leading from i to j. By iterating the matrix n2 times we pass through all the possible combination of δ and β. Indeed, LCM(a,b) is defined as (ab)/GCD(a,b) and no cycle can be greater than n.

I stop to iterate once i found (Ap)i,j=2.

am i wrong?


I tried the same and I encountered some problems/uncertainties: 1) What if the paths are connected to more than one cycle? Do you have to "check" all combinations (in the worst case, every node lies on exponentially many cycles!), blowing up the upper bound, or is it sufficient to consider only one for each? 2) Because of the constant offsets α and γ, is the LCM really an upper bound?
Raphael

By the way, there is no need for a funky algebra: just stop the moment you compute a 2 as matrix entry.
Raphael

@Raphae 1) if there is a path with two cycles, then there are for sure two path of same lenght. one that loops on first cycle and one that loops on second. how much do they have to loop? exactely the LCM of the lenght of both cycles. this is bounded by n2, where n is the number of vertexes in the graph. 2) LCM is the upper bound (in the case 1)) because LCM(a,b) is bounded by a*b plus α and γ offsets; so, in total we have LCM(a,b)+α+γ<ab+α+γ. we know that α+γ+a+b<n, so ab+α+γ is less than n2.
Paolo Parisen T.
Використовуючи наш веб-сайт, ви визнаєте, що прочитали та зрозуміли наші Політику щодо файлів cookie та Політику конфіденційності.
Licensed under cc by-sa 3.0 with attribution required.