-
Notifications
You must be signed in to change notification settings - Fork 185
erdos_renyi is n^2 algorithm #27
Comments
The two issues with this are
|
|
Subtraction is relatively expensive. I was looking at doing that for the generic random graph creation but there are a lot of nuances to it. add_edge! checks has_edge, but unless you want to catch exceptions (expensive) you should do it beforehand. |
At least for the undirected case its n choose 2 edge operations which is the original cost h = Graph(nv(g))
for i in 1:nv(g)
for j in i+1:nv(g)
if !has_edge(g, i,j)
add_edge!(h,i,j)
end
end
end
return h Yeah we have to check before each insertion but we get and asymptotic gain. |
@jpfairbanks Can you create a function |
Are you willing to depend on |
I'm ok with it. I'm using StatsBase already for some sampling stuff for |
As it turns out, |
Closed via #31. Thank you! |
You can instead compute the number of edges to draw as
ne ~ binomial((n^2-n)/2 , p)
and then picki,j
uniformly at random until you hitne
edges. This leads to an O(ne) algorithm for smallp
For largep
you end up doing O(n^2) work anyway.The text was updated successfully, but these errors were encountered: