Skip to content

Instantly share code, notes, and snippets.

View daveweber's full-sized avatar

Dave daveweber

View GitHub Profile
@daveweber
daveweber / graphs.py
Created March 17, 2016 18:46
Breadth First and Depth First Search in Python
def bfs(graph, start):
visited, queue = set(), [start]
while queue:
vertex = queue.pop(0)
if vertex not in visited:
visited.add(vertex)
queue.extend(graph[vertex] - visited)
return visited