Graph/connected_components library

🔗 Connected Components (Undirected)

Finds all connected components in an undirected graph represented as an adjacency list. Returns a list of sets where each set contains the nodes of one component.

  • Time complexity: O(V + E)
  • Space complexity: O(V)

Example:

final graph = {'A': ['B'], 'B': ['A'], 'C': []};
final comps = connectedComponents(graph); // [{A, B}, {C}]

Functions

connectedComponents<T>(Map<T, List<T>> graph) → List<Set<T>>