Source: https://goodhandover.co.uk/tools/connected-components-calculator/

[Computer science maths](https://goodhandover.co.uk/tools/computer-science-maths/#year-2) / Year 2

🔒 Files never leave your device

# Connected components calculator

Find the groups of vertices connected by paths in an undirected graph. Your inputs stay on your device.

## Set up your task

Ready. Processing stays in this browser.

Files and text stay on your device. [Privacy details](https://goodhandover.co.uk/privacy/).

 

## How to use Connected components calculator

Find the groups of vertices connected by paths in an undirected graph. The pre-filled problem gives you a worked starting point. Compare the response with your own working before trying the self-check below.

 

- Check the example inputs: Vertices (space-separated), Edges (from and to, one per line).

- Change the inputs for your problem. Results update as you type, so finish entering the values before copying an answer.

- Use the working to check an intermediate value or assumption. Then change the example as suggested in the self-check and compare the result.

 

## Supported inputs and limits

Use up to 20 vertices and 80 unweighted edges. List all vertices, including ones with no edges.

 

## How it works

A connected component contains all vertices reachable from one of its members in an undirected graph. Different components have no path between them. The sets partition the vertices, so every vertex belongs to exactly one component, including a vertex with no adjacent edges.

The algorithm chooses an unseen vertex and runs a traversal to find its entire component. Then it chooses another unseen vertex until all have been placed. This is a typical use of breadth-first search inside a larger problem. Adding a bridging edge can merge two groups at once.

 

## Example

Run the pre-filled example. Its first result is “Connected components: 3”.

Vertices (space-separated)

A B C D E

Edges (from and to, one per line)

A B

C D

Connected components: 3
1. A, B
2. C, D
3. E

 

## Questions about Connected components calculator

### Will a self-loop add a new component?

A self-loop stays at its own vertex. Components depend on which different vertices can reach one another.

### What about strongly connected components?

Strong connectivity is for directed graphs and requires a way back along directed edges. This calculator uses the undirected definition.

### Add B C to the example edge list.

The groups containing A and D merge. E still has no connections, so the output now has two components.

 
 

## Related tools

[Year 2: Algorithms and theory](https://goodhandover.co.uk/tools/computer-science-maths/#year-2)

- [Floyd–Warshall calculator](https://goodhandover.co.uk/tools/floyd-warshall-calculator/)

- [0/1 knapsack calculator](https://goodhandover.co.uk/tools/knapsack-calculator/)

- [Minimum spanning tree calculator](https://goodhandover.co.uk/tools/minimum-spanning-tree-calculator/)

- [Levenshtein edit distance calculator](https://goodhandover.co.uk/tools/edit-distance-calculator/)

 

Last updated 24 November 2026
