Skip to content

Commit 73f9b73

Browse files
committed
BFS
1 parent 24d5fef commit 73f9b73

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Data Structures/Graphs/BFS.py

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

Comments
 (0)