Depth First Search
graph = {0:[1,4,5], 1:[3,4], 2:[1], 3:[2,4], 4:[], 5:[]}
visited = []
def dfs(node):
visited.append(node)
print('Node %i' % node)
for i in graph[node]:
if i not in visited:
dfs(i)
if __name__ == '__main__':
dfs(0)