BFS and DFS in Code