Find Network Components

Find network components, sizes, and lists of member nodes.
Updated 24 Apr 2014

View License

Given an undirected network represented by an adjacency matrix, we may wish to find that network's
- largest component
- number of components
- list of which nodes are in which component together.
This code computes these rapidly (linear in the number of nodes) and accurately. The code is commented so that if you wish to modify it, you may do so.

1. Network adjacency matrix.

1. Number of network components
2. Sizes of network components (sorted, descending)
3. Membership list of each component (sorted by component size, descending).

Code includes a couple examples of usage at the top. I have tested this in R2014a, but it uses nothing fancy, and I believe it to be backward compatible for many years.

Cite As

Daniel Larremore (2024). Find Network Components (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2013a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Find more on Graph and Network Algorithms in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!


Version Published Release Notes

Fixed typos (clarity), removed possibility of self-edges in the example (clarity), changed instances of "cluster" to "component" in comments and variable names (clarity and correctness), and sorted outputs by component sizes (ease of use).

Fixed typo in description.