arXiv:2610.02438cs.LGOct 2026

Manuscript Offprint

arXiv:2610.02438

Are you Synthesizing or Recalling? Evaluating LLMs on Algorithmic Code Retrieval

Nickil Maveli, Antonio Vergari, Shay B. Cohen

Abstract

Large language models (LLMs) have demonstrated strong performance in code generation, where success depends on both recalling relevant algorithmic knowledge and reasoning about how to apply it. However, existing LLM pipelines are opaque, with no explicit separation between these two components. We argue that for well-known algorithms whose canonical implementations are widely accessible in pretraining corpora, code generation is better measured as parametric code retrieval: reproducing a named algorithm from internalised knowledge rather than synthesizing a novel one. We introduce ALGOREVAL, a benchmark of 599 problems spanning classical 77 algorithms across 14 domains, 7 programming languages, and 4 graph-input representations to evaluate this capability in isolation, and assess 15 models (7B–34B parameters) in a zero-shot setting. We find substantial variation in retrieval accuracy across languages and input representations, even for widely documented algorithms and show that prompt augmentation with retrieved code snippets or structured algorithmic hints improve accuracy on complex algorithms, while SFT achieves broader language gains and GRPO achieves larger per-language gains on specific languages. Together, our results establish parametric code retrieval as a distinct, measurable capability and caution against deploying AI-generated algorithmic code without systematic validation. 1^{1}

1 Introduction

When an LLM writes Dijkstra’s algorithm, is it synthesizing, retrieving, or reciting? Synthesizing means reasoning from the problem statement to a solution, deriving logic the model has not seen in the exact form during pre-training (Chen et al., 2021; Austin et al., 2021b). Retrieving means reconstructing a correct implementation from inter-

Prim, dense regime: model tiers vs. two real reference implementations networkx (no early exit) k=2.28 | early-exit-heap k=2.10

Figure

Figure 1: Ten LLMs implement Prim’s MST algorithm, split into a fast tier (4 models) and a slow tier (6 models) by wall-clock scaling. We time two independently-written, correctness-verified reference implementations. Since both tiers land close to a real, legitimate pattern rather than one looking like an unexplained outlier, the evidence here is symmetric and consistent with both tiers reflecting retrieval of different existing implementations, not one retrieving and the other synthesizing from scratch.

nalised parametric knowledge. The model has encoded the algorithm’s structure, invariants, and control flow in its weights and can express it correctly even in forms it has not seen verbatim (Roberts et al., 2020; Gekhman et al., 2026). Reciting means replaying a near-verbatim token sequence cached from a specific training example: correct output is a side-effect of having stored that string, not of understanding what it computes (Carlini et al., 2023; Huang et al., 2024). Synthesis, retrieval, and recitation are distinct capabilities with different failure modes and different implications for reliability: synthesis may fail on novel problems; retrieval degrades when surface form shifts away from the training distribution; recitation breaks the moment the expected transcription is absent. Prior work conflates all three under the label of code

1^{1}Code and dataset are available at https://github.com/Nickil21/AlgoREval. denotes shared supervision.

Figure

Figure 2: Parametric code retrieval evaluation pipeline. LLMs generate solutions zero-shot, drawing solely on algorithmic knowledge encoded in their pretraining weights. The four panels show four models (three open-weight, one closed API) on the same Bridge Finding problem, each in a different language: Yi-Coder-9B (Python) uses self.time in a plain function with no class, causing a runtime error; CodeLlama-34B (Rust) passes graph by value where a reference is required, producing a compile error; gpt-4o-mini (Java, closed API) finds the correct bridges but omits the sort step, yielding wrong output order; QwQ-32B (JavaScript) normalises, sorts, and passes.

generation.

We focus on the “retrieval” aspect. The distinction has real stakes: an estimated 72% of developers now use AI coding tools on a daily basis, and AI currently generates 42% of all committed code. 2^{2} Yet, 66% report their top frustration is code that is almost right, but not quite, which precisely describes retrieval failure: the model knows the algorithm but gets a detail wrong (Zhu et al., 2025). In agentic coding pipelines, where models plan, generate, and commit code without per-step human review, a retrieval failure in a graph algorithm may not surface until a production incident exposes the wrong output being computed silently (Sapkota et al., 2025; Cemri et al., 2025). Knowing where and how retrieval breaks is the minimum information needed to decide when AI-generated algorithmic code can be trusted without verification.

Most code generation research frames the task as synthesis: given a problem statement, construct a solution. This is appropriate for novel problems, but for well-known algorithms whose canonical implementations appear across thousands of open-source repositories and almost certainly in the pre-training corpora of every model we evaluate. The model need not invent anything; it must retrieve. Conflating the two obscures a distinct failure mode: a model may demonstrate impressive synthesis on novel tasks while quietly failing to reproduce even the most widely documented algorithms, or vice-versa (Riddell et al., 2024; Matton et al., 2024). We isolate this as parametric code retrieval: reproducing a correct implementation of a named algorithm in a specified language from parametric memory alone. Code constitutes roughly 13% of the Dolma corpus (411 B of 3.1 T tokens) (Kocetkov et al., 2022; Soldaini et al., 2024), with JavaScript (486 GB), Java (271 GB), and C (222 GB) accounting for over half by volume, which are precisely the language families our benchmark targets.

Contributions. We introduce ALGOREVAL, a benchmark of 599 problems spanning 77 algorithms, 7 programming languages, and 4 graph-input representations, and evaluate fifteen models zero-shot. We then ask whether retrieval failures can be remediated: first via prompt augmentation with retrieved code snippets or structured algorithmic hints, and then via GRPO (Group Relative Policy Optimization) fine-tuning with execution-based rewards compared against a SFT (Supervised fine-tuning) baseline. Our main findings are threefold. First, retrieval accuracy varies widely across models, and the variance is governed by surface form (programming language and input representa-

2^{2}https://www.sonarsource.com/ state-of-code-developer-survey-report.pdf tion) and not model size or code specialisation. The dominant failure mode in Python and JavaScript is wrong output: runnable code that silently returns the wrong answer. Second, prompt augmentation does not reliably improve retrieval in aggregate, and actively hurts when parametric knowledge is already present; executable snippets are more effective than abstract hints only on problems where the model's parametric trace is already thin. Third, GRPO fine-tuning with execution-based rewards converges faster than SFT and closes language gaps that binary supervision cannot address, particularly in Rust where partial-credit signals from compile failures carry information that correct/incorrect labels discard.