2

Given $n$ labelled nodes and $k$ edges, how many number of distinct connected undirected graphs are possible? There can be only one edge between a pair of nodes and cycles are allowed.

I came up with following steps:

  1. Find total number of possible edges with $n$ nodes, $t = (n * (n - 1)) / 2$
  2. If $k \le t$, find $ret = t! / (k! * (t-k)!)$ i.e. tCk
  3. For $n - 1$ nodes, calculate:

$t1=$ total number of possible edges with $n-1$ nodes

$r1=$ t1Ck

$ret = ret - r1$

  1. Repeat step $3$ for $n-2$, $n-3$ until $1$

The main idea here is to find all possible ways of choosing $k$ edges from total number of possible edges for $n$ nodes and then remove all possible ways of choosing $k$ edges from total number of possible edges for less than $n$ nodes (which would result in disconnected graph). It seems I am missing something, but I am not able to figure out what. Can someone please help?

h_t
  • 83

0 Answers0