Computes the the parents for each vertex as determined through breadth-first search :return: parents for each vertex :rtype: dict
(self)
| 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 | """ |