MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / bfs

Method bfs

graphs/directed_and_undirected_weighted_graph.py:352–366  ·  view source on GitHub ↗
(self, s=-2)

Source from the content-addressed store, hash-verified

350 self.add_pair(i, n, 1)
351
352 def bfs(self, s=-2):
353 d = deque()
354 visited = []
355 if s == -2:
356 s = next(iter(self.graph))
357 d.append(s)
358 visited.append(s)
359 while d:
360 s = d.popleft()
361 if len(self.graph[s]) != 0:
362 for node in self.graph[s]:
363 if visited.count(node[1]) < 1:
364 d.append(node[1])
365 visited.append(node[1])
366 return visited
367
368 def degree(self, u):
369 return len(self.graph[u])

Callers 1

bfs_timeMethod · 0.95

Calls 3

popleftMethod · 0.80
countMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected