0

How can I find all available path for each Vertices which won't cause a cycle? What algorithm to use? Please be brief and provide links if possible, and ask questions if something is not clear from the wonderful diagram below :) asdas

I am not looking for a shortest path or anything like that. Instead I just want to know which paths I can still draw on my graph without causing a loop/cycle. For example L4 can goto L1, L2, L5 AND L2 can goto L5...and so on....

I guess I want a Directed acyclic graph and need help finding out which algorithm to use and how?

7
  • 1
    In your example, how can L4 goto L5? Commented Oct 15, 2010 at 7:23
  • No it is not homework. Just haven't used any of the algorithm for a while and have a need to use one now. So I thought what better place to learn than the wonderful SO :) Commented Oct 15, 2010 at 7:23
  • @Amit S: You would draw a line from L4 to L5 with the arrow pointing at L5 :) Commented Oct 15, 2010 at 7:26
  • @VoodooChild: My bad. I didn't read your question properly. Commented Oct 15, 2010 at 7:29
  • @Amit S: No big deal, I thought maybe I might have made an error in my question. Commented Oct 15, 2010 at 7:33

3 Answers 3

2

A shortest-path algorithm like Bellman-Ford or Dijkstra has the side effect of telling you which nodes you can reach from a given node "A" -- which is exactly the list of nodes from which edges to "A" would form a loop.

I suspect there is a way to modify Bellman-Ford to generate all these lists in one go, instead of running the algorithm separately for every node, but I'll leave that as an exercise for the reader. :)

Sign up to request clarification or add additional context in comments.

Comments

1

Look the Ford Algorithm

http://en.wikipedia.org/wiki/Bellman%E2%80%93Ford_algorithm

Enjoy',

Comments

1

Following is not the answer but just a way to think for this problem.
You can think for the problem from the opposite side. Find all the paths that have exactly one edge missing to form a cycle(I havn't think of it, how). Then those missing edges are not the edges you are looking. Accept everything other than that.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.