Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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'm not sure if this is a Mathematica problem, math problem or a CS problem, so if this is off-topic please transfer it.

In the package Combinatorica there is a function ListGraphs[n,m] which returns all nonisomorphic undirected graphs with n vertices and m edges. What algorithm does it use? All I can think of is to enumerate all graphs with n vertices and m edges brute-force, and check isomorphism for each graph. But I don't think that's effective. Is there a better algorism for this task? Thanks!

share|improve this question
The Combinatorica package is described in detail in this book: Computational Discrete Mathematics: Combinatorics and Graph Theory with Mathematica . – Yves Klett Jun 23 '14 at 7:00
@YvesKlett Thanks for the recommendation! I checked but it's not in our library, so I might as well wait for an answer – arax Jun 23 '14 at 7:08
up vote 6 down vote accepted

You can find the code for the function in the file Combinatorica.m:

nb = NotebookOpen[ToFileName[{$InstallationDirectory, "AddOns", "Packages", 
            "Combinatorica"}, "Combinatorica.m"]];
NotebookFind[nb, "ListGraphs[n_Integer?Positive, m_Integer]"]

enter image description here

share|improve this answer

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.