You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: main/algorithms/DFS.py
+3-35
Original file line number
Diff line number
Diff line change
@@ -1,27 +1,5 @@
1
1
importpygame
2
-
from .RPimportreconstruct_path
3
-
4
-
"""
5
-
Recursive
6
-
1. Mark the current node as visited(initially current node is the root node)
7
-
2. Check if current node is the goal, If so, then return it.
8
-
3. Iterate over children nodes of current node, and do the following:
9
-
1. Check if a child node is not visited.
10
-
2. If so, then, mark it as visited.
11
-
3. Go to it's sub tree recursively until you find the goal node(In other words, do the same steps here passing the child node as the current node in the next recursive call).
12
-
4. If the child node has the goal node in this sub tree, then, return it.
13
-
3. If goal node is not found, then goal node is not in the tree!
14
-
15
-
16
-
Iterative
17
-
1. Add root node to the stack.
18
-
2. Loop on the stack as long as it's not empty.
19
-
1. Get the node at the top of the stack(current), mark it as visited, and remove it.
20
-
2. For every non-visited child of the current node, do the following:
21
-
1. Check if it's the goal node, If so, then return this child node.
22
-
2. Otherwise, push it to the stack.
23
-
3. If stack is empty, then goal node was not found!
0 commit comments