Skip to content

Commit 3e9bb9b

Browse files
committed
Added Depth First Search
1 parent 79a9f54 commit 3e9bb9b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)