Add in-progress notes for 2026.07.21
This commit is contained in:
25
notes-and-examples/2026.07.21/main.py
Normal file
25
notes-and-examples/2026.07.21/main.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# Adjacency list
|
||||
first_graph = {
|
||||
1: [3, 20],
|
||||
2: [20],
|
||||
3: [1, 20],
|
||||
20: [2, 3]
|
||||
}
|
||||
|
||||
# First exercise: go from 1, to 20, to 2
|
||||
first_graph[first_graph[1][1]][0]
|
||||
|
||||
# pass visited by reference
|
||||
def depth_first_search(graph: dict, start, visited=set()):
|
||||
print(start)
|
||||
if len(visited)==len(graph):
|
||||
return visited
|
||||
|
||||
for x in graph[start]:
|
||||
if x not in visited:
|
||||
visited.add(x)
|
||||
return depth_first_search(graph, x, visited)
|
||||
pass
|
||||
|
||||
|
||||
depth_first_search(first_graph, 1)
|
||||
Reference in New Issue
Block a user