File Exchange

image thumbnail

Largest Component

version 1.4 (1.22 KB) by

Takes an adj. matrix of a network and outputs a list of the nodes in its largest connected component



View License


This function find the largest connected component of a networks.

Input A is the adjacency matrix of the network.

Output B is a list of the nodes that are in the largest component.

A(B,B) will give the adj. matrix of the largest component.

Comments and Ratings (5)

Used on Octave, works as advertised.

Fabio Gori

It would be nice if you commented the code, so that the procedure would be more comprehensible.

Puck Rombach

You are right. Thank you!

Xin Dong

There is a bug in this script. It fails when there are several largest connected components of the same size, because now cm is a vector.

If you only need to find any one of them, than it should be:


Otherwise, a loop is needed to print out all the largest components.



Fixed bug about multiple largest components.


Made the code faster by not using the 'find' function.

MATLAB Release
MATLAB 7.9 (R2009b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video