bfs and dfs algorithm python