How to order the set of all graphs?

277 Views Asked by At

When trying to figure out how to order the set of all graphs, it seems obvious to me that graphs with fewer nodes come before graphs with more nodes, and that among graphs with equal nodes that graphs with fewer edges come before graphs with more edges. However, at that point I get stuck. You could construct a string representation of each graph's adjacency matrix and sort by lexicographic order, but I fell that's clunky and unnatural. Alternately you could, for each graph, make any array of the degree of each node sorted in ascending order and then do a lexicographical-ish sort on the arrays, but what about graphs which have the same number nodes, same number of edges, and the same sorted node degree arrays?

1

There are 1 best solutions below

0
On BEST ANSWER

The root of your requirement to order graphs is to have a 'canonical form' of a graph. Also called a 'canonical labelling'.

As you point out, the 'linearised' adjacency (half-) matrix of a graph can help you order graphs up to a point - except that the ordering of the edges in the graph affects the resulting string. If you try all n! orderings of each graph, you can use the lex-minimal (or maximal) string form of the matrix.

The degree sequence is useful ... except as you mention, for k-regular graphs. However, there are efficient algorithms to determine a canonical form for any graph. As always, nAUTy/Traces is one to mention but the general technique is similar to your adjacency matrix approach in that you are finding a labelling of the graph that is lexographically maximal.