# Transformers Provably Learn Graph Search: Training Dynamics and the Exponential Power of Depth

DevFeed: [Transformers Provably Learn Graph Search: Training Dynamics and the Exponential Power of Depth](<https://devfeed.tech/articles/transformers-provably-learn-graph-search-training-dynamics-and-the-exponential-power-of-depth-128332.md>)

Original publisher: [Read original article](<https://arxiv.org/abs/2611.13594>)

Author: Xutao Ma, Somayeh Sojoudi

Published: 2026-11-11T05:00:00Z

Content type: article

Language: en

Sources: [arXiv: Artificial Intelligence](<https://devfeed.tech/sources/arxiv-artificial-intelligence.md>)

Topics: [llm-reasoning](<https://devfeed.tech/topics/llm-reasoning.md>), [Transformers](<https://devfeed.tech/topics/transformers.md>), [Machine learning](<https://devfeed.tech/topics/machine-learning.md>), [graph theory](<https://devfeed.tech/topics/graph-theory.md>)

Tags: [cs-ai](<https://devfeed.tech/tags/cs-ai.md>), [dfs](<https://devfeed.tech/tags/dfs.md>), [graph](<https://devfeed.tech/tags/graph.md>), [large-language-models-llms](<https://devfeed.tech/tags/large-language-models-llms.md>), [reasoning](<https://devfeed.tech/tags/reasoning.md>), [search](<https://devfeed.tech/tags/search.md>), [training](<https://devfeed.tech/tags/training.md>), [transformers](<https://devfeed.tech/tags/transformers.md>)

## AI overview

For directed-graph path finding, the paper's analysis says a second transformer layer changes the size needed for DFS: one layer requires Ω(N²) size on dense graphs for the key child-selection primitive, while two layers implement full DFS with O(N log N) size. For every k >= 3, it reports that k layers implement a bounded-reachability DFS policy with look-ahead horizon 1 + 2^(k−3). It also shows that two-layer transformers can learn DFS through gradient flow and generalize to unseen graphs, given appropriately curated training data.

## Source excerpt

arXiv:2611.13594v1 Announce Type: new Abstract: Large Language Models (LLMs) have achieved remarkable progress on complex reasoning tasks, yet the mechanisms by which they acquire reasoning capabilities and the efficiency of their reasoning remain poorly understood. In this paper, we investigate the path-finding problem over directed graphs, a symbolic abstraction of multi-step reasoning. We first characterize the architectural requirements for this task, proving that one-layer transformers require $\Omega(N^2)$ size on dense graphs to implement the key DFS child-selection primitive. While a two-layer transformer implements full DFS with $O(N\log(N))$ size. Thus, a second layer is necessary and sufficient for near-linear DFS reasoning. We then extend this expressivity analysis to deeper models: for every $k\geq3$, a $k$-layer transformer implements a bounded-reachability DFS policy with look-ahead horizon $1+2^{k-3}$, establishing an exponential increase in reachability horizon with depth. Finally, going beyond expressivity, given appropriately curated training data, we show that two-layer transformers can provably learn to execute DFS via gradient flow and generalize to unseen graphs. Together, our results provide a mechanistic account of how transformers implement graph search, how depth expands bounded look-ahead, and how such reasoning algorithms can emerge through training.