# All paths of length n from a single graph vertex in a directed cyclic graph [duplicate]

Thanks in advance...looking for recommendations on an algorithm to find all paths of length n starting from a single node in a directed, cyclic graph.

I am not concerned with at which node the path completes. i.e. not looking to travel from i to j in a path of a certain length. I would like to start from i and end ultimately with an enumeration of all unique paths emanating from i of length n. These unique paths may or may not contain cycles.

• Why not use BFS? Jul 9, 2015 at 18:53
• @Shaull Thanks for the recommendation. What I am struggling with is how to deal with cycles and their inclusion in all possible paths. I'm not sure BFS with manage that. Jul 9, 2015 at 19:26
• What have you tried? What research have you done? What algorithms have you considered? Are you aware that there can be exponentially many such paths, so any algorithm will necessarily be terribly inefficient in the worst case?
– D.W.
Jul 9, 2015 at 19:37
• @D.W. Thank you for your comment. I am currently researching Floyd Warshall as must current best algorithm candidate but I'm a little rusty on my graph theory thus the ask for a recommendation. I saw the question referenced above and this is a little different in that I am not concerned with at which not the path ends merely that is of length n. Ultimately I'd like to enumerate all unique paths of length n starting from any given node. Jul 9, 2015 at 19:45
• 1. If you see another question that you think is similar but not exactly the same, normally we expect you to mention that in the question (I saw X, but this is different because Y). 2. You can use the techniques there to solve your problem: just iterate through all possible destination nodes, and for each one, use the technique there to find all paths from the source to that destination. The union of those will give you all possible paths starting from the source. So I think the answer to that question does answer your question, too.
– D.W.
Jul 9, 2015 at 19:47