Skip to content

Commit e2318e4

Browse files
authored
Merge pull request OmkarPathak#4 from vhag/master
Added consistant function names for BFS and DFS
2 parents f492ced + b7a5c1c commit e2318e4

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

pygorithm/searching/breadth_first_search.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Created On: 1st August 2017
33

44
# breadth first search algorithm
5-
def bfs(graph, startVertex):
5+
def search(graph, startVertex):
66
# Take a list for stoting already visited vertexes
77
if startVertex not in graph or graph[startVertex] is None or graph[startVertex] == []:
88
return None
@@ -25,4 +25,4 @@ def time_complexities():
2525
# easily retrieve the source code of the bfs function
2626
def get_code():
2727
import inspect
28-
return inspect.getsource(bfs)
28+
return inspect.getsource(search)

pygorithm/searching/depth_first_search.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Created On: 1st August 2017
33

44
# depth first search algorithm
5-
def dfs(graph, start, path = []):
5+
def search(graph, start, path = []):
66
# check if graph is empty or start vertex is none
77
if start not in graph or graph[start] is None or graph[start] == []:
88
return None
@@ -19,4 +19,4 @@ def time_complexities():
1919
# easily retrieve the source code of the dfs function
2020
def get_code():
2121
import inspect
22-
return inspect.getsource(dfs)
22+
return inspect.getsource(search)

tests/searching_tests.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ def test_bfs(self):
4747
'E': {'A'},
4848
'G': {'C'}
4949
}
50-
result = breadth_first_search.bfs(self.graph, 'A')
50+
result = breadth_first_search.search(self.graph, 'A')
5151
self.assertEqual(result, {'A', 'B', 'D', 'F', 'C', 'G', 'E'})
52-
result = breadth_first_search.bfs(self.graph, 'G')
52+
result = breadth_first_search.search(self.graph, 'G')
5353
self.assertEqual(result, {'G', 'C', 'A', 'B', 'D', 'F', 'E'})
5454

5555
class DFSSearch(unittest.TestCase):
@@ -63,9 +63,9 @@ def test_dfs(self):
6363
'E': ['A'],
6464
'G': ['C']
6565
}
66-
result = depth_first_search.dfs(self.graph, 'A')
66+
result = depth_first_search.search(self.graph, 'A')
6767
self.assertEqual(result, ['A', 'B', 'D', 'F', 'C', 'G', 'E'])
68-
result = depth_first_search.dfs(self.graph, 'G')
68+
result = depth_first_search.search(self.graph, 'G')
6969
self.assertEqual(result, ['G', 'C', 'A', 'B', 'D', 'F', 'E'])
7070

7171
if __name__ == '__main__':

0 commit comments

Comments
 (0)