# Container method

The method of (hypergraph) containers is a powerful tool that can help characterize the typical structure and/or answer extremal questions about families of discrete objects with a prescribed set of local constraints. Such questions arise naturally in extremal graph theory, additive combinatorics, discrete geometry, coding theory, and Ramsey theory; they include some of the most classical problems in the associated fields.
These problems can be expressed as questions of the following form: given a hypergraph H on finite vertex set V with edge set E (i.e. a collection of subsets of V with some size constraints), what can we say about the independent sets of H (i.e. those subsets of V that contain no element of E)? The hypergraph container lemma provides a method for tackling such questions.

## History

One of the foundational problems of extremal graph theory, dating to work of Mantel in 1907 and Turán from the 1940s, asks to characterize those graphs that do not contain a copy of some fixed forbidden H as a subgraph. In a different domain, one of the motivating questions in additive combinatorics is understanding how large a set of integers can be without containing a k-term arithmetic progression, with upper bounds on this size given by Roth ($k=3$) and Szemerédi (general k).
The method of containers (in graphs) was initially pioneered by Kleitman and Winston in 1980, who bounded the number of lattices and graphs without 4-cycles. Container-style lemmas were independently developed by multiple mathematicians in different contexts, notably including Sapozhenko, who initially used this approach in 2002-2003 to enumerate independent sets in regular graphs, sum-free sets in abelian groups, and study a variety of other enumeration problems
A generalization of these ideas to a hypergraph container lemma was devised independently by Saxton and Thomason and Balogh, Morris, and Samotij in 2015, inspired by a variety of previous related work.

## Main idea and informal statement

Many problems in combinatorics can be recast as questions about independent sets in graphs and hypergraphs. For example, suppose we wish to understand subsets of integers 1 to n, which we denote by $[n]$ that lack a k-term arithmetic progression. These sets are exactly the independent sets in the k-uniform hypergraph $H=(\{1,2,\ldots ,n\},E)$, where E is the collection of all k-term arithmetic progressions in $\{1,2,\ldots ,n\}$.
In the above (and many other) instances, there are usually two natural classes of problems posed about a hypergraph H:
* What is the size of a maximum independent set in H? What does the collection of maximum-sized independent sets in H look like?
* How many independent sets does H have? What does a "typical" independent set in H look like?
These problems are connected by a simple observation. Let $\alpha (H)$ be the size of a largest independent set of H and suppose $H$ has $i(H)$ independent sets. Then,
    $2^{\alpha (H)}\leq i(H)\leq \sum _{r=0}^{\alpha (H)}{|V(H)| \choose r},$
where the lower bound follows by taking all subsets of a maximum independent set. These bounds are relatively far away from each other unless $\alpha (H)$ is very large, close to the number of vertices of the hypergraph. However, in many hypergraphs that naturally arise in combinatorial problems, we have reason to believe that the lower bound is closer to the true value; thus the primary goal is to improve the upper bounds on i(H).
The hypergraph container lemma provides a powerful approach to understanding the structure and size of the family of independent sets in a hypergraph. At its core, the hypergraph container method enables us to extract from a hypergraph, a collection of containers, subsets of vertices that satisfy the following properties:
* There are not too many containers.
* Each container is not much larger than the largest independent set.
* Each container has few edges.
* Every independent set in the hypergraph is fully included in some container.
The name container alludes to this last condition. Such containers often provide an effective approach to characterizing the family of independent sets (subsets of the containers) and to enumerating the independent sets of a hypergraph (by simply considering all possible subsets of a container).
The hypergraph container lemma achieves the above container decomposition in two pieces. It constructs a deterministic function f. Then, it provides an algorithm that extracts from each independent set I in hypergraph H, a relatively small collection of vertices $S\subset I$, called a fingerprint, with the property that $S\subset I\subset S\cup f(S)$. Then, the containers are the collection of sets $S\cup f(S)$ that arise in the above process, and the small size of the fingerprints provides good control on the number of such container sets.

## Graph container algorithm

We first describe a method for showing strong upper bounds on the number of independent sets in a graph; this exposition is adapted from a survey of Samotij about the graph container method, originally employed by Kleitman-Winston and Sapozhenko.

### Notation

We use the following notation in the below section.
* $G=(V,E)$ is a graph on $|V|=n$ vertices, where the vertex set is equipped with (arbitrary) ordering $\{v_{1},\ldots ,v_{n}\}$.
* Let $\ell (G)$ be the collection of independent sets of G with size $i(G):=|\ell (G)|$. Let $i(G,r)$ be the number of independent sets of size r.
* The max-degree ordering of a vertex subset $A\subset V$ is the ordering of the vertices in A by their degree in the induced subgraph $G[A]$.

### Kleitman-Winston algorithm

The following algorithm gives a small "fingerprint" for every independent set in a graph and a deterministic function of the fingerprint to construct a not-too-large subset that contains the entire independent set
Fix graph G, independent set $I\in \ell (G)$ and positive integer $q\leq |I|$.
* Initialize: let $A=V(G),S=\emptyset$.
* Iterate for $s=1,2,\ldots ,q$:
** Construct the max-degree ordering of $A,\,(v_{1},\ldots v_{|A|})$
** Find the minimal index $j_{s}$ such that $v_{j_{s}}\in I$ (i.e. the vertex in A of largest degree in induced subgraph G[A])
** Let $S\leftarrow S\cup \{v_{j_{s}}\},\,A\leftarrow A\backslash (\{v_{1},\ldots ,v_{j_{s}}\}\cup N(v_{j_{s}}))$, where $N(v)$ is the neighborhood of vertex $v$.
* Output the vector $(j_{1},\ldots ,j_{q})$ and the vertex set $A\cap I$.

### Analysis

By construction, the output of the above algorithm has property that $\{v_{j_{1}},\ldots ,v_{j_{q}}\}\subset I\subset \{v_{j_{1}},\ldots ,v_{j_{q}}\}\cup (A\cap I)$, noting that $A\cap I$ is a vertex subset that is completely determined by $\{j_{1},\ldots ,j_{q}\}$ and not otherwise a function of $I$. To emphasize this we will write $A=A(j_{1},\ldots ,j_{q})$. We also observe that we can reconstruct the set $S=\{v_{j_{1}},\ldots ,v_{j_{q}}\}=S(j_{1},\ldots j_{q})$ in the above algorithm just from the vector $(j_{1},\ldots ,j_{q})$.
This suggests that $S$ might be a good choice of a fingerprint and $S(j_{1},\ldots j_{q})\cup A(j_{1},\ldots ,j_{q})$ a good choice for a container. More precisely, we can bound the number of independent sets of $G$ of some size $r\geq q$ as a sum over output sequences $(j_{1},\ldots j_{q})$
    $i(G,r)=\sum _{(j_{s})_{s=1}^{q}}i(G[A(j_{1},\ldots j_{q})],r-q)\leq \sum _{(j_{s})}{A(j_{1},\ldots j_{q}) \choose r-q}$,
where we can sum across $r$ to get a bound on the total number of independent sets of the graph:
    $i(G)=\sum _{r=0}^{q-1}{n \choose r}+\sum _{(j_{s})_{s=1}^{q}}i(G[A(j_{1},\ldots j_{q})])\leq \sum _{r=0}^{q-1}{n \choose r}+\sum _{(j_{s})}2^{|A(j_{1},\ldots j_{q})|}$.
When trying to minimize this upper bound, we want to pick $q$ that balances/minimizes these two terms. This result illustrates the value of ordering vertices by maximum degree (to minimize $|A(j_{1},\ldots j_{q})|$).

### Lemmas

The above inequalities and observations can be stated in a more general setting, divorced from an explicit sum over vectors $(j_{s})$.
Lemma 1: Given a graph $G$ with $n$ and assume that integer $q$ and real numbers $R,\beta \in [0,1]$ satisfy $R\geq e^{-\beta q}n$. Suppose that every induced subgraph on at least $R$ vertices has edge density at least $\beta$. Then for every integer $r\geq q$,
    $i(G,r)\leq {n \choose q}{R \choose r-q}.$
Lemma 2: Let $G$ be a graph on $n$ vertices and assume that an integer $q$ and reals $R,D$ are chosen such that $n\leq R+qD$. If all subsets $U$ of at least $R$ vertices have at least $D|U|/2$ edges, then there is a collection ${\mathcal {F}}$ of subsets of $q$ vertices ("fingerprints") and a deterministic function $f\colon {\mathcal {C}}\rightarrow {\mathcal {P}}(V(G))$, so that for every independent set $I\subset V(G)$, there is $S\in {\mathcal {F}}$ such that $S\subset I\subset f(S)\cup S$.

## Hypergraph container lemma

Informally, the hypergraph container lemma tells us that we can assign a small fingerprint $S\subset I$ to each independent set, so that all independent sets with the same fingerprint belong to the same larger set, $C=f(S)$, the associated container, that has size bounded away from the number of vertices of the hypergraph. Further, these fingerprints are small (and thus there are few containers), and we can upper bound their size in an essentially optimal way using some simple properties of the hypergraph.
We recall the following notation associated to $k$ uniform hypergraph ${\mathcal {H}}$.
* Define $\Delta _{l}({\mathcal {H}}):=\max\{d_{H}(A)\mid A\subset V({\mathcal {H}}),|A|=l\}$ for positive integers $1\leq l\leq k$, where $d_{\mathcal {H}}(A)=|\{e\in E({\mathcal {H}})\mid A\subset e\}|$.
* Let ${\mathcal {I}}({\mathcal {H}})$ be the collection of independent sets of ${\mathcal {H}}$. $I$ will denote some such independent set.

### Statement

We state the version of this lemma found in a work of Balogh, Morris, Samotij, and Saxton.
Let ${\mathcal {H}}$ be a $k$-uniform hypergraph and suppose that for every $l\in \{1,2,\ldots ,k\}$ and some $b,r\in \mathbb {N}$, we have that $\Delta _{l}(H)\leq \left({\frac {b}{|V(H)|}}\right)^{l-1}{\frac {|E(H)|}{r}}$. Then, there is a collection ${\mathcal {C}}\subset {\mathcal {P}}(V(H))$ and a function $f\colon {\mathcal {P}}(V(H))\rightarrow {\mathcal {C}}$ such that
* for every $I\in {\mathcal {I}}(H)$ there exists $S\subset I$ with $|S|\leq (k-1)b$ and $I\subset f(S)$.
* $|C|\leq |V(H)|-\delta r$ for every $C\in {\mathcal {C}}$ and $\delta =2^{-k(k+1)}$.

## Example applications
### Regular graphs
#### Upper bound on the number of independent sets

We will show that there is an absolute constant C such that every $n$-vertex $d$-regular graph $G$ satisfies $i(G)\leq 2^{\left(1+C{\sqrt {\frac {\log d}{d}}}\right){\frac {n}{2}}}$.
We can bound the number of independent sets of each size $r$ by using the trivial bound $i(G,r)\leq {n \choose r}\leq {n \choose n/10}\leq 2^{0.48n}$ for $r\leq n/10$. For larger $r$, take $\beta >10/n,q=\lfloor 1/\beta \rfloor ,R={\frac {n}{2}}+{\frac {\beta n^{2}}{2d}}.$ With these parameters, d-regular graph $G$ satisfies the conditions of Lemma 1 and thus,
    $i(G,r)\leq {n \choose q}{R \choose r-q}\leq {n \choose q}{{\frac {n}{2}}+{\frac {\beta n^{2}}{2d}} \choose r-q}\leq \left({\frac {en}{q}}\right)^{q}{{\frac {n}{2}}+{\frac {\beta n^{2}}{2d}} \choose r-q}\leq (e\beta n)^{\lfloor 1/\beta \rfloor }{{\frac {n}{2}}+{\frac {\beta n^{2}}{2d}} \choose r-q}.$
Summing over all $0\leq r\leq n$ gives
    $i(G)\leq 2^{0.49n}+2^{{\frac {n}{2}}+{\frac {\beta n^{2}}{2d}}+\lfloor 1/\beta \rfloor \log _{2}(e\beta n)}$,
which yields the desired result when we plug in $\beta ={\sqrt {d\log d}}/n.$

#### Sum-free sets

A set $A$ of elements of an abelian group is called sum-free if there are no $x,y,z\in A$ satisfying $x+y=z$. We will show that there are at most $2^{(1/2+o(1))n}$ sum-free subsets of $[n]:=\{1,2,\ldots ,n\}$.
This will follow from our above bounds on the number of independent sets in a regular graph. To see this, we will need to construct an auxiliary graph. We first observe that up to lower order terms, we can restrict our focus to sum-free sets with at least $n^{2/3}$ elements smaller than $n/2$ (since the number of subsets in the complement of this is at most $(n/2)^{n^{2/3}}2^{n/2+1}$).
Given some subset $S\subset \{1,2,\ldots ,\lceil n/2\rceil -1\}$, we define an auxiliary graph $G_{S}$ with vertex set $[n]$ and edge set $\{\{x,y\}\mid x+s\equiv y{\pmod {n}}{\text{ for some }}s\in S\cup (-S)\}$, and observe that our auxiliary graph is $2|S|$ regular since each element of S is smaller than $n/2$. Then if $S_{A}$ are the smallest $n^{2/3}$ elements of subset $A\subset [n]$, the set $A\backslash S_{A}$ is an independent set in the graph $G_{S_{A}}$. Then, by our previous bound, we see that the number of sum-free subsets of $[n]$ is at most
    $(n/2)^{n^{2/3}}2^{n/2+}+{n/2 \choose n^{2/3}}2^{(1+O(n^{-1/3}{\sqrt {\log n}})){\frac {n}{2}}}\leq 2^{(1/2+O(n^{-1/3}\log n))n}.$

### Triangle-free graphs

We give an illustration of using the hypergraph container lemma to answer an enumerative question by giving an asymptotically tight upper bound on the number of triangle-free graphs with $n$ vertices.

#### Informal statement

Since bipartite graphs are triangle-free, the number of triangle free graphs with $n$ vertices is at least $2^{\lfloor n^{2}/4\rfloor }$, obtained by enumerating all possible subgraphs of the balanced complete bipartite graph $K_{\lfloor n/2\rfloor ,\lceil n/2\rceil }$.
We can construct an auxiliary 3-uniform hypergraph H with vertex set $V(H)=E(K_{n})$ and edge set $E(H)=\{\{e_{1},e_{2},e_{3}\}\subset E(K_{n})=V(H)\mid e_{1},e_{2},e_{3}{\text{ form a triangle}}\}$. This hypergraph "encodes" triangles in the sense that the family of triangle-free graphs on $n$ vertices is exactly the collection of independent sets of this hypergraph, ${\mathcal {I}}(H)$.
The above hypergraph has a nice degree distribution: each edge of $K_{n}$, and thus vertex in $V(H)$ is contained in exactly $n-2$ triangles and each pair of elements in $V(H)$ is contained in at most 1 triangle. Therefore, applying the hypergraph container lemma (iteratively), we are able to show that there is a family of $n^{O(n^{3/2})}$ containers that each contain few triangles that contain every triangle-free graph/independent set of the hypergraph.

#### Upper bound on the number of triangle-free graphs

We first specialize the generic hypergraph container lemma to 3-uniform hypergraphs as follows:
Lemma: For every $c>0$, there exists $\delta >0$ such that the following holds. Let $H$ be a 3-uniform hypergraph with average degree $d\geq 1/\delta$ and suppose that $\Delta _{1}(H)\leq cd,\Delta _{2}(H)\leq c{\sqrt {d}}$. Then there exists a collection ${\mathcal {C}}\subset {\mathcal {P}}(V(H))$ of at most $|{\mathcal {C}}|\leq {|V(H)| \choose |V(H)|/{\sqrt {d}}}$ containers such that
* for every $I\in {\mathcal {I}}(H)$, there exists $I\subset C\in {\mathcal {C}}$
* $|C|\leq (1-\delta )|V(H)|$ for all $C\in {\mathcal {C}}$
Applying this lemma iteratively will give the following theorem (as proved below):
Theorem: For all $\epsilon >0$, there exists $C>0$ such that the following holds. For each positive integer n, there exists a collection ${\mathcal {G}}$ of graphs on n vertices with $|{\mathcal {G}}|\leq n^{Cn^{3/2}}$ such that
* each $G\in {\mathcal {G}}$ has fewer than $\epsilon n^{3}$ triangles,
* each triangle-free graph on $n$ vertices is contained in some $G\in {\mathcal {G}}$.
Proof: Consider the hypergraph $H$ defined above. As observed informally earlier, the hypergraph satisfies $|V(H)|={n \choose 2},\Delta _{2}(H)=1,d(v)=n-2$ for every $v\in V(H)$. Therefore, we can apply the above Lemma to $H$ with $c=1$ to find some collection ${\mathcal {C}}$ of $n^{O(n^{3/2})}$ subsets of $E(K_{n})$ (i.e. graphs on $n$ vertices) such that
* every triangle free graph is a subgraph of some $C\in {\mathcal {C}}$,
* every $C\in {\mathcal {C}}$ has at most $(1-\delta ){n \choose 2}$ edges.
This is not quite as strong as the result we want to show, so we will iteratively apply the container lemma. Suppose we have some container $C\in {\mathcal {C}}$ with at least $\epsilon n^{3}$ triangles. We can apply the container lemma to the induced sub-hypergraph $H[C]$. The average degree of $H[C]$ is at least $6\epsilon n$, since every triangle in $C$ is an edge in $H[C]$, and this induced subgraph has at most ${n \choose 2}$ vertices. Thus, we can apply Lemma with parameter $c=1/\epsilon$, remove $C$ from our set of containers, replacing it by this set of containers, the containers covering ${\mathcal {I}}(H[C])$.
We can keep iterating until we have a final collection of containers ${\mathcal {C}}$ that each contain fewer than $\epsilon n^{3}$ triangles. We observe that this collection cannot be too big; all of our induced subgraphs have at most ${n \choose 2}$ vertices and average degree at least $6\epsilon n$, meaning that each iteration results in at most $n^{O(n^{3/2})}$ new containers. Further, the container size shrinks by a factor of $1-\delta$ each time, so after a bounded (depending on $\epsilon$) number of iterations, the iterative process will terminate.