Computes the parents for each vertex as determined through depth-first-search (though not too meaningful in an undirected weightless graph) :return: parents for each vertex :rtype: dict
(self)
| 60 | self.dfs_util(u, parents) |
| 61 | |
| 62 | def dfs_iterative(self): |
| 63 | """ |
| 64 | Computes the parents for each vertex as determined through depth-first-search |
| 65 | (though not too meaningful in an undirected weightless graph) |
| 66 | :return: parents for each vertex |
| 67 | :rtype: dict |
| 68 | """ |
| 69 | parents = {} |
| 70 | to_visit = [0] |
| 71 | |
| 72 | while to_visit: |
| 73 | v = to_visit.pop() |
| 74 | |
| 75 | for neighbor in self.get_neighbor(v): |
| 76 | if neighbor not in parents: |
| 77 | parents[neighbor] = v |
| 78 | to_visit.append(neighbor) |
| 79 | |
| 80 | return parents |
| 81 | |
| 82 | def bfs(self): |
| 83 | """ |