I've been scouring the internet and haven't been able to find anything that would help. I'm running a basic dfs algorithm in python. My error is in the explore
subroutine of dfs
def dfs(graph):
for node in graph:
if not node in visited:
explore(graph, node)
def explore(graph, v):
visited.append(v)
adjNode = graph[v]
for i in range(0, len(adjNode)):
if not adjNode[i] in visited:
explore(graph, adjNode[i])
visited
is a list I'm using to keep track of visited nodes and graph
is a dictionary that holds the graph.
With a standard recursion limit of 1000 I get this error
File "2breakDistance.py", line 45, in explore
explore(graph, adjNode[i], cycles)
File "2breakDistance.py", line 45, in explore
explore(graph, adjNode[i], cycles)
File "2breakDistance.py", line 45, in explore
explore(graph, adjNode[i], cycles)
File "2breakDistance.py", line 45, in explore
explore(graph, adjNode[i], cycles)
File "2breakDistance.py", line 41, in explore
adjNode = graph[v]
RuntimeError: maximum recursion depth exceeded in cmp
First of all, I'm not quite sure why the error is occurring in adjNode = graph[v]
since explore
is the recursive call and adjNode
is just list assignment.
But to deal with the recursion error, I increased the recursion limit with sys.setrecursionlimit(5000)
I no longer get the error, but the program quits right before the adjNode = graph[v]
line and exits with no error. It never even reaches the end of dfs
so I'm not quite sure what's going on. Thanks for reading all this and for any help!