Which Algorithms Can Graph Neural Networks Learn?

Solveig Wittig, Antonis Vasileiou, Robert R Nerem, Timo Stoll, Floris Geerts, Yusu Wang, Christopher Morris

Introduction

In recent years, Neural Algorithmic Reasoning (NAR) has emerged as a promising field aiming to integrate the rigorous logic of classical discrete algorithms—such as Dijkstra's or Bellman-Ford—into neural network pipelines. Because of their permutation equivariance and ability to handle sparse, variable-sized inputs, Message-Passing Neural Networks (MPNNs) are the architecture of choice for these tasks.

However, a significant "Generalization Gap" remains. While we know MPNNs are expressive enough to mimic these algorithms, existing research is largely empirical or relies on non-differentiable constraints. If a Graph Neural Network (GNN) is trained on graphs with 10 nodes, will it successfully execute the algorithm on a graph with 10,000 nodes? This paper provides a general theoretical framework establishing the formal conditions under which GNNs can learn an algorithm from finite data and provably generalize to arbitrary sizes with worst-case guarantees.

The Challenge: Size Generalization

The fundamental hurdle in NAR is ensuring that a model doesn't just memorize algorithmic steps for a specific input size but actually learns the underlying logic to apply it at any scale. Most prior theoretical work focuses solely on expressivity—proving a network can represent an algorithm—but leaves open the question of how and when it will generalize beyond its finite training set. This paper bridges the gap between learning theory and graph topology to answer this exact question.

Theoretical Framework and Methodology

The authors introduce several key techniques to guarantee size generalization:

  • Finite Lipschitz Framework: The paper defines a "finite Lipschitz class" for GNNs. If a hypothesis class is Lipschitz-continuous (meaning small changes in the input lead to bounded changes in the output) and the input space has a manageable geometry (finite covering numbers), the model is provably learnable from a finite dataset.
  • Metric Spaces for Graphs: By equipping graph spaces with pseudo-metrics based on computation trees and Hausdorff distances, the authors prove that standard aggregators like mean, sum, and max/min satisfy the requirements for size generalization.
  • Differentiable $\ell_1$ Regularization: For the Bellman-Ford algorithm (used for shortest paths), previous non-differentiable $\ell_0$ penalties are replaced with a specific, layer-weighted $\ell_1$ regularization. This allows the model to be trained via standard gradient descent while enforcing the sparsity necessary for algorithmic logic.
  • Node Individualization (1-iWL): The authors establish impossibility results for standard MPNNs, proving they are fundamentally limited in learning algorithms like Minimum Spanning Trees (MST) or Single-Source Shortest Paths (SSSP). To overcome symmetry issues, the GNN requires "individualized" nodes (e.g., marking a source node), leading to more expressive architectures like 1-iWL.

Key Findings and Results

The theoretical claims are supported by empirical tests across synthetic graphs (Erdős-Rényi, Stochastic Block Models, Star, and Complete graphs) and real-world benchmarks (Cora and Citeseer citation networks).

  • Provable Extrapolation: GNNs trained on tiny, specifically constructed path graphs successfully generalized to graphs with up to 1024 nodes with near-zero error. This strongly supports the paper's theory of "regularization-induced extrapolation."
  • The Role of Regularization: In NAR, regularization acts as a complexity control mechanism. It forces the GNN to stay within the Lipschitz bounds required for the theoretical guarantees to hold. The proposed differentiable $\ell_1$ regularizer proved significantly more stable and yielded lower generalization errors than standard $\ell_1$ or $\ell_2$ norms.
  • Expressivity is Crucial: Standard 1-WL GNNs failed to generalize on general datasets (achieving a test score of ~0.83). In contrast, the more expressive 1-iWL architecture achieved near-perfect scores (~0.003), confirming that node individualization is strictly necessary for SSSP tasks.
  • Generalization as a Geometric Problem: The ability to generalize depends heavily on the "covering number" of the graph space. For graphs with unbounded degrees, the space becomes too complex for standard MPNNs to satisfy learnability criteria unless the aggregation mechanism is normalized.

Limitations and Future Directions

While this framework represents a major step forward for Neural Algorithmic Reasoning, the authors note several limitations:

  • Exponential Scaling: In the Bellman-Ford analysis, the regularization parameter $\eta$ and the training edge weights scale exponentially with the number of algorithmic steps ($K$). This could make learning algorithms with very long execution paths difficult.
  • Constructive Covers: The paper proves that "good" training sets exist via $\epsilon$-covers, but actually finding these sets for complex, non-shortest-path algorithms remains a practical challenge.
  • Beyond Polynomial Time: The current framework is restricted to polynomial-time algorithms. Extending these guarantees to NP-hard problems or approximation algorithms is a major open direction.
  • Optimization Convergence: The theoretical guarantees assume the model successfully reaches a small training loss. However, it does not guarantee that gradient descent will always find this global minimum in practice.

Summary updated

BibTeX
@inproceedings{wittig2026which,
  author = {Solveig Wittig and Antonis Vasileiou and Robert R Nerem and Timo Stoll and Floris Geerts and Yusu Wang and Christopher Morris},
  title = {{Which Algorithms Can Graph Neural Networks Learn?}},
  booktitle = {International Conference on Machine Learning},
  year = {2026},
  url = {https://openreview.net/forum?id=GnmuZIlvxw},
}
Figure