• Post Reply Bookmark Topic Watch Topic
  • New Topic

Finding All Paths in a Graph  RSS feed

 
Greenhorn
Posts: 16
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am using the recursive method below in a program to find all the non-looping paths between two vertices in a directed graph. Currently, the stopping case is when the current vertex is equal to the destination vertex. It works fine when finding all the paths between two different vertices, but obviously doesn't work when looking for the paths between a vertex and itself. I was wondering if anyone might have some advice on how to modify the method below to allow the method to find all the paths between a vertex and itself in a cyclic graph without repeating any vertices except the starting and ending vertex (for example 1-2-3-1 would be okay but not 1-3-1-3-4-1). I am still having quite a difficult time with recursion so any tips you might have would be much appreciated.

 
Jaime Alnwick
Greenhorn
Posts: 16
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never mind, I think I came up with a solution. Sorry, for some reason sometimes just asking the question helps me find an answer.

 
Marshal
Posts: 56600
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jaime Alnwick wrote:. . . Sorry, for some reason sometimes just asking the question helps me find an answer. . . .
That is called rubber‑duck programming.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!