We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 79a9f54 commit 3e9bb9bCopy full SHA for 3e9bb9b
pygorithm/searching/depth_first_search.py
@@ -0,0 +1,17 @@
1
+# Author: OMKAR PATHAK
2
+# Created On: 1st August 2017
3
+
4
+# depth first search algorithm
5
+def dfs(graph, start, path = []):
6
+ # check if graph is empty or start vertex is none
7
+ if start not in graph or graph[start] is None or graph[start] == []:
8
+ return None
9
+ path = path + [start]
10
+ for edge in graph[start]:
11
+ if edge not in path:
12
+ path = dfs(graph, edge, path)
13
+ return path
14
15
+# time complexities
16
+def time_complexities():
17
+ return '''O(V + E) where V = Number of vertices and E = Number of Edges'''
0 commit comments