A depth-first search is an algorithm that looks for data structures in graphs or trees. Before doing backtracking, it starts at the root node and searches as far as it can along each branch. It’s LIFO-based. DFS algorithms also have a different order of nodes than BFS algorithms. Every iteration, the system records the path in a linear format, requiring space.
The search procedure for levels 1 and 2 is carried out via iterative deepening DFS algorithms. It keeps looking for the answer until it finds it. It keeps generating nodes until it reaches the desired node, then stores the stack of nodes it’s produced.