c# - Randomly Connected Graph Generator -


i'm trying generate simple graph randomly connecting n nodes. i'm looking efficient algorithm so, this:

  • input:
    • n number of nodes
    • e number of edges n-1 n(n-1)/2
  • output: simple connected graph n vertices , e edges

create array of n nodes. fisher-yates shuffle array. scan array , create edge each pair of nodes adjacent in array. result connected graph n-1 edges.

if number of additional edges small, can randomly add edges till have enough. otherwise, create array of unused edges, fisher-yates shuffle array, , take first (e - (n-1)) edges array.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -