Possible Duplicate:
Find the paths between two given nodes?
Given a directed graph, how to find ALL the possible paths between two nodes and return those paths.
If not in Java, please recommend me with the algorithm for it. I searched and what I found is using BFS or DFS, but I'm not able to see which is better in my case. And how to keep track of all paths not only the shortest one.
For example, given the following graph:
1 -> 2
1 -> 3
2 -> 3
3 -> 4
For paths between nodes 1 and 4, the output should be:
First Path: 1 -> 2 -> 3 -> 4
Second Path: 1 -> 3 -> 4