MCPcopy Create free account
hub / github.com/jwasham/practice-python / bfs

Method bfs

graphs/undirected_graph_matrix.py:82–100  ·  view source on GitHub ↗

Computes the the parents for each vertex as determined through breadth-first search :return: parents for each vertex :rtype: dict

(self)

Source from the content-addressed store, hash-verified

80 return parents
81
82 def bfs(self):
83 """
84 Computes the the parents for each vertex as determined through breadth-first search
85 :return: parents for each vertex
86 :rtype: dict
87 """
88 parents = {}
89 to_visit = queue.Queue()
90 to_visit.put(0)
91
92 while not to_visit.empty():
93 v = to_visit.get()
94
95 for neighbor in self.get_neighbor(v):
96 if neighbor not in parents:
97 parents[neighbor] = v
98 to_visit.put(neighbor)
99
100 return parents
101
102 def is_bipartite(self):
103 """

Callers 1

test_bfsFunction · 0.45

Calls 1

get_neighborMethod · 0.95

Tested by 1

test_bfsFunction · 0.36