forked from OmkarPathak/pygorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdepth_first_search.py
More file actions
45 lines (36 loc) · 895 Bytes
/
depth_first_search.py
File metadata and controls
45 lines (36 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""
Author: OMKAR PATHAK
Created On: 1st August 2017
"""
import inspect
def search(graph, start, path=[]):
"""
depth first search algorithm
:param graph:
:param start:
:param path:
:return:
"""
# check if graph is empty or start vertex is none
if start not in graph or graph[start] is None or graph[start] == []:
return path
path = path + [start]
for edge in graph[start]:
if edge not in path:
path = search(graph, edge, path)
return path
# TODO: Are these necessary?
def time_complexities():
"""
Return information on functions
time complexity
:return: string
"""
return "O(V + E) where V = Number of vertices and E = Number of Edges"
def get_code():
"""
easily retrieve the source code
of the function
:return: source code
"""
return inspect.getsource(search)