Skip to content

Commit ba00279

Browse files
committed
[ENHANCEMENT] Include Time and Space Complexity Information #698
Added time and space complexity for Bellman-Ford, find cycle and depth first search implementations
1 parent 495cff8 commit ba00279

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

graph/bellmanford.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// It is slower than Dijkstra but capable of handling negative edge weights.
44
// https://en.wikipedia.org/wiki/Bellman%E2%80%93Ford_algorithm
55
// Implementation is based on the book 'Introduction to Algorithms' (CLRS)
6+
// Worst Case Time Complexity: O(V * E)
7+
// Auxiliary Space: O(V)
68

79
package graph
810

graph/cycle.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
package graph
77

8+
// Worst Case Time Complexity: O(V + E)
9+
// Auxiliary Space: O(V)
810
func (g *Graph) HasCycle() bool {
911
//this implimetation referred as 3-color too
1012
all := map[int]struct{}{}
@@ -45,6 +47,8 @@ func (g Graph) hasCycleHelper(v int, all, visiting, visited map[int]struct{}) bo
4547
}
4648

4749
// this function can do HasCycle() job but it is slower
50+
// Worst Case Time Complexity: O(V + E)
51+
// Auxiliary Space: O(V)
4852
func (g *Graph) FindAllCycles() []Graph {
4953
all := map[int]struct{}{}
5054
visiting := map[int]struct{}{}

graph/depthfirstsearch.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Worst Case Time Complexity: O(V + E)
2+
// Auxiliary Space: O(V)
3+
14
package graph
25

36
func GetIdx(target int, nodes []int) int {

0 commit comments

Comments
 (0)