Strange Counting Added

Here are some common graph counting routines. Since my polynomial skills are zero, I won't optimize the formulas. If you find any issues with the formulas or know how to optimize them, please tell me directly. Undirected graph counting: How many undirected graphs with nn nodes are there? To improve the reading experience of a blog that nobody would read anyway, let's start with something simple. Consider that each point can connect at most one edge to each remaining point, for a total of n1n-1 edges. Since it's an undirected graph, each edge is counted once by each of its two endpoints, so an undirected graph can have at most n(n1)2\frac{n(n-1)}{2} edges. Because

Here are some common graph counting routines. Since my polynomial skills are zero, I won't optimize the formulas. If you find any issues with the formulas or know how to optimize them, please tell me directly.

Undirected Graph Counting

How many undirected graphs with nn nodes are there?

To improve the reading experience of a blog that nobody would read anyway, let's start with something simple.

Consider that each point can connect at most one edge to each remaining point, for a total of n1n-1 edges,
Since it's an undirected graph, each edge is counted once by each of its two endpoints,
so an undirected graph can have at most n(n1)2\frac{n(n-1)}{2} edges.

Because each edge independently has two possibilities: connected or not,
there are a total of 2n(n1)22^{\frac{n(n-1)}{2}} ways to connect edges.

Prufer Sequence

How many labeled unrooted trees are there?

Cayley's Formula

Cayley's formula states that there are nn2n^{n-2} unrooted trees with nn nodes.

The Prufer sequence demonstrates a bijection between a sequence and a labeled unrooted tree,
that is, the number of sequences satisfying a certain rule is the number of labeled unrooted trees.

The Prufer sequence was designed to prove Cayley's formula.

Construction

Try to prove the bijection between sequences and labeled unrooted trees, which can help us understand this formula.
Of course, we can also directly memorize such a simple formula.

Given a tree, how do we construct its Prufer sequence?

According to the definition of the Prufer sequence, each time remove the leaf with the smallest label and record the edge it connects to, until two nodes remain.

Given a sequence, how do we construct a tree using the Prufer method?

Observing the construction method, we get some information:

  • Among the remaining two points, one must be node nn.
  • The degree of node ii is the number of times it appears in the sequence plus 1.
  • From the previous point, nodes not appearing in the sequence are leaf nodes.

After we get all leaf nodes, we can add points in the same way as removing points.
The first value in the sequence is the edge connected to the smallest leaf node, and so on.
Maintain a min-heap; if a new leaf node is generated, add it to the heap.
Finally, two points remain, connect them directly.

It can be seen that a tree can construct a unique sequence, and a sequence can construct a unique tree.

Binary Tree Counting

How many unlabeled binary trees with N points are there? (Binary trees are rooted by default, and symmetry is not considered the same)

Recursive Method

For a binary tree with NN nodes, we can enumerate the size of one subtree, and then the size of the other subtree is determined.
Let fif_i denote the number of ways to construct a subtree with ii nodes. fi=j=0i1fj×fi1jf_i=\sum_{j=0}^{i-1}{f_j \times f_{i-1-j}}

Catalan Numbers

We find that the above formula is the recurrence for Catalan numbers, so we can also directly use the Catalan number formula to solve it.

We can consider the bijection between valid bracket sequences and binary trees.
Consider the origin of the Catalan recurrence: each time a bracket is added, enumerate the number of valid bracket sequences inside the bracket and to the right of the bracket.
Extended to binary trees, each time match the first left bracket; the inside of the bracket is the left subtree, and the right of the bracket is the right subtree.

Undirected Connected Graph Counting

How many labeled undirected connected graphs are there?

Consider an inclusion-exclusion, subtracting the disconnected connection ways from all connection ways.

We fix a point and enumerate the size of the connected component it belongs to.
Let the size of the connected component be jj, combine to choose the jj points and multiply by the number of connected graphs on jj points fjf_j,
and the outside of the connected component can be connected arbitrarily, which is 2(nj)(nj1)22^{\frac{(n-j)(n-j-1)}{2}}.

fi=2n(n1)2j=1i1Ci1j1×fj×2(ij)(ij1)2f_i= 2^{\frac{n(n-1)}{2}} -\sum_{j=1}^{i-1}{ C_{i-1}^{j-1} \times f_j \times 2^{\frac{(i-j)(i-j-1)}{2}} }

Thus we can compute recursively in O(n2)O(n^2).

Bipartite Graph Counting

How many labeled bipartite graphs with nn points and mm connected components are there?

Let's change our approach and try to find the number of colored bipartite graphs SS (not necessarily connected).
Enumerate the set of points on one side, then connect edges arbitrarily between the two sides.
Sn=i=0nCni×2i(ni)S_n= \sum_{i=0}^{n}{ C_{n}^{i} \times 2^{i(n-i)} }

At the same time, let fi,jf_{i,j} be the number of bipartite graphs with ii points and jj connected components.
Using a method similar to undirected connected graph counting, fix a point and enumerate the size of the connected component to get:
fi,j=k=1ij+1Cikk1×fk,1×fik,j1f_{i,j}= \sum_{k=1}^{i-j+1}{ C_{i-k}^{k-1} \times f_{k,1} \times f_{i-k,j-1} }

We see that we cannot find fi,1f_{i,1} this way. Don't be discouraged; let's try to establish a relationship between SS and ff.
For each connected component, we have 22 coloring schemes, so for ii connected components, there are 2i2^{i} coloring schemes.
Sn=i=1nfn,i×2iS_n=\sum_{i=1}^{n}{ f_{n,i} \times 2^{i} }

There should be a table here.

j\i 1 2 3
1 1
2 1
3 1

Our SnS_n is a parameterized sum over a column of ff, so when we have the values in this column except fn,1f_{n,1}, we can get fn,1f_{n,1}.
All fi,if_{i,i} are obvious,
and the recurrence for fi,jf_{i,j} only needs values with i<ii'<i and j<jj'<j, which can be obtained by the above method.

Specifically, we enumerate the first dimension in increasing order of ii, and the second dimension in decreasing order of jj.
When j>1j>1, we directly recurse; when j=1j=1, we obtain it by subtracting from SnS_n.

Base Cycle Tree Counting

How many labeled base cycle trees are there?

This problem is actually simpler than the previous one QwQ.

If we have a forest, we just need to arrange all trees in a cycle.
Let fi,jf_{i,j} be the number of ways to have ii points and jj trees.

Each time choose kk points as one tree to add to the answer: fi,j=k=1ij+1Cik×fk,1×fik,j1f_{i,j}= \sum_{k=1}^{i-j+1}{ C_{i}^{k} \times f_{k,1} \times f_{i-k,j-1} } fk,1f_{k,1} is solved using Cayley's formula.

Finally, multiply by the cyclic permutation: i=3nfn,i×(i1)!2\sum_{i=3}^{n}{ f_{n,i} \times \frac{(i-1)!}{2} }

An Expected Value Problem

Why does this appear here? Probably because it was covered in class, so I put it here.

On the number line, there are 2n2n positions. Fill each position with a bracket to make the entire sequence a valid bracket sequence. What is the expected distance of a pair of brackets?

Comments

0

No comments yet.