Created
May 28, 2022 04:38
-
-
Save anandijain/ff7270f010485e0c0aeb856fa043b778 to your computer and use it in GitHub Desktop.
Number of connected unlabeled graphs with n edges
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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