From 41c6783a2057198d08c75d8b3220cdee5d7bb2df Mon Sep 17 00:00:00 2001 From: kortschak Date: Sat, 6 Jun 2015 19:12:45 +0930 Subject: [PATCH] search: add time complexity notes --- search/bellman_ford_moore.go | 2 ++ search/dijkstra.go | 4 ++++ search/floydwarshall.go | 2 ++ search/johnson_apsp.go | 2 ++ 4 files changed, 10 insertions(+) diff --git a/search/bellman_ford_moore.go b/search/bellman_ford_moore.go index b8339623..30937f21 100644 --- a/search/bellman_ford_moore.go +++ b/search/bellman_ford_moore.go @@ -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 diff --git a/search/dijkstra.go b/search/dijkstra.go index 197276ec..a738a6cf 100644 --- a/search/dijkstra.go +++ b/search/dijkstra.go @@ -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} @@ -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 diff --git a/search/floydwarshall.go b/search/floydwarshall.go index df36d5ad..deaab2b6 100644 --- a/search/floydwarshall.go +++ b/search/floydwarshall.go @@ -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 diff --git a/search/johnson_apsp.go b/search/johnson_apsp.go index 63bdb666..78280ea0 100644 --- a/search/johnson_apsp.go +++ b/search/johnson_apsp.go @@ -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 JonsonAllPaths is O(|V|.|E|+|V|^2.log|V|). func JohnsonAllPaths(g graph.Graph, weight graph.CostFunc) (paths ShortestPaths, ok bool) { jg := johnsonWeightAdjuster{ g: g,