Skip to content

Commit 60cd296

Browse files
committed
add space complexity
1 parent dd69d42 commit 60cd296

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Graphs/graphs_dfs.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
The time complexity of the DFS algorithm is O(V + E), where V is the number of vertices (nodes) and E is the number of
2121
edges in the graph. This is because the algorithm visits every vertex and every edge once.
2222
23+
The space complexity of DFS depends on the maximum depth of the recursion stack. In the worst case, where the tree or
24+
graph is completely unbalanced, the recursion stack can reach a depth of O(n), where n is the number of nodes in the graph.
25+
Therefore, the space complexity of DFS is O(n).
26+
2327
*/
2428
package main
2529

0 commit comments

Comments
 (0)