Блог пользователя sayeed_1999

Автор sayeed_1999, история, 4 года назад, По-английски

The algorithm computes from one source vertex the whole thing.

If i want to detect negative cycles in a graph using bellman ford, if i assume vertex 1 as the source, and no edge comes out of the vertex 1 in that test set, it wont work.

how will you consider source vertex in these cases... to detect negative cycles

Asking for solutions..

  • Проголосовать: нравится
  • +4
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

If no edge comes out from source vertex, then it's not possible to reach any other vertex from this source. The algorithm will work as expected.

  • »
    »
    4 года назад, # ^ |
    Rev. 3   Проголосовать: нравится +5 Проголосовать: не нравится

    I want to run bellman ford to detect negative cycles in a graph, in that case how will i choose the source. as i cant see which should be the source from the test set

    should i consider all vertices as source each time and run!?

    • »
      »
      »
      4 года назад, # ^ |
        Проголосовать: нравится +5 Проголосовать: не нравится

      You can set the initial distance to every node as 0 and run the algorithm. This will be the same as creating a dummy node that goes to every vertex in the graph with 0 cost and using it as source vertex.

      • »
        »
        »
        »
        4 года назад, # ^ |
        Rev. 2   Проголосовать: нравится +8 Проголосовать: не нравится

        Thank you so much!!

        This logic works fine considering a source from which no edge comes out!! O:)

        because in other sense all are the sources here when all are initially zero :p :p