Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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]

Result:

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 at 11:39
4  
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 at 12:58
    
@Öskå " If you remove it" remove what exactly? –  sdkbj May 6 at 13:10
1  
You could use Histogram[Log /@ Length /@ ConnectedComponents[H], LabelingFunction -> Above] –  belisarius May 6 at 13:14
2  
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 at 14:01

1 Answer 1

up vote 5 down vote accepted

Here is a toy example:

Generate toy graph

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

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 at 12:40

Your Answer

 
discard

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.