Skip to content

Instantly share code, notes, and snippets.

@anandijain
Created May 28, 2022 04:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anandijain/ff7270f010485e0c0aeb856fa043b778 to your computer and use it in GitHub Desktop.
Save anandijain/ff7270f010485e0c0aeb856fa043b778 to your computer and use it in GitHub Desktop.
Number of connected unlabeled graphs with n edges
using Graphs, Combinatorics
# [861a8166] Combinatorics v1.0.2
# [86223c79] Graphs v1.7.0
function all_balanced_graphs(n)
S = Set{SimpleGraph}()
all_balanced_graphs!(S, n)
end
function all_balanced_graphs!(S, n)
possible_gs = combinations(1:binomial(n, 2), n)
e_labels = collect(combinations(1:n, 2))
for p in possible_gs
g = SimpleGraph(n)
for ev in e_labels[p]
add_edge!(g, ev...)
end
push_graph!(S, g)
end
S
end
function push_graph!(set::AbstractSet, g::AbstractGraph)
for e in set
if Graphs.Experimental.has_isomorph(g, e)
return set
end
end
push!(set, g)
end
# https://oeis.org/A116508
gl = all_balanced_graphs.(1:7)
# https://oeis.org/A057500
gc = map(g -> filter(is_connected, g), gl)
# this sequence
length.(gc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment