Skip to content
This repository has been archived by the owner on Apr 26, 2019. It is now read-only.

Commit

Permalink
search: add time complexity notes
Browse files Browse the repository at this point in the history
  • Loading branch information
kortschak committed Jun 8, 2015
1 parent 2babe18 commit 83cfacf
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions search/bellman_ford_moore.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import "github.com/gonum/graph"
// BellmanFordFrom returns a shortest-path tree for a shortest path from u to all nodes in
// the graph g, or false indicating that a negative cycle exists in the graph. If weight
// is nil and the graph does not implement graph.Coster, UniformCost is used.
//
// The time complexity of BellmanFordFrom is O(|V|.|E|).
func BellmanFordFrom(u graph.Node, g graph.Graph, weight graph.CostFunc) (path Shortest, ok bool) {
if !g.NodeExists(u) {
return Shortest{from: u}, true
Expand Down
4 changes: 4 additions & 0 deletions search/dijkstra.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
// DijkstraFrom returns a shortest-path tree for a shortest path from u to all nodes in
// the graph g. If weight is nil and the graph does not implement graph.Coster, UniformCost
// is used. DijkstraFrom will panic if g has a u-reachable negative edge weight.
//
// The time complexity of DijkstrFrom is O(|E|+|V|.log|V|).
func DijkstraFrom(u graph.Node, g graph.Graph, weight graph.CostFunc) Shortest {
if !g.NodeExists(u) {
return Shortest{from: u}
Expand Down Expand Up @@ -73,6 +75,8 @@ func DijkstraFrom(u graph.Node, g graph.Graph, weight graph.CostFunc) Shortest {
// DijkstraAllPaths returns a shortest-path tree for shortest paths in the graph g.
// If weight is nil and the graph does not implement graph.Coster, UniformCost is used.
// DijkstraAllPaths will panic if g has a negative edge weight.
//
// The time complexity of DijkstrAllPaths is O(|V|.|E|+|V|^2.log|V|).
func DijkstraAllPaths(g graph.Graph, weight graph.CostFunc) (paths ShortestPaths) {
var (
from = g.Neighbors
Expand Down
2 changes: 2 additions & 0 deletions search/floydwarshall.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
// FloydWarshall returns a shortest-path tree for the graph g or false indicating
// that a negative cycle exists in the graph. If weight is nil and the graph does not
// implement graph.Coster, UniformCost is used.
//
// The time complexity of FloydWarshall is O(|V|^3).
func FloydWarshall(g graph.Graph, weight graph.CostFunc) (paths ShortestPaths, ok bool) {
var (
from = g.Neighbors
Expand Down
2 changes: 2 additions & 0 deletions search/johnson_apsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (

// JohnsonAllPaths returns a shortest-path tree for shortest paths in the graph g.
// If weight is nil and the graph does not implement graph.Coster, UniformCost is used.
//
// The time complexity of JohnsonAllPaths is O(|V|.|E|+|V|^2.log|V|).
func JohnsonAllPaths(g graph.Graph, weight graph.CostFunc) (paths ShortestPaths, ok bool) {
jg := johnsonWeightAdjuster{
g: g,
Expand Down

0 comments on commit 83cfacf

Please sign in to comment.