Skip to main content

Crate dfs

Crate dfs 

Source
Expand description

Depth-First Search (DFS) on a graph.

DFS explores as deep as possible along each branch before backtracking. It is the natural building block for topological order, cycle detection on directed/undirected graphs, strongly connected components, and tree traversals.

This module exposes DFS as two helpers operating on an adjacency list:

  • dfs_order — returns vertices in the order they are first visited (iterative, stack-based; safe for deep graphs).
  • has_cycle_undirected — detects whether an undirected graph contains a cycle.

Functions§

dfs_order
Return the DFS visitation order starting from source.
has_cycle_undirected
Detect whether an undirected graph contains a cycle.