Skip to content

Commit

Permalink
graph/path: fix comments in BellmanFordFrom
Browse files Browse the repository at this point in the history
  • Loading branch information
kortschak committed Jul 2, 2020
1 parent 1236d60 commit 18a9c3e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions graph/path/bellman_ford_moore.go
Expand Up @@ -31,11 +31,13 @@ func BellmanFordFrom(u graph.Node, g graph.Graph) (path Shortest, ok bool) {
path.dist[path.indexOf[u.ID()]] = 0

// Queue to keep track which nodes need to be relaxed.
// Only nodes whose vertex distance changed in the previous iterations need to be relaxed again.
// Only nodes whose vertex distance changed in the previous iterations
// need to be relaxed again.
queue := newBellmanFordQueue(path.indexOf)
queue.enqueue(u)

// The maximum of edges in a graph is |V| * (|V|-1) which is also the worst case complexity.
// The maximum number of edges in a graph is |V| * (|V|-1) which is also
// the worst case complexity.
// If the queue-loop has more iterations than the amount of maximum edges
// it indicates that we have a negative cycle.
maxEdges := len(nodes) * (len(nodes) - 1)
Expand Down

0 comments on commit 18a9c3e

Please sign in to comment.