diff --git a/graph/bellmanford.go b/graph/bellmanford.go index f130a4e06..7831df633 100644 --- a/graph/bellmanford.go +++ b/graph/bellmanford.go @@ -3,6 +3,8 @@ // It is slower than Dijkstra but capable of handling negative edge weights. // https://en.wikipedia.org/wiki/Bellman%E2%80%93Ford_algorithm // Implementation is based on the book 'Introduction to Algorithms' (CLRS) +// Worst Case Time Complexity: O(V * E) +// Auxiliary Space: O(V) package graph diff --git a/graph/cycle.go b/graph/cycle.go index cf45d1854..df3572a7f 100644 --- a/graph/cycle.go +++ b/graph/cycle.go @@ -5,6 +5,8 @@ package graph +// Worst Case Time Complexity: O(V + E) +// Auxiliary Space: O(V) func (g *Graph) HasCycle() bool { //this implimetation referred as 3-color too all := map[int]struct{}{} @@ -45,6 +47,8 @@ func (g Graph) hasCycleHelper(v int, all, visiting, visited map[int]struct{}) bo } // this function can do HasCycle() job but it is slower +// Worst Case Time Complexity: O(V + E) +// Auxiliary Space: O(V) func (g *Graph) FindAllCycles() []Graph { all := map[int]struct{}{} visiting := map[int]struct{}{} diff --git a/graph/depthfirstsearch.go b/graph/depthfirstsearch.go index c035c79f5..7d06d0f22 100644 --- a/graph/depthfirstsearch.go +++ b/graph/depthfirstsearch.go @@ -1,3 +1,6 @@ +// Worst Case Time Complexity: O(V + E) +// Auxiliary Space: O(V) + package graph func GetIdx(target int, nodes []int) int {