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 3034b38 commit dd12f8bCopy full SHA for dd12f8b
9_breadth_first_search/breadth_first_search.py
@@ -0,0 +1,24 @@
1
+def bfs(Data, start, visited=set()):
2
+
3
+ queue = [start]
4
5
+ while queue:
6
+ currentnode = queue.pop(0)
7
+ if currentnode not in visited: print(currentnode, end = " ")
8
+ visited.add(currentnode)
9
10
+ for i in Data[currentnode] - visited:
11
+ queue.append(i)
12
13
+ return
14
15
16
+Data = {'A': {'B'},
17
+ 'B': {'A', 'C', 'D'},
18
+ 'C': {'B', 'E'},
19
+ 'D': {'B', 'E'},
20
+ 'E': {'C', 'D', 'F'},
21
+ 'F': {'E'}}
22
23
+if __name__ == '__main__':
24
+ bfs(Data, 'A')
0 commit comments