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 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 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 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 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 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 edges.
Because each edge independently has two possibilities: connected or not,
there are a total of ways to connect edges.
Prufer Sequence
How many labeled unrooted trees are there?
Cayley's Formula
Cayley's formula states that there are unrooted trees with 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 .
- The degree of node 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 nodes, we can enumerate the size of one subtree, and then the size of the other subtree is determined.
Let denote the number of ways to construct a subtree with nodes.
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 , combine to choose the points and multiply by the number of connected graphs on points ,
and the outside of the connected component can be connected arbitrarily, which is .
Thus we can compute recursively in .
Bipartite Graph Counting
How many labeled bipartite graphs with points and connected components are there?
Let's change our approach and try to find the number of colored bipartite graphs (not necessarily connected).
Enumerate the set of points on one side, then connect edges arbitrarily between the two sides.
At the same time, let be the number of bipartite graphs with points and connected components.
Using a method similar to undirected connected graph counting, fix a point and enumerate the size of the connected component to get:
We see that we cannot find this way. Don't be discouraged; let's try to establish a relationship between and .
For each connected component, we have coloring schemes, so for connected components, there are coloring schemes.
There should be a table here.
| j\i | 1 | 2 | 3 |
|---|---|---|---|
| 1 | 1 | ||
| 2 | 1 | ||
| 3 | 1 |
Our is a parameterized sum over a column of , so when we have the values in this column except , we can get .
All are obvious,
and the recurrence for only needs values with and , which can be obtained by the above method.
Specifically, we enumerate the first dimension in increasing order of , and the second dimension in decreasing order of .
When , we directly recurse; when , we obtain it by subtracting from .
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 be the number of ways to have points and trees.
Each time choose points as one tree to add to the answer: is solved using Cayley's formula.
Finally, multiply by the cyclic permutation:
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 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
0No comments yet.