I am attempting to implement an "all paths" algorithm described in this question's top answer using Python.
So far, I have defined the function as such:
def AllPaths(start, end, edges):
print(start)
if (start == end):
return
for i in range(0, len(edges)):
if edges[i][1] == start:
AllPaths(edges[i][0], end, edges)
I have included print(start)
to try give myself an idea of the function's behaviour.
For example, if the initial function call is as such:
edges = [ (1, 2), (1, 3), (2, 3), (3, 4) ]
AllPaths(edges[len(edges) - 1][1], edges[0][0], edges)
With the starting node being 4 and the ending node being 1, the output of the function is:
4
3
1
2
1
Somewhere in that output, it is telling me that all paths between node 4 and node 1 consists of:
[ (4, 3), (3, 1) ]
[ (4, 3), (3, 2), (2, 1) ]
But how do I form these collections during execution and, if I wanted to keep track of how many distinct paths there are, how would this be counted during execution?