Add in-progress notes for 2026.07.21

This commit is contained in:
2026-07-21 21:06:54 -04:00
parent 059c848d3d
commit a7ee5d06a0

View 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)