Explain depth-first search (DFS).
Depth-First Search (DFS) is a fundamental algorithm used to explore nodes and edges of a graph or tree by traversing as far as possible along each branch before backtracking. It is useful for various graph and tree operations and has distinct characteristics compared to Breadth-First Search (BFS).
Time and Space Complexity: