# Expander code

Expander codes
bipartite expander graph
Classification
Type Linear block code
Block length ${\displaystyle n}$
Message length ${\displaystyle n-m}$
Rate ${\displaystyle 1-m/n}$
Distance ${\displaystyle 2(1-\epsilon )\gamma \cdot n}$
Alphabet size ${\displaystyle 2}$
Notation ${\displaystyle [n,n-m,2(1-\epsilon )\gamma \cdot n]_{2}}$-code

In coding theory, expander codes form a class of error-correcting codes that are constructed from bipartite expander graphs. Along with Justesen codes, expander codes are of particular interest since they have a constant positive rate, a constant positive relative distance, and a constant alphabet size. In fact, the alphabet contains only two elements, so expander codes belong to the class of binary codes. Furthermore, expander codes can be both encoded and decoded in time proportional to the block length of the code. Expander codes are the only known asymptotically good codes which can be both encoded and decoded from a constant fraction of errors in polynomial time.

## Expander codes

In coding theory, an expander code is a ${\displaystyle [n,n-m]_{2}\,}$ linear block code whose parity check matrix is the adjacency matrix of a bipartite expander graph. These codes have good relative distance ${\displaystyle 2(1-\varepsilon )\gamma \,}$, where ${\displaystyle \varepsilon \,}$ and ${\displaystyle \gamma \,}$ are properties of the expander graph as defined later), rate ${\displaystyle \left(1-{\tfrac {m}{n}}\right)\,}$, and decodability (algorithms of running time ${\displaystyle O(n)\,}$ exist).

## Definition

Consider a bipartite graph ${\displaystyle G(L,R,E)\,}$, where ${\displaystyle L\,}$ and ${\displaystyle R\,}$ are the vertex sets and ${\displaystyle E\,}$ is the set of edges connecting vertices in ${\displaystyle L\,}$ to vertices of ${\displaystyle R\,}$. Suppose every vertex in ${\displaystyle L\,}$ has degree ${\displaystyle d\,}$ (the graph is ${\displaystyle d\,}$-regular), ${\displaystyle |L|=n\,}$, and ${\displaystyle |R|=m\,}$, ${\displaystyle m. Then ${\displaystyle G\,}$ is a ${\displaystyle (N,M,d,\gamma ,\alpha )\,}$ expander graph if every small enough subset ${\displaystyle S\subset L\,}$, ${\displaystyle |S|\leq \gamma n\,}$ has the property that ${\displaystyle S\,}$ has at least ${\displaystyle d\alpha |S|\,}$ distinct neighbors in ${\displaystyle R\,}$. Note that this holds trivially for ${\displaystyle \gamma \leq {\tfrac {1}{n}}\,}$. When ${\displaystyle {\tfrac {1}{n}}<\gamma \leq 1\,}$ and ${\displaystyle \alpha =1-\varepsilon \,}$ for a constant ${\displaystyle \varepsilon \,}$, we say that ${\displaystyle G\,}$ is a lossless expander.

Since ${\displaystyle G\,}$ is a bipartite graph, we may consider its ${\displaystyle n\times m\,}$ adjacency matrix. Then the linear code ${\displaystyle C\,}$ generated by viewing the transpose of this matrix as a parity check matrix is an expander code.

It has been shown that nontrivial lossless expander graphs exist. Moreover, we can explicitly construct them.[1]

## Rate

The rate of ${\displaystyle C\,}$ is its dimension divided by its block length. In this case, the parity check matrix has size ${\displaystyle m\times n\,}$, and hence ${\displaystyle C\,}$ has dimension at least ${\displaystyle (n-m)/n=1-{\tfrac {m}{n}}\,}$.

## Distance

Suppose ${\displaystyle \varepsilon <{\tfrac {1}{2}}\,}$. Then the distance of a ${\displaystyle (n,m,d,\gamma ,1-\varepsilon )\,}$ expander code ${\displaystyle C\,}$ is at least ${\displaystyle 2(1-\varepsilon )\gamma n\,}$.

### Proof

Note that we can consider every codeword ${\displaystyle c\,}$ in ${\displaystyle C\,}$ as a subset of vertices ${\displaystyle S\subset L\,}$, by saying that vertex ${\displaystyle v_{i}\in S\,}$ if and only if the ${\displaystyle i\,}$th index of the codeword is a 1. Then ${\displaystyle c\,}$ is a codeword iff every vertex ${\displaystyle v\in R\,}$ is adjacent to an even number of vertices in ${\displaystyle S\,}$. (In order to be a codeword, ${\displaystyle cP=0\,}$, where ${\displaystyle P\,}$ is the parity check matrix. Then, each vertex in ${\displaystyle R\,}$ corresponds to each column of ${\displaystyle P\,}$. Matrix multiplication over ${\displaystyle {\text{GF}}(2)=\{0,1\}\,}$ then gives the desired result.) So, if a vertex ${\displaystyle v\in R\,}$ is adjacent to a single vertex in ${\displaystyle S\,}$, we know immediately that ${\displaystyle c\,}$ is not a codeword. Let ${\displaystyle N(S)\,}$ denote the neighbors in ${\displaystyle R\,}$ of ${\displaystyle S\,}$, and ${\displaystyle U(S)\,}$ denote those neighbors of ${\displaystyle S\,}$ which are unique, i.e., adjacent to a single vertex of ${\displaystyle S\,}$.

#### Lemma 1

For every ${\displaystyle S\subset L\,}$ of size ${\displaystyle |S|\leq \gamma n\,}$, ${\displaystyle d|S|\geq |N(S)|\geq |U(S)|\geq d(1-2\varepsilon )|S|\,}$.

#### Proof

Trivially, ${\displaystyle |N(S)|\geq |U(S)|\,}$, since ${\displaystyle v\in U(S)\,}$ implies ${\displaystyle v\in N(S)\,}$. ${\displaystyle |N(S)|\leq d|S|\,}$ follows since the degree of every vertex in ${\displaystyle S\,}$ is ${\displaystyle d\,}$. By the expansion property of the graph, there must be a set of ${\displaystyle d(1-\varepsilon )|S|\,}$ edges which go to distinct vertices. The remaining ${\displaystyle d\varepsilon |S|\,}$ edges make at most ${\displaystyle d\varepsilon |S|\,}$ neighbors not unique, so ${\displaystyle U(S)\geq d(1-\varepsilon )|S|-d\varepsilon |S|=d(1-2\varepsilon )|S|\,}$.

#### Corollary

Every sufficiently small ${\displaystyle S\,}$ has a unique neighbor. This follows since ${\displaystyle \varepsilon <{\tfrac {1}{2}}\,}$.

#### Lemma 2

Every subset ${\displaystyle T\subset L\,}$ with ${\displaystyle |T|<2(1-\varepsilon )\gamma n\,}$ has a unique neighbor.

#### Proof

Lemma 1 proves the case ${\displaystyle |T|\leq \gamma n\,}$, so suppose ${\displaystyle 2(1-\varepsilon )\gamma n>|T|>\gamma n\,}$. Let ${\displaystyle S\subset T\,}$ such that ${\displaystyle |S|=\gamma n\,}$. By Lemma 1, we know that ${\displaystyle |U(S)|\geq d(1-2\varepsilon )|S|\,}$. Then a vertex ${\displaystyle v\in U(S)\,}$ is in ${\displaystyle U(T)\,}$ iff ${\displaystyle v\notin N(T\setminus S)\,}$, and we know that ${\displaystyle |T\setminus S|\leq 2(1-\varepsilon )\gamma n-\gamma n=(1-2\varepsilon )\gamma n\,}$, so by the first part of Lemma 1, we know ${\displaystyle |N(T\setminus S)|\leq d(1-2\varepsilon )\gamma n\,}$. Since ${\displaystyle \varepsilon <{\tfrac {1}{2}}\,}$, ${\displaystyle |U(T)|\geq |U(S)\setminus N(T\setminus S)|\geq |U(S)|-|N(T\setminus S)|>0\,}$, and hence ${\displaystyle U(T)\,}$ is not empty.

#### Corollary

Note that if a ${\displaystyle T\subset L\,}$ has at least 1 unique neighbor, i.e. ${\displaystyle |U(T)|>0\,}$, then the corresponding word ${\displaystyle c\,}$ corresponding to ${\displaystyle T\,}$ cannot be a codeword, as it will not multiply to the all zeros vector by the parity check matrix. By the previous argument, ${\displaystyle c\in C\implies wt(c)\geq 2(1-\varepsilon )\gamma n\,}$. Since ${\displaystyle C\,}$ is linear, we conclude that ${\displaystyle C\,}$ has distance at least ${\displaystyle 2(1-\varepsilon )\gamma n\,}$.

## Encoding

The encoding time for an expander code is upper bounded by that of a general linear code - ${\displaystyle O(n^{2})\,}$ by matrix multiplication. A result due to Spielman shows that encoding is possible in ${\displaystyle O(n)\,}$ time.[2]

## Decoding

Decoding of expander codes is possible in ${\displaystyle O(n)\,}$ time when ${\displaystyle \varepsilon <{\tfrac {1}{4}}\,}$ using the following algorithm.

Let ${\displaystyle v_{i}\,}$ be the vertex of ${\displaystyle L\,}$ that corresponds to the ${\displaystyle i\,}$th index in the codewords of ${\displaystyle C\,}$. Let ${\displaystyle y\in \{0,1\}^{n}\,}$ be a received word, and ${\displaystyle V(y)=\{v_{i}|{\text{ the }}i^{\text{th}}{\text{ position of }}y{\text{ is a }}1\}\,}$. Let ${\displaystyle e(i)\,}$ be ${\displaystyle |\{v\in R|N(v)\cap V(y)\,}$ is even${\displaystyle \}|\,}$, and ${\displaystyle o(i)\,}$ be ${\displaystyle |\{v\in R|N(v)\cap V(y)\,}$ is odd${\displaystyle \}|\,}$. Then consider the greedy algorithm:

Input: received codeword ${\displaystyle y\,}$.

initialize y' to y
while there is a v in R adjacent to an odd number of vertices in V(y')
if there is an i such that o(i) > e(i)
flip entry i in y'
else
fail


Output: fail, or modified codeword ${\displaystyle y'\,}$.

### Proof

We show first the correctness of the algorithm, and then examine its running time.

#### Correctness

We must show that the algorithm terminates with the correct codeword when the received codeword is within half the code's distance of the original codeword. Let the set of corrupt variables be ${\displaystyle S\,}$, ${\displaystyle s=|S|\,}$, and the set of unsatisfied (adjacent to an odd number of vertices) vertices in ${\displaystyle R\,}$ be ${\displaystyle c\,}$. The following lemma will prove useful.

##### Lemma 3

If ${\displaystyle 0, then there is a ${\displaystyle v_{i}\,}$ with ${\displaystyle o(i)>e(i)\,}$.

##### Proof

By Lemma 1, we know that ${\displaystyle U(S)\geq d(1-2\varepsilon )s\,}$. So an average vertex has at least ${\displaystyle d(1-2\varepsilon )>d/2\,}$ unique neighbors (recall unique neighbors are unsatisfied and hence contribute to ${\displaystyle o(i)\,}$), since ${\displaystyle \varepsilon <{\tfrac {1}{4}}\,}$, and thus there is a vertex ${\displaystyle v_{i}\,}$ with ${\displaystyle o(i)>e(i)\,}$.

So, if we have not yet reached a codeword, then there will always be some vertex to flip. Next, we show that the number of errors can never increase beyond ${\displaystyle \gamma n\,}$.

##### Lemma 4

If we start with ${\displaystyle s<\gamma (1-2\varepsilon )n\,}$, then we never reach ${\displaystyle s=\gamma n\,}$ at any point in the algorithm.

##### Proof

When we flip a vertex ${\displaystyle v_{i}\,}$, ${\displaystyle o(i)\,}$ and ${\displaystyle e(i)\,}$ are interchanged, and since we had ${\displaystyle o(i)>e(i)\,}$, this means the number of unsatisfied vertices on the right decreases by at least one after each flip. Since ${\displaystyle s<\gamma (1-2\varepsilon )n\,}$, the initial number of unsatisfied vertices is at most ${\displaystyle d\gamma (1-2\varepsilon )n\,}$, by the graph's ${\displaystyle d\,}$-regularity. If we reached a string with ${\displaystyle \gamma n\,}$ errors, then by Lemma 1, there would be at least ${\displaystyle d\gamma (1-2\varepsilon )n\,}$ unique neighbors, which means there would be at least ${\displaystyle d\gamma (1-2\varepsilon )n\,}$ unsatisfied vertices, a contradiction.

Lemmas 3 and 4 show us that if we start with ${\displaystyle s<\gamma (1-2\varepsilon )n\,}$ (half the distance of ${\displaystyle C\,}$), then we will always find a vertex ${\displaystyle v_{i}\,}$ to flip. Each flip reduces the number of unsatisfied vertices in ${\displaystyle R\,}$ by at least 1, and hence the algorithm terminates in at most ${\displaystyle m\,}$ steps, and it terminates at some codeword, by Lemma 3. (Were it not at a codeword, there would be some vertex to flip). Lemma 4 shows us that we can never be farther than ${\displaystyle \gamma n\,}$ away from the correct codeword. Since the code has distance ${\displaystyle 2(1-\varepsilon )\gamma n>\gamma n\,}$ (since ${\displaystyle \varepsilon <{\tfrac {1}{2}}\,}$), the codeword it terminates on must be the correct codeword, since the number of bit flips is less than half the distance (so we couldn't have traveled far enough to reach any other codeword).

#### Complexity

We now show that the algorithm can achieve linear time decoding. Let ${\displaystyle {\tfrac {n}{m}}\,}$ be constant, and ${\displaystyle r\,}$ be the maximum degree of any vertex in ${\displaystyle R\,}$. Note that ${\displaystyle r\,}$ is also constant for known constructions.

1. Pre-processing: It takes ${\displaystyle O(mr)\,}$ time to compute whether each vertex in ${\displaystyle R\,}$ has an odd or even number of neighbors.
2. Pre-processing 2: We take ${\displaystyle O(dn)=O(dmr)\,}$ time to compute a list of vertices ${\displaystyle v_{i}\,}$ in ${\displaystyle L\,}$ which have ${\displaystyle o(i)>e(i)\,}$.
3. Each Iteration: We simply remove the first list element. To update the list of odd / even vertices in ${\displaystyle R\,}$, we need only update ${\displaystyle O(d)\,}$ entries, inserting / removing as necessary. We then update ${\displaystyle O(dr)\,}$ entries in the list of vertices in ${\displaystyle L\,}$ with more odd than even neighbors, inserting / removing as necessary. Thus each iteration takes ${\displaystyle O(dr)\,}$ time.
4. As argued above, the total number of iterations is at most ${\displaystyle m\,}$.

This gives a total runtime of ${\displaystyle O(mdr)=O(n)\,}$ time, where ${\displaystyle d\,}$ and ${\displaystyle r\,}$ are constants.