Graph Theory – How to Calculate the Number of Possible Connected Simple Graphs with $n$ Labeled Vertices

graph theory

Suppose that we had a set of vertices labelled $1,2,\ldots,n$.

There will several ways to connect vertices using edges. Assume that the graph is simple and connected.

In what efficient (or if there is no efficient way, you can just tell me whatever procedure you can think of) way do we be able to calculate the number of possible ways the graph can be made? (even if some graphs are isomorphic to each other, they are counted as separate cases.)

Best Answer

There are $\binom{n}2=\frac12n(n-1)$ pairs of distinct points. If you do not allow loops or multiple edges, each of these pairs determines one possible edge, and you can have any subset of those possible edges. A set with $\binom{n}2$ members has $2^{\binom{n}2}$ subsets, so there are $2^{\binom{n}2}$ possible graphs without loops or multiple edges.

If you demand that the graphs be connected, the problem becomes very much harder. From your final comment I take it that you are in effect counting labelled graphs. This sequence of numbers is A001187 in the On-Line Encyclopedia of Integer Sequences. If $d_n$ is the number of labelled, connected, simple graphs on $n$ vertices, the numbers $d_n$ satisfy the recurrence

$$\sum_k\binom{n}kkd_k2^{\binom{n-k}2}=n2^\binom{n}2\;,$$

from which it’s possible to calculate $d_n$ for small values of $n$. This recurrence is derived as formula (3.10.2) in Herbert S. Wilf, generatingfunctionology, 2nd edition, which is available for free download here.

According to MathWorld, Brendan McKay’s software package nauty includes a routine that efficiently enumerates such graphs; it’s available here.

If you count unlabelled graphs instead, so that you don’t count isomorphic graphs separately, you get the sequence mentioned by Arturo in the comments.