The Connected Component algorithm identifies the connected components in a graph, which is the essential indicator to examine the connectivity and topology characteristics of the graph.
The number of connected components in a graph can serve as a coarse-grained metering method. If the number of connected components remains unchanged after certain operations or modifications to the graph, it suggests that the macroscopic connectivity and topology characteristics of the graph have not been altered significantly.
This information is valuable in various graph analysis scenarios. For example, in social networks, if the number of connected components remains the same over time, it implies that the overall connectivity patterns and community structures within the network have not experienced substantial changes.
A connected component is a maximal subset of nodes in a graph where all nodes in that subset are reachable from one another by following edges in the graph. A maximal subset means that no additional nodes can be added to the subset without breaking the connectivity requirement.
The number of connected components in a graph indicates the level of disconnectedness or the presence of distinct subgraphs within the overall graph. A graph that has exactly one component, consisting of the whole graph, is called a connected graph.
There are two important concepts related to connected component: weakly connected component (WCC) and strongly connected component (SCC):

This example shows the 3 strongly connected components and 2 weakly connected components of a graph. The number of SCCs in a graph is always equal to or greater than the number of WCCs, as determining a SCC requires stricter conditions compared to a WCC.
algo(connected_component)Name | Type | Spec | Default | Optional | Description |
|---|---|---|---|---|---|
| cc_type | int | 1, 2 | 1 | Yes | 1 means weakly connected component (WCC), 2 means strongly connected component (SCC) |
| limit | int | ≥-1 | -1 | Yes | Number of results to return, -1 to return all results |
| order | string | asc, desc | / | Yes | Sort results by the count of nodes in each connected component (only valid in mode 2 of the stream() execution) |
NOTEIn Ultipa's Connected Component algorithm, each connected component is denoted as a community.
The example graph is as follows:

| Spec | Content |
|---|---|
| filename_community_id | _id,community_id |
| filename_ids | community_id,_id,_id,... |
| filename_num | community_id,count |
UQLalgo(connected_component).params({ cc_type: 1 }).write({ file:{ filename_community_id: 'f1', filename_ids: 'f2', filename_num: 'f3' } })
Statistics: community_count = 2
Results: Files f1, f2, f3
File: f1Alice,0 Bill,0 Bob,0 Sam,0 Joe,0 Anna,0 Cathy,6 Mike,6
File: f20,Alice,Bill,Bob,Sam,Joe,Anna, 6,Cathy,Mike,
File: f30,6 6,2
| Spec | Content | Write to | Data Type |
|---|---|---|---|
| property | community_id | Node property | int64 |
UQLalgo(connected_component).params().write({ db:{ property: 'wcc_id' } })
Statistics: community_count = 2
Results: The community ID of each node is written to a new property named wcc_id
Alias Ordinal | Type | Description | Columns |
|---|---|---|---|
| 0 | []perNode | Node and its community ID | _uuid, community_id |
| 1 | KV | Number of communities | community_count |
UQLalgo(connected_component).params({ cc_type: 2 }) as r1, r2 return r1, r2
Results: r1 and r2
| _uuid | community_id |
|---|---|
| 8 | 0 |
| 7 | 0 |
| 6 | 0 |
| 5 | 3 |
| 4 | 0 |
| 3 | 0 |
| 2 | 6 |
| 1 | 7 |
| community_count |
|---|
| 4 |
| Spec | Content | Alias Ordinal | Type | Description | Columns |
|---|---|---|---|---|---|
| mode | 1 or if not set | 0 | []perNode | Node and its community ID | _uuid, community_id |
2 | []perCommunity | Community and the number of nodes in it | community_id, count |
UQLalgo(connected_component).params({ cc_type: 2 }).stream() as r return r
Results: r
| _uuid | community_id |
|---|---|
| 8 | 0 |
| 7 | 0 |
| 6 | 0 |
| 5 | 3 |
| 4 | 0 |
| 3 | 0 |
| 2 | 6 |
| 1 | 7 |
UQLalgo(connected_component).params({ cc_type: 2, order: 'asc' }).stream({ mode: 2 }) as r return r
Results: r
| community_id | count |
|---|---|
| 6 | 1 |
| 7 | 1 |
| 3 | 1 |
| 0 | 5 |
| Alias Ordinal | Type | Description | Columns |
|---|---|---|---|
| 0 | KV | Number of communities | community_count |
UQLalgo(connected_component).params().stats() as count return count
Results: count
| community_count |
|---|
| 2 |