If you have a fixed graph where the node are dense integers, use GetConnectedComponents(): it's very fast and uses little memory.
If you have a more dynamic scenario where you want to incrementally add nodes or edges and query the connectivity between them, use the [Dense]ConnectedComponentsFinder class, which uses the union-find algorithm aka disjoint sets: https://en.wikipedia.org/wiki/Disjoint-set_data_structure.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-08-06 UTC."],[[["This documentation explains how to find connected components in undirected graphs using tools provided by Or-Tools."],["For graphs with dense integer nodes, `GetConnectedComponents()` offers a fast and memory-efficient solution."],["For dynamic scenarios with incremental node/edge additions and connectivity queries, use the `[Dense]ConnectedComponentsFinder` class, which leverages the union-find algorithm."],["Two classes, `ConnectedComponentsFinder` and `DenseConnectedComponentsFinder`, are available for different use cases and can be further explored through the provided links."]]],[]]