0

Let us only be interested in simple undirected graphs.

Find the number of all graphs of $N$ vertices, where exactly one vertex has degree $N - 1$. For example $f(3) = 3, f(4) = 16$.

My idea is: let us know the answer for a fixed vertex number one $V_1$, provided that it is connected to all the others $p_1(N)$, then $f(N) = N * p_1(N)$. So now we should add a new one vertex and count $p_1(N + 1)$. We should connect $V_{N + 1}$ and $V_1$ to hold the task condition, now it's possible to connect new vertex with another N - 1 in different combinations, except only one case, when $V_{N + 1}$ connected with all others, total number is $\sum_{k=0}^{n-2} \binom{n - 1}{k}$. But with the addition of a new vertex, there are cases when some of the vertices $V_2, V_3, ..., V_N$ can now be connected to each other and not included in $p_1(N)$, I don't know how to count such cases.

Are there any other ideas?

P.S. time complexity should be not greater than $O(N^2)$

Babado
  • 1,306
Evgeny
  • 411

1 Answers1

1

As you said, you choose the vertex with degree $N-1$ in $N$ ways, and then choose the other connections. If you ignore the vertex with degree $N-1$, what remains is a graph on $N-1$ vertices where no vertex is connected to every other vertex. Taking the complement, this is equivalent to a graph with on $N-1$ vertices with no isolated vertices.

The problem of counting graphs with no isolated vertices has been discussed multiple times on this site. It can be solved fairly easily in $O(N)$ time using the principle of inclusion-exclusion. See

  1. Number of graphs without isolated vertices, which also points to the relevant OEIS sequence: https://oeis.org/A006129.

  2. Number of directed graphs without isolated vertices (The answer here is for directed graphs, but the logic can be modified to undirected graphs).

Mike Earnest
  • 75,930