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

Method bfs

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

Source from the content-addressed store, hash-verified

84 self.add_pair(i, n, 1)
85
86 def bfs(self, s=-2):
87 d = deque()
88 visited = []
89 if s == -2:
90 s = next(iter(self.graph))
91 d.append(s)
92 visited.append(s)
93 while d:
94 s = d.popleft()
95 if len(self.graph[s]) != 0:
96 for node in self.graph[s]:
97 if visited.count(node[1]) < 1:
98 d.append(node[1])
99 visited.append(node[1])
100 return visited
101
102 def in_degree(self, u):
103 count = 0

Callers 1

bfs_timeMethod · 0.95

Calls 3

popleftMethod · 0.80
countMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected