Johnson Algorithm - Negative cycle check

Johnson Algorithm - Negative cycle check



Original Graph & Modified GraphI am using the BellmanFord algorithm to check the negative cycle for Johnson's algorithm.



The issue is after I add the extra node added with zero weights, the modified graph reports a negative cycle, while the original graph without the extra edge does not have any negative cycle.



My question is whether this can happen? If yes, how to detect negative cycle in Johnson's algorithm?





Are you sure the added edges are directed from the new node to the existing nodes in the graph only and have weight 0? If so, are you sure that Bellman Ford is checking for negative weight cycles only? Maybe it detects 0-weight cycles as well.
– HSK
Aug 23 at 4:21





See the image for the sample graph. The modified graph reports a negative cycle from node 1 to node 2
– shibu thomas
Aug 24 at 8:47




1 Answer
1



If your graph has no negative cycle or no cycle at all, adding a node and connecting it with a zero weight edge to the original graph will not add a cycle, especially not a negative cycle.



But I'm not sure if this is not a misunderstanding. If you just add a zero weight edge to a graph connecting two already existing nodes, this can add a negative cycle.
Just imaging a tree with only negative edge weights. It has no cycles. But if you add a zero weight edge, you close a cycle and since the edge weights are all negative the cycle will also have negative length.



I think in case of Johnson's algorithm you add out-edges from a new node to all existing nodes. So this cannot close any cycles because you can never come back to the new node.





Please see the image. The modified graph now reports a -ve cycle from node 1 to node 2
– shibu thomas
Aug 24 at 8:48





I cannot see a negative cycle in the image. The minimal distance for node 2 is not correct. It should be -1 instead of 0. Since you connect the new node to all other node with zero weight edges, all distances can be at most zero. Have you stopped bellman ford too early? you need an extra round since you have added one node.
– AbcAeffchen
Aug 24 at 9:09






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

How do I collapse sections of code in Visual Studio Code for Windows?

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ