begin write BFS and DFS