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 24d5fef commit 73f9b73Copy full SHA for 73f9b73
Data Structures/Graphs/BFS.py
@@ -0,0 +1,26 @@
1
+"""
2
+Author : Robin Singh
3
+Implementation Of BFS
4
+
5
6
+def bfs(graph, start):
7
8
+ path = []
9
+ queue = [start]
10
+ while queue:
11
+ vertex = queue.pop(0)
12
+ if vertex not in path:
13
14
+ path.append(vertex)
15
+ queue.extend(graph[vertex])
16
+ return path
17
+if __name__ == '__main__':
18
19
20
+ graph={ 0: [1, 3,4],
21
+ 1: [2],
22
+ 2: [3],
23
+ 3: [1,4],
24
+ 4: [0,2] }
25
+ print(bfs(graph, 0))
26
0 commit comments