depth-first search (dfs)

Depth-first search (DFS) is a graph traversal algorithm that explores vertices of a graph by prioritizing the deepest unexplored paths. It starts at a given vertex, and then follows each path as far as possible before backtracking. This algorithm uses a stack to maintain the visiting order and keeps track of visited vertices to avoid cycles. DFS is primarily used for graph traversals and can be employed to solve problems such as finding connected components, detecting cycles, and searching for specific nodes or paths within a graph.

Requires login.