Skip to content

Commit 9dcd981

Browse files
authored
Update Breadth_First_Search.py
Fixed the fact that all nodes except source are marked as visited twice
1 parent 3770551 commit 9dcd981

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Graphs/Breadth_First_Search.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ def add_edge(self, i, j):
1515

1616
def bfs(self,s):
1717
queue=[s]
18+
self.visited[s]=1
1819
while len(queue)!=0:
1920
x=queue.pop(0)
2021
print(x)
21-
self.visited[x]=1
2222
for i in range(0,self.nodes):
2323
if self.graph[x][i]==1 and self.visited[i]==0:
2424
queue.append(i)

0 commit comments

Comments
 (0)