# [erlang-questions] Wanted: A method to find all paths from V1 to V2 using digraph module

Jesper Louis Andersen jesper.louis.andersen@REDACTED
Mon Apr 23 15:56:58 CEST 2018

```On Sun, Apr 22, 2018 at 11:45 PM Vlad Dumitrescu <vladdu55@REDACTED> wrote:

> Hi Bengt,
>
> The solution is to do a search starting from one of the vertices and keep
> track of the found paths (saving a stack of already traversed vertices and
> watching out for cycles), but in the worst case it is an O(n!) algorithm.
> Even in non-pathological cases, it is easy to get an untractable number of
> solutions as the complexity is exponential.
>
>
The obvious algorithm is a breadth-first-search keeping track of the
possible paths in each vertex. But if the number of edges are high, then
this has to visit all the edges.

It might be possible, given assumptions about cycles, to use a variant of
(Floyd-)Warshall's algorithm. Build an "ascendancy matrix", but rather than
processing boolean bits in each matrix cell, track the (number of) paths.
If you can pull this off, then we are closer to something like O(n^3),
though there are obvious flaws given cycles. So it may be you would need to
analyze the incoming data and make sure the graph has a certain structure.

Is the graph directed or undirected? Are all the paths simple (i.e., they
are not allowed to cycle?). I'd also look into graph cuts where you can
divide the graph into two halves, one containing S and one containing T. It
could be the solution count can be based on that number.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180423/bfd846c5/attachment.htm>
```