patternModerate
Finding at least two paths of same length in a directed graph
Viewed 0 times
samegraphlengthpathsdirectedtwoleastfinding
Problem
Suppose we have a directed graph $G=(V,E)$ and two nodes $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.
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.
Solution
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 \times V \times \{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) \to (i',j',e')$ in $G'$ iff $i \to i'$, $j \to j'$ 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(V^4)$, 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 $2n^2$, therefore potential "path collisions" must occur latest at that length. You can get a $O(V^{\omega} \log V)$ algorithm from this observation, where $\omega$ 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.
Formally, there is an edge $(i,j,e) \to (i',j',e')$ in $G'$ iff $i \to i'$, $j \to j'$ 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(V^4)$, 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 $2n^2$, therefore potential "path collisions" must occur latest at that length. You can get a $O(V^{\omega} \log V)$ algorithm from this observation, where $\omega$ 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.
Context
StackExchange Computer Science Q#2498, answer score: 10
Revisions (0)
No revisions yet.