Code covered by the BSD License

5.0

by Puck Rombach

31 Mar 2011 (Updated 06 Jun 2011)

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

| Watch this File

B=largestcomponent(A)

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.

Used on Octave, works as advertised.

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

You are right. Thank you!

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:

B=find(x==cm(1));

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

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

Fixed bug about multiple largest components.

Contact us