Hi,
I don't know much graph theory, so if there is a better place to answer this question, feel free to redirect me.
I'm trying to create a function that uses breadth first iteration to return the neighbors of a node, but which organizes the results according to depth.
In other words, I would like the algorithm to do take a given node, get it's neighbors, mark the depth as 1, get the neighbors of all those neighbors, then mark the depth as 2, etc.
Here is my current naive and incorrect code:
from collections import deque
def breadthFirstToDepth(graph, node, depth):
q = deque()
q.append(node)
touched = [node]
while len(q) > 0 and depth > 0:
current = q.popleft()
depth -= 1
for n in graph[current]:
if n not in touched:
touched.append(n)
q.append(n)
Thanks for any possible help!
-Ben