1
$\begingroup$

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

Length[GraphData[G,"ConnectedComponents"]]  

but this fails. What am I doing wrong?

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

$\endgroup$
  • $\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 '13 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$ – clive elphick Nov 16 '13 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 '13 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 '13 at 18:38
  • 3
    $\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 '13 at 18:39
4
$\begingroup$

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

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

enter image description here

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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