0

What's the best way to find all possible paths in a given tree? Let's say I have a graph where a path exists between the following nodes

1,2

1,3

2,5

2,6

So I should get an output somewhat like this:- 1

1,2

1,3

1,2,5

1,2,6

2

2,5

2,6

2,1,3

and so on..

  • The best way is to go for it. It is quite simple: just pick any node, perform a traversal from that node (like DFS) and keep outputting what you have. Repeat for other nodes as starting point. – trincot Apr 11 '20 at 20:54
  • Is this a tree or a graph? A tree is a directed acyclic graph. So if there's a path `1,2`, there can't be a path `2,1`. – Jim Mischel Apr 12 '20 at 05:03

0 Answers0