# Finding all possible simple directed graphics given a set of nodes

Is it possible to find all simple directed graphs given a set of nodes? I was thinking of just finding all permutations of an adjacency list of lists. For example, given nodes A, B I can have the adjacency lists:

A | \
B | \

A | B
B | \

A | \
B | A

A | B
B | A


The constraints are: no self loops, simple graph, directed edges

I can probably code up the way I described above, but I wanted to make sure doing this wasn't hitting some sort of fundamental boundary of graph theory or cs.

I was also thinking about using an adjacency matrix where I can store the matrix in row-major or column-major order in a uni-dimensional array of 0s and 1s - permute the uni-dimensional array (which has to be possible) and rebuild the NxM matrix to represent the graph that way.

Apologies that this is more of a discussion than a question, but any advice would be much appreciated!

• Do you want a set of all non-isomorphic directed graphs? Or all directed graphs, period? You do realize that the number grows exponentially and so this won't be feasible unless the number of vertices is very small, right? – D.W. Mar 31 '17 at 7:27
• What are non-isomorphic directed graphs? Yes the number of vertices will be on the order of 10 – Carpetfizz Mar 31 '17 at 13:00
• With 10 vertices, there are $2^{90}$ possible directed graphs -- way too many to enumerate all of them within your lifetime. – D.W. Mar 31 '17 at 17:14
• @D.W. ah, that kills my idea then, thanks for letting me know – Carpetfizz Mar 31 '17 at 17:15

Any of those will work, as long as you view the graphs $A\to B$ and $B\to A$ as different graphs. If you view them as being the same graph, then things are much more complex as you have to either do isomorphism testing or somehow enumerate in a way that doesn't produce isomorphic graphs more than once.
The fundamental barrier is that, in an $n$-vertex digraph has $n(n-1)$ possible edges, each of which may be present or not, so there are $2^{n(n-1)}$ possible digraphs on $n$ vertices. Your program must output all of these which is going to be infeasible for all but small graphs.
• I think you mean $2^{n(n-1)}$ different graphs. – D.W. Mar 31 '17 at 17:14
Enumerate all possible adjacency matrices. A matrix is a possible adjacency matrix for a directed graph if it is a $n\times n$ matrix with 0 or 1 in every entry, except that the diagonal has to be all zeros. It is easy to enumerate them, because this is equivalent to enumerating all bit-strings of length $n(n-1)$.
Consequently, there are $2^{n(n-1)}$ directed graphs. Thus unless $n$ is very small, the number of such graphs is enormous -- too many to enumerate all of them.