Briefly speaking, the recursion stopped halfway though everything else is fine.
The recursion function is shown below (The entire code can be found here):
def DFS(graph, startNode = 0):
global nodesProcessed; global explored; global finishingTime
explored[startNode] = True
currentLeader = startNode
if startNode in graph:
for neighbor in graph[startNode]:
if not explored[neighbor]:
#checkpoint 1
DFS(graph, neighbor)
#checkpoint 2
else: return currentLeader
nodesProcessed += 1
finishingTime[startNode] = nodesProcessed
return currentLeader
The problem is that after a while's recursion, it stopped. The things that confused me are that:
- The input is fixed, but where it stops is not fixed. However, it always stopped at around 7000 times of invoke;
- All the failed recursions reaches
checkpoint 1but fails to reachcheckpoint 2, and the recursion does not execute at all; - It doesn't reach that maximum recursion time at all, I've set the max recursion as
sys.setrecursionlimit(10**6) - It runs pretty well on relatively small input (hundreds or thousands of nodes) but stuck on a large graph which has more than 800,000 nodes.
Which are driving me crazy, I can't see a reason why it doesn't work, no error, no stack overflow, just stopped, saying Press any key to continue ... as if it is finished. Anyone has a clue about what could possibly go wrong?
Killthe process so as not to crash the operating system. If you are running on Windows or Mac I'm not sure what will happen but it is something to look at.22473and it's neighbor (or neighbor's neighbor), But because the input is fixed, I'm not sure if that's the problem of the hardware or the problem of the algorithm.return DFS(graph, neighbor)