---
title: Berlekamp–Massey Algorithm
url: https://www.emergentmind.com/topics/berlekamp-massey-algorithm
type: topic
---

# Berlekamp–Massey Algorithm

The Berlekamp–Massey algorithm is a fundamental algorithm in coding theory and computer algebra for determining the minimal linear recurrence relation that a finite sequence over a field satisfies. Its core applications include efficient decoding of Reed–Solomon and BCH codes, cryptanalysis, sequence synthesis, and the theory of shift registers. The algorithm has powerful multivariate generalizations—most notably, the Berlekamp–Massey–Sakata (BMS) algorithm—crucial for decoding multidimensional cyclic and abelian codes and for multivariate sparse interpolation. The BM algorithm’s theoretical foundation is closely linked to minimal polynomial theory, linear feedback shift-register synthesis, extended Euclidean algorithms, and Gröbner basis computation.

## 1. Minimal Linear Recurrence Problem and Connection Polynomial

Given a sequence \(s_0, s_1, \ldots, s_{N-1}\) over a field \(\mathbb{F}\), the goal is to find the monic polynomial \(C(x) = 1 + c_1x + \cdots + c_Lx^L\) of least degree \(L\) such that
\[
\sum_{j=0}^L c_j s_{n-j} = 0
\]
for all \(n \geq L\). The minimal such \(C(x)\) is known as the connection polynomial or error-locator polynomial; \(L\) defines the linear complexity of the sequence [1001.1597], [2107.02582], [1709.07168]. In coding theory, for Reed–Solomon codes, the BM algorithm computes the error-locator and error-evaluator polynomials required to solve the key equation fundamental to syndrome-based decoding [2108.02758], [1310.2473], [0908.2198].

## 2. The Classical Berlekamp–Massey Algorithm

### 2.1. Algorithmic Structure

The BM algorithm iterates over the sequence, maintaining:
- The current minimal polynomial \( C(x) \)
- A backup polynomial \( B(x) \) (the last instance where \(C(x)\)'s degree increased)
- Degree \(L\) of \(C(x)\)
- The last discrepancy \(b\) and its associated index \(m\)

At each index \(n\), the discrepancy is calculated as
\[
\Delta_n = s_n + \sum_{i=1}^{L} c_i s_{n-i}
\]
If \(\Delta_n = 0\), \(C(x)\) remains unchanged. If \(\Delta_n \neq 0\), \(C(x)\) is updated by shifting and combining with \(B(x)\):
\[
C(x) \leftarrow C(x) - (\Delta_n / b) x^{n-m} B(x)
\]
If \(2L \leq n\), then \(B(x), b, m\) are updated accordingly, and \(L\) increases to \(n+1-L\) [1709.07168], [1301.7236], [1310.2473].

### 2.2. Pseudocode
```python
def berlekamp_massey(sequence):
    N = len(sequence)
    C = [1] + [0]*N    # connection polynomial
    B = [1] + [0]*N    # backup polynomial
    L, m, b = 0, -1, 1
    for n in range(N):
        # Compute discrepancy
        d = sequence[n]
        for i in range(1, L+1):
            d += C[i] * sequence[n-i]
        if d == 0:
            continue
        T = C[:]
        for i in range(N-n+m):
            C[n-m+i] -= d / b * B[i]
        if 2*L <= n:
            L = n+1-L
            B = T[:]
            b = d
            m = n
    return C[:L+1], L
```
The above pseudocode is conceptual; exact field arithmetic and degree handling must be respected [1709.07168], [2211.11721].

### 2.3. Correctness and Complexity

After at most \(N\) steps, the minimal connection polynomial is constructed. The complexity is \(O(N^2)\) in naive arithmetic, or \(O(N\log N)\) with FFT-based convolution. At each step, only \(L\) coefficients are updated [1001.1597], [2107.02582].

## 3. Algebraic Foundations and Minimal Polynomials

The BM algorithm is equivalent to the process of finding the unique minimal polynomial that annihilates the sequence. This connection is formalized via annihilator ideals and Laurent polynomial action: for \((s_1,\dots,s_n) \in D^n\) (a domain), the minimal polynomial \(f(x) \in D[x]\) satisfies
\[
\sum_{k=0}^d f_k s_{j-d+k} = 0, \quad \forall j > d
\]
The minimal polynomial construction leads to the same recursive update as the BM algorithm via reciprocal pairs and shift operators, as shown by Norton [1001.1597]. This gives rise to alternative iterative and recursive implementations, with total operation count bounded by \(2\lfloor n^2/4 \rfloor\) multiplications in a field.

## 4. Links to the Euclidean Algorithm and Key Equations

### 4.1. Key Equation for Reed–Solomon and Dual Codes

The BM algorithm can be interpreted as a specialized instance of the extended Euclidean algorithm, solving the key equation
\[
\Lambda(x)S(x) \equiv \Omega(x) \pmod{x^{n-k}}
\]
in Reed–Solomon decoding, where \(\Lambda(x)\) is the error-locator polynomial and \(\Omega(x)\) the error-evaluator. The Euclidean recursion
\[
f_i(x) S(x) - g_i(x) (x^n-1) = r_i(x)
\]
yields the same recurrence and update structure as the BM algorithm, with discrepancies mapped to the leading coefficients of remainders [0908.2198], [2108.02758].

### 4.2. Modified and Reverse Variants

The BM framework extends to cases with arbitrary moduli, such as the reverse BM algorithm for general \(m(x)\), yielding minimal \(A(x)\) with bounded-degree remainder in \(b(x)A(x) \bmod m(x)\) [1301.7236]. This is essential for decoding with punctured or shortened codes, and for algebraic inversion in quotient rings.

## 5. Generalizations: The Berlekamp–Massey–Sakata Algorithm

### 5.1. Multivariate Recurrences and the BMS Algorithm

The Berlekamp–Massey–Sakata (BMS) algorithm generalizes BM to multivariate sequences and arrays, seeking minimal sets of bivariate (or multivariate) polynomials annihilating a multidimensional data array \(U=(U_{n_1,\ldots,n_s})\). The BMS algorithm produces a Gröbner basis for the ideal of relations by iteratively constructing minimal generators over a chosen monomial ordering [2401.10527], [1709.07168].

### 5.2. Application to Abelian and AG Codes

In two dimensions and for abelian codes, the BMS algorithm efficiently computes Gröbner bases characterizing locator ideals from a reduced set of syndrome observations. With suitable index set selection \(S(t)\) of size \(O(t^2)\), the final iterate yields the complete Gröbner basis for the ideal, greatly reducing syndrome sampling requirements compared to naive methods [2401.10527].

### 5.3. Handling Missing Syndrome Values and Syndrome Inference

For practical scenarios where some syndrome values are unavailable, recent work [2509.14835] introduces inference techniques that allow the BMS algorithm to proceed and reconstruct missing data. The algorithms leverage redundancy in the structure to infer or parametrize missing syndromes, culminating in a unique solution by local consistency checks.

## 6. Complexity, Optimizations, and Output-Sensitive Algorithms

### 6.1. Complexity

- Classical BM: \(O(N^2)\) operations, \(N\) sequence samples.
- BMS (2D): Up to \(O(N^4)\) in worst case, but using minimal index sets reduces to \(O(t^4)\), where \(t\) is the designed error-correction radius [2401.10527].
- Output-sensitive polynomial division-based variants can further exploit the structure for quasi-linear arithmetic complexity and minimal sequence queries, especially in high dimensions [2107.02582].

### 6.2. Comparison with Scalar-FGLM and Interpolation Algorithms

The Scalar-FGLM algorithm computes relations via linear algebra on Hankel matrices and is particularly effective for dense or nearly square staircase shapes but incurs high cost for sparse, large multivariate data. The BMS algorithm is shift/add-based and typically requires fewer table queries, making it more efficient for sparse or output-sensitive Gröbner basis computation [1709.07168], [2107.02582].

| Algorithm                | Dimension | Arithmetic Complexity        | Sequence Queries      |
|--------------------------|-----------|-----------------------------|----------------------|
| Berlekamp–Massey         | 1         | \(O(N^2)\) or \(O(N\log N)\)| \(N+1\)              |
| BMS (Sakata)             | \(>1\)    | \(O(\#\text{monomials} \times |G|)\)| \(\#T[a^2]\)      |
| Scalar-FGLM              | \(>1\)    | \(O((\#T)^3)\)              | \(\#T\)              |
| Poly Scalar-FGLM         | \(>1\)    | output-sensitive \(O(|S|^{2.5})\)| \(2|S|\)          |

## 7. Extensions, Non-linear Generalizations, and Open Problems

### 7.1. Non-linear Feedback Synthesis

The classical BM algorithm produces optimal linear feedback models only. For synthesis of minimal nonlinear binary \(k\)-stage machines, algorithmic extensions have been introduced that construct Boolean state machines generating any given binary sequence, optimizing for stage count but potentially incurring exponential support in the resulting logic [1009.5802].

### 7.2. Simultaneous and Interleaved Decoding

For interleaved codes or simultaneous key equations (Simultaneous Partial Inverse, SPI), BM-type algorithms exist that ensure uniqueness and degree bounds for the minimal polynomial solution across multiple sequences, generalizing the classical multi-sequence BM of Feng–Tzeng [1612.07854].

### 7.3. Syndrome Majority Voting and Inference for Multivariate Codes

Recent advances allow the BMS algorithm to function with partial syndrome information, reconstructing missing values via combinatorial and algebraic methods (including monomial-order switching and parametric updates), directly paralleling Feng–Rao majority voting in the one-point AG code case [2509.14835].

### 7.4. Adaptive and Lazy Variants

Variants of the BM algorithm supporting lazy evaluation, dynamic extension when the minimal degree is unknown, and fully division-based restatements offer improved flexibility and implementation simplicity, essential for large sparse linear algebra and on-the-fly computation [2211.11721].

---

**References**
- [1709.07168] In-depth comparison of the Berlekamp -- Massey -- Sakata and the Scalar-FGLM algorithms: the non adaptive variants.
- [2401.10527] A new approach to the Berlekamp-Massey-Sakata Algorithm. Improving Locator Decoding.
- [2509.14835] Inference of unknown syndrome values in the implementation of the Berlekamp-Massey-Sakata algorithm.
- [1001.1597] The Berlekamp-Massey Algorithm via Minimal Polynomials.
- [2107.02582] Polynomial-Division-Based Algorithms for Computing Linear Recurrence Relations.
- [2211.11721] The Berlekamp-Massey Algorithm revisited.
- [0908.2198] The Berlekamp-Massey Algorithm and the Euclidean Algorithm: a Closer Link.
- [2108.02758] The Key Equation for One-Point Codes.
- [1310.2473] Improved Decoding Algorithms for Reed-Solomon Codes.
- [1009.5802] Synthesis of Binary k-Stage Machines.
- [1301.7236] Reverse Berlekamp-Massey Decoding.
- [1612.07854] Simultaneous Partial Inverses and Decoding Interleaved Reed-Solomon Codes.

Source: https://www.emergentmind.com/topics/berlekamp-massey-algorithm