MCPcopy
hub / github.com/jwasham/practice-python / dfs_iterative

Method dfs_iterative

graphs/undirected_graph_matrix.py:62–80  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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 """

Callers 1

test_dfs_iterativeFunction · 0.80

Calls 3

get_neighborMethod · 0.95
popMethod · 0.80
appendMethod · 0.80

Tested by 1

test_dfs_iterativeFunction · 0.64