I am trying to find the number of connected components of numerous named graphs within Combinatorica. The obvious answer seems to be:


but this fails. What am I doing wrong?

Does this property only work when the number of connected components is >= 2?

  • $\begingroup$ Please give a complete and runnable example which fails. What is "G"? Also, GraphData is not part of Combinatorica. Do not load Combinatorica for this. $\endgroup$
    – Szabolcs
    Nov 16, 2013 at 18:23
  • $\begingroup$ I am using version 9 of Mathematica. Has the use of Combinatorica` changed from earlier versions? I have been using GraphData with Combinatorica` for a long time. $\endgroup$ Nov 16, 2013 at 18:31
  • $\begingroup$ GraphData is not part of Combinatorica, and to my knowledge it has never been. It is a built-in function introduced in version 8. $\endgroup$
    – Szabolcs
    Nov 16, 2013 at 18:33
  • $\begingroup$ I have to correct myself, GraphData was introduced in version 6, but it was a built-in, not part of Combinatorica. In version 8 and version 9 it returns the new Graph objects that were introduced in version 8. These are not directly compatible with Combinatorica. While it is still possible to use Combinatorica, and even convert these built-in graphs to Combinatorica's format, great care has to be taken to choose the correct function from the correct context for each operation. So unless you know you need Combinatorica, I recommend you don't load it to avoid accidental problems. $\endgroup$
    – Szabolcs
    Nov 16, 2013 at 18:38
  • 4
    $\begingroup$ GraphData["PappusGraph", "Properties"] shows that this graph has no property called "ConnectedComponents" in version 9. It has GraphData["PappusGraph", "ConnectedComponentCount"] which returns 1. $\endgroup$
    – Szabolcs
    Nov 16, 2013 at 18:39

1 Answer 1


Negotiating between system and Combinatorica is tricky. I post this for illustrative purposes.Notes also ConnectedComponents is a built-in command in Mathematica 9.

fg = FiniteGraphs;
adj = ToAdjacencyMatrix /@ fg;
sysg = System`AdjacencyGraph /@ adj;
  Row /@ ({#, Length[System`ConnectedComponents[#]]} & /@ sysg), 5], 
 Frame -> All]

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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