working bfs and dfs