* How do you count paths with potential loops?* How do you detect loops, and how do you break out of them?* Under what conditions can you state that all paths have been found?

And, most importantly:* Why do you want to base this on Dijkstra's algorithm, which is designed to find a single shortest-path? Surely there are better options for your base implementation. A quick Google search suggests a breadth-first search might be in order, and that you'd probably want to choose an arbitrary upper-bound for the path length to prevent infinite recursion (pruning loops would also help, of course).

Just to correct some terminology, a loop is an edge from a vertex to itself and a path by definition doesn't reach any vertex twice. Using this definition of path, OP, you must realize that there may be exponentially (in the number of vertices + edges in the graph) many paths between two vertices (even in simple graphs). For example, consider graphs like this:

Code:

* * / \ / \* * *... \ / \ / * *

So you can't reasonably get all the paths between two vertices in general.

So after you've labeled your nodes instead of picking one and moving on, you just arbitrarily number them and recursively call each node, that way it'll look at everything seems like it could get pretty hairy pretty quickly if it's a big graph.

So after you've labeled your nodes instead of picking one and moving on, you just arbitrarily number them and recursively call each node, that way it'll look at everything seems like it could get pretty hairy pretty quickly if it's a big graph.

I'm starting to think the same, for more complicated graph that can be hairy with recursion so maybe modifing dijkstra is not a good idea...So is there other algorithm more suited for finding all paths? I have read somewhere that BFS could do it but it also need to be modified

p.s.my test graph is like this: A->B9(5),B->C(4),C->D(8),D->C(8),D->E(6),A->D(5),C->E(2),E->B(3),A->E(7)weight or distance is in parentheses

I'm starting to think the same, for more complicated graph that can be hairy with recursion so maybe modifing dijkstra is not a good idea...So is there other algorithm more suited for finding all paths?

I hope you realize how odd this request really is. You're asking for an optimized algorithm to do exactly what pathfinding algorithms are optimized to avoid doing: searching all the possible paths.

At a brief glance it looks like Orionpaul has the right idea. Recursive DFS? BFS? I don't think you're going to be required to do anything more clever than that for what is clearly a homework problem.