Caterpillar interview question

Code tasks, For DFS OR BFS