Counting the Same Structure in Two Ways
Many graph arguments become clearer when we count a collection of objects in two different ways. For instance, one can count pairs of vertices that have a common neighbor by first choosing the neighbor, or by first choosing the pair. The two counts must agree. This simple principle yields useful equalities, checks computations, and can force restrictions on a graph.
Throughout, graphs are finite and simple: there are no loops or multiple edges. The neighborhood \(N(v)\) of a vertex \(v\) is the set of vertices adjacent to it, and \(\deg(v)=|N(v)|\). For distinct vertices \(u,v\), define their common-neighbor count by
We count unordered pairs \(\{u,v\}\), so each pair is considered once, not once in each order. A common neighbor \(x\) of \(u\) and \(v\) gives a length-two path \(u,x,v\), with endpoints \(u,v\). The endpoints are distinct, and in a simple graph \(x\) differs from both of them.
The Basic Common-Neighbor Identity
Proof. Count the objects \((x,\{u,v\})\) for which \(u\) and \(v\) are distinct neighbors of \(x\). If \(x\) is fixed, there are \(\deg(x)\) choices of its neighbors and therefore \(\binom{\deg(x)}{2}\) unordered pairs of distinct neighbors. Summing over \(x\in V\) gives the left-hand side. Alternatively, fix the unordered pair \(\{u,v\}\). The possible choices of \(x\) are exactly the common neighbors of \(u\) and \(v\), so there are \(c(u,v)\) choices. Summing over all unordered pairs gives the right-hand side. Both counts enumerate the same objects. If \(|V|<2\), there are no eligible pairs, and every degree is at most one, so both sides are zero. \(\square\)
The identity counts length-two paths by their middle vertex on the left and by their pair of endpoints on the right. The endpoints need not be adjacent. This matters: the right-hand sum includes all unordered pairs, whether or not they form an edge.
Worked Example: Checking Common-Neighbor Counts
Let \(G\) have vertex set \(\{1,2,3,4,5\}\) and edge set \(\{12,13,23,24,34,45\}\). Compute both sides of the identity.
The neighborhoods are \(N(1)=\{2,3\}\), \(N(2)=\{1,3,4\}\), \(N(3)=\{1,2,4\}\), \(N(4)=\{2,3,5\}\), and \(N(5)=\{4\}\). Thus the degrees are \(2,3,3,3,1\), and the degree-side count is
For the ten unordered vertex pairs, the common-neighbor counts are \(c(1,2)=1\), \(c(1,3)=1\), \(c(1,4)=2\), \(c(1,5)=0\), \(c(2,3)=2\), \(c(2,4)=1\), \(c(2,5)=1\), \(c(3,4)=1\), \(c(3,5)=1\), and \(c(4,5)=0\). Adding gives \(1+1+2+0+2+1+1+1+1+0=10\).
Check: The pair-side total is \(10\), matching the independently calculated degree-side total \(10\). For example, the two common neighbors of \(1\) and \(4\) are \(2\) and \(3\), since \(N(1)\cap N(4)=\{2,3\}\).
Counting Across a Partition
Sometimes only pairs separated by a chosen partition are relevant. Let \(A\) and \(B\) be disjoint sets whose union is \(V\); either set may be empty. For each vertex \(x\), the sets \(N(x)\cap A\) and \(N(x)\cap B\) record its neighbors in the two parts.
Proof. Count triples \((x,a,b)\) such that \(a\in A\), \(b\in B\), and \(xa,xb\in E\). For fixed \(x\), there are \(|N(x)\cap A|\) choices for \(a\), independently of the \(|N(x)\cap B|\) choices for \(b\). This gives the product on the left, and summing over \(x\) counts all such triples. Alternatively, fix \(a\in A\) and \(b\in B\). The eligible vertices \(x\) are exactly the common neighbors of \(a\) and \(b\), giving \(c(a,b)\) choices. Summing over the cross-part pairs gives the right-hand side. If either part is empty, both sides are zero: each product has a zero factor and there are no cross-part pairs. \(\square\)
This identity counts length-two paths whose endpoints lie in different parts. The middle vertex can lie in either part. In particular, the endpoints of these paths are always distinct because the parts are disjoint.
Worked Example: Pairs Across Two Parts
Use the graph with \(V=\{1,2,3,4,5\}\) and \(E=\{12,13,23,24,34,45\}\), and take \(A=\{1,2,5\}\) and \(B=\{3,4\}\). Compute both sides of the partition identity.
For \(x=1\), the neighbors in \(A\) and \(B\) are \(\{2\}\) and \(\{3\}\), so the product is \(1\cdot1=1\). For \(x=2\), they are \(\{1\}\) and \(\{3,4\}\), giving \(1\cdot2=2\). For \(x=3\), they are \(\{1,2\}\) and \(\{4\}\), giving \(2\cdot1=2\). For \(x=4\), they are \(\{2,5\}\) and \(\{3\}\), giving \(2\cdot1=2\). For \(x=5\), they are \(\varnothing\) and \(\{4\}\), giving \(0\cdot1=0\). The left-hand side is therefore \(1+2+2+2+0=7\).
The cross-part pairs are \(\{1,3\},\{1,4\},\{2,3\},\{2,4\},\{5,3\},\{5,4\}\). Their common-neighbor counts are, respectively, \(1,2,2,1,1,0\). For instance, \(N(1)\cap N(4)=\{2,3\}\), while \(N(5)\cap N(4)=\varnothing\). The right-hand side is \(1+2+2+1+1+0=7\).
Check: Both counts give \(7\). The pair \(\{1,4\}\), for example, contributes two triples on the left, one for each common neighbor, \(2\) and \(3\).
Using the Identity to Obtain Constraints
A useful special case occurs when the graph is triangle-free, meaning it has no three vertices that are pairwise adjacent. If \(u\) and \(v\) are adjacent, they cannot have a common neighbor: such a vertex together with the edge \(uv\) would form a triangle. Thus all contributions on the common-neighbor side come from nonedges.
Proof. Apply the basic identity and split its right-hand sum into adjacent and nonadjacent pairs. For an adjacent pair \(u,v\), a common neighbor would make a triangle, so \(c(u,v)=0\). The sum over adjacent pairs is therefore zero, leaving exactly the sum over nonedges. If every nonadjacent pair has at most one common neighbor, each term in that remaining sum is at most one. There are \(\binom{n}{2}-|E|\) nonedges, since a simple graph has \(\binom{n}{2}\) unordered vertex pairs in total and \(|E|\) of them are edges. This proves the inequality. \(\square\)
Worked Example: A Constraint in a Five-Cycle
Let \(G=C_5\) have vertex set \(\{1,2,3,4,5\}\) and edge set \(\{12,23,34,45,51\}\). Verify the constraint and identify the common neighbors of the nonedges.
Every vertex has degree \(2\), so the degree-side sum is \(5\binom{2}{2}=5\). The graph has five edges and \(\binom{5}{2}=10\) unordered pairs, hence \(10-5=5\) nonedges: \(\{1,3\},\{1,4\},\{2,4\},\{2,5\},\{3,5\}\). Their common neighbors are, respectively, \(2,5,3,1,4\). Each pair has exactly one common neighbor, so the nonedge-side sum is \(1+1+1+1+1=5\).
The cycle has no triangle, and each nonedge has at most one common neighbor, so the corollary gives \(5\le 5\). The direct calculations attain equality. As a check on the common-neighbor list, the pair \(\{1,4\}\) has common neighbor \(5\), because both \(15\) and \(45\) are edges.
Four-Cycles from Common Neighbors
Common-neighbor counts can also count cycles. In the formula below, a four-cycle is counted as a cycle subgraph: changing its starting vertex or reversing its direction does not create a new cycle.
Proof. First fix an unordered pair \(\{u,v\}\) and choose two distinct common neighbors \(x,y\). The edges \(ux,xv,vy,yu\) form the four-cycle \(u,x,v,y,u\). Its four vertices are distinct: \(u\ne v\), \(x\ne y\), and neither common neighbor can equal \(u\) or \(v\), since there are no loops. Conversely, a four-cycle has two pairs of opposite vertices. For either opposite pair, its two other vertices are distinct common neighbors. Thus each four-cycle gives exactly two choices counted by the sum, one for each opposite pair, and every choice in the sum gives a four-cycle. The sum counts each four-cycle twice, so division by \(2\) gives the number of four-cycles. If there are fewer than four vertices, the sum is zero because no pair has two distinct common neighbors, as required. \(\square\)
Worked Example: Counting Four-Cycles in \(K_{2,3}\)
Let \(G\) have vertex set \(\{1,2,3,4,5\}\) and edge set \(\{13,14,15,23,24,25\}\). This is the complete bipartite graph with parts \(\{1,2\}\) and \(\{3,4,5\}\). Compute the formula and check by a separate count.
The pair \(\{1,2\}\) has three common neighbors, so it contributes \(\binom{3}{2}=3\). Each pair among \(\{3,4,5\}\) has common neighbors \(1\) and \(2\), so each contributes \(\binom{2}{2}=1\); there are three such pairs, contributing \(3\) in total. Each cross-part pair has no common neighbor: its two neighborhoods lie in opposite parts and are disjoint. The sum is therefore \(3+3+0=6\), and the formula gives \(6/2=3\) four-cycles.
To check independently, every four-cycle must use both vertices \(1,2\) and a pair chosen from \(\{3,4,5\}\). There are \(\binom{3}{2}=3\) choices of that pair, and each produces exactly one cycle. Thus there are \(3\) four-cycles, as the formula gives.
A Common Counting Mistake
Do not count only adjacent pairs in the basic identity. The left-hand side counts every pair of neighbors of each vertex, whether or not those two neighbors are adjacent. Therefore the matching sum on the right must include all unordered pairs, not just edges.
For a concrete error, take the graph with \(V=\{1,2,3\}\) and \(E=\{12,23\}\). Its degrees are \(1,2,1\), so the degree-side sum is \(0+1+0=1\). The only common neighbor belongs to the nonedge pair \(\{1,3\}\), for which \(c(1,3)=1\). If one incorrectly sums only over edges, both edge pairs have common-neighbor count zero, producing \(0\), which fails to match the degree-side total. Including all three pairs gives \(c(1,2)+c(1,3)+c(2,3)=0+1+0=1\), restoring the identity.
There is a related distinction when counting triangles: \(\sum_{\{u,v\}\in E}c(u,v)\) counts each triangle three times, once for each of its edges. It is not the basic identity, whose right-hand side sums over all pairs and counts length-two paths by their endpoints.
Check Your Understanding
Use the definitions and counting arguments above to answer the following.
- For a graph on \(n\) vertices, explain why the basic common-neighbor identity still holds when \(n=0\) or \(n=1\).
- For \(V=\{1,2,3,4\}\) and \(E=\{12,23,34\}\), compute the degree-side sum and list the pairs with a positive common-neighbor count.
- For a partition \(V=A\cup B\), explain why a vertex \(x\) contributes \(|N(x)\cap A|\,|N(x)\cap B|\), rather than a sum of these two neighborhood sizes.
- In a triangle-free graph, why must every pair of adjacent vertices have zero common neighbors?
- Explain why the four-cycle formula divides the sum by \(2\), rather than by \(4\).