Algorithm
Depth-First Search (DFS) Algorithm:
- Initialize a stack and mark the starting node as visited.
- Push the starting node onto the stack.
- While the stack is not empty:
- Pop a node from the top of the stack.
- Process the popped node (e.g., print or store it).
- For each unvisited adjacent node of the popped node:
- Mark the adjacent node as visited.
- Push the adjacent node onto the stack.
Example:

Fig. 1: Step-by-Step Process of Depth-First Search
Note: DFS is particularly useful for exploring all possible paths in a graph and for solving problems like maze traversal and topological sorting.