-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirest H-W.py
More file actions
42 lines (30 loc) · 838 Bytes
/
firest H-W.py
File metadata and controls
42 lines (30 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def dfs(graph, node, destination, path=None, visited=None):
if path is None:
path = []
if visited is None:
visited = set()
path.append(node)
visited.add(node)
if node == destination:
print("Path:", " : ".join(path))
else:
for neighbor in graph[node]:
if neighbor not in visited:
dfs(graph, neighbor, destination, path, visited)
path.pop()
visited.remove(node)
graph = {
'ONE': ['TWO', 'THREE','FOUR' ],
'TWO': ['FOUR', 'FIVE', 'FIVE'],
'THREE': ['FOUR','SIX'],
'FOUR': ['SEVEN','FIVE'],
'FIVE': ['SIX'],
'SIX': ['SEVEN'],
'SEVEN': []
}
root = 'ONE'
destination = 'SEVEN'
dfs(graph, root, destination)
print(" ")
print(" function finash successfully")
print(" thank you for tring")