Some time ago, I wrote some code, which uses DFS to find whether there is a path from a source vertex to a destination vertex. However, I am thinking now what if there is more than 1 possible way? What comes to my mind is save paths in an ArrayList as Arralist of integer and then for every path source-destionation check whether it was found already or not? Just like visitting the nodes, mark them as visited. Actually when I think about it, only visitted nodes should be enough won't even need to check whether paths are identical or noth since it won't repeat the visitted nodes path again, but it has to be done in a loop now, what should the stopping condition be? What I do now is using DFS, as soon as the path is found it returns true and the search stops (my dfs is decleared as boolean, just wanted to check whether path exists or not). I guess it has to be similiar to Dijkstra's algorithm for the shortest path if there is cost added between the edges but in this case to display all paths not to return the shortest one? Any suggestions on how to the logic behind not stopping to execute until no unchecked nodes exist? How about having an arraylist with all vertexes, and the arraylist which gets all visited, if i compare the size of those, it should loop until it has been to every vertex right? as in while(!(allVertex.size() == visitedVertex.size()))
, but in this case how would I print out only those paths that reach the destination and not every visited vertex? Sorry for the essay :D
Slavi 94 Master Poster Featured Poster
Slavi 94 Master Poster Featured Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
Slavi 94 Master Poster Featured Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
Taywin 312 Posting Virtuoso
Slavi 94 Master Poster Featured Poster
Hiroshe 499 Posting Whiz in Training
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
Slavi 94 Master Poster Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.