DFS explained
def depth_first_search(graph):
visited, stack = set(), [root]
while stack:
vertex = stack.pop()
if vertex not in visited:
visited.add(vertex)
stack.extend(graph[vertex] - visited)
return visited