2

I'm working on implementing the floyd warshall algorithm. I apply this algorithm on a graph with different vertices and some of them are not linked. My code isn't getting the right answer.

The final path generated from one vertex to another sometimes includes an edge which doesn't exist. I think my error comes from the fact that I compare infinity to infinity. I currently do that: I assume that a big integer will represent infinity for example 10000. What should I do when I met a situation like that 10000 > 10000 + n? with n < 10000

Stefan Kendall
  • 66,414
  • 68
  • 253
  • 406
mel
  • 2,730
  • 8
  • 35
  • 70

1 Answers1

1

The longest possible valid path can have length = (n - 1) * 1000. Thus, "infinity" must be strictly greater than this value. And there is no need to handle it specially as long as 2 * infinity fits into the type you are using to store distances.

kraskevich
  • 18,368
  • 4
  • 33
  • 45
  • Ok so if my number of vertex is 7 and i met a case like that: 10000 > 10000 + 450; Should I do a similar thing that if I would have met: 300> 100 +50; – mel Jan 13 '15 at 18:51
  • @mel I do not get your question. How do you implement Floyd-Warshall algorithm? In the implementation I usually use there is no need to handle infinity in a special way. – kraskevich Jan 13 '15 at 19:00