Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a huge graph with ~8k vertices and ~1k components. I want a histogram showing the number of vertices for each component. How do I do this?

EDIT: I'm trying ubpdqn's approach, but not gettting the expected results. Here are the details of my graph and the resulting histogram:

H = ExampleData[{"NetworkGraph", "HighEnergyTheoryCollaborations"}]

Histogram[Length /@ ConnectedComponents[H], LabelingFunction -> Above, BaseStyle -> 20]


enter image description here

share|improve this question
I'm using google but cannot find functions that do what I want. I do ConnectedComponents[G] and I get the labels of all vertices, grouped in components. I do Length@ConnectedComponents[G] and I get the number of components. Not sure where to go from here. – sdkbj May 6 '14 at 11:39
This question appears to be off-topic because it the underlying problem is in the OP'sdata and not in Mathematica. – m_goldberg May 6 '14 at 12:58
@Öskå " If you remove it" remove what exactly? – sdkbj May 6 '14 at 13:10
You could use Histogram[Log /@ Length /@ ConnectedComponents[H], LabelingFunction -> Above] – Dr. belisarius May 6 '14 at 13:14
Your result looks perfectly correct to me. It says simply that most of the connected components are quite small. You should probably accept the answer given by @ubpdqn. – Mark McClure May 6 '14 at 14:01
up vote 6 down vote accepted

Here is a toy example:

Generate toy graph

g = Graph[
   UndirectedEdge @@@ 
    RandomSample[Subsets[Union[RandomInteger[{1, 1000}, 1000]], {2}], 

Mine: enter image description here

Histogram can be obtained by mapping Length to ConnectedComponents:

Histogram[Length /@ ConnectedComponents[g], LabelingFunction -> Above,
  BaseStyle -> 20]

enter image description here

share|improve this answer
I tried this approach but getting strange result. I added to my question. – sdkbj May 6 '14 at 12:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.