Read the Big-O
Visited as a List
The graph has n nodes, each with at most 2 neighbours (like a chain). Visited nodes are kept in a list: how does the time grow?1def reach(graph, start):
2 visited = [start]
3 queue = [start]
4 for node in queue:
5 for nxt in graph[node]:
6 if nxt not in visited:
7 visited.append(nxt)
8 queue.append(nxt)
9 return len(visited)