AlgoBench: Benchmarking Algorithmic Adaptation in Code Generation

Xinyuan Song, Zekun Cai, Liang ZhaoarXiv 2026

TL;DR

Large language models (LLMs) often excel at coding benchmarks by memorizing public solutions rather than demonstrating true algorithmic reasoning. To address this, the authors introduce ALGOBENCH, a framework that automatically transforms existing competitive programming problems via constraint-shifting operations to force models to adapt their code. By introducing a deterministic three-layer complexity verifier, ALGOBENCH reveals that even frontier models frequently fail when forced to adapt beyond memorized templates.

What Problem Does This Paper Address?

Standard programming benchmarks like HumanEval and LiveCodeBench are heavily exposed to data contamination. Because problem statements, editorials, and reference solutions are publicly available on the web, web-scale pretraining corpora often contain near-duplicate problem-solution pairs. As a result, an LLM can achieve a high pass rate simply by recalling a known template rather than deriving an algorithm from first principles.

Furthermore, standard benchmarks rely on pass@k (functional correctness), which fails to verify if a solution is asymptotically optimal. A model might write a slow, naive algorithm that happens to pass under a permissive time limit on small test cases, hiding its lack of true algorithmic competence. The authors address this by asking: How can we automatically generate new algorithmic problems that require adaptation rather than memorization?

Figure 1: Core idea of ALGOBENCH. A standard benchmark may allow an LLM to reuse a familiar template such as Prefix Sum. ALGOBENCH changes the problem so that the original solution fails under the new constraints, and then tests whether the model can produce the required new algorithm, such as Lazy Segment Tree, with the correct asymptotic complexity.

Methods

ALGOBENCH automatically constructs novel algorithmic problems from known source problems using a pipeline of rule-based transformation operators and strict quality filters.

1. Transformation Operators

The framework utilizes ten rule-based operators to alter problems while maintaining traceability to their sources. Key operators include:

  • Constraint Scaling (CS): Increasing input bounds (e.g., $N \le 2000 \rightarrow N \le 2 \times 10^5$), forcing a shift to a faster complexity class (e.g., $O(N^2) \rightarrow O(N \log N)$).
  • Static-to-Dynamic (SD): Introducing online update operations, requiring dynamic data structures (e.g., Prefix Sum $\rightarrow$ Lazy Segment Tree).
  • Greedy-Trap Injection (GT): Adding constraints that invalidate a standard greedy choice, forcing a shift to dynamic programming.
  • Objective Perturbation (OP): Changing the optimization target (e.g., minimizing a total sum vs. minimizing the maximum element).

2. Quality Gates

To ensure validity, every generated problem must pass four quality gates:

  1. Old-Solution Rejection: The original reference solution must fail (via Wrong Answer, Time Limit Exceeded, or Memory Limit Exceeded).
  2. Reference-Solution Verification: A new reference solution must match a brute-force oracle on small inputs.
  3. Similarity Filtering: The text must not be a simple paraphrase of the source.
  4. Complexity Certification: The new reference solution must satisfy the target time/space complexity.

3. Deterministic Complexity Verifier

To evaluate solutions beyond functional correctness, the authors implement a three-layer verifier:

  • Layer 1 (Static AST Analysis): Inspects the abstract syntax tree for loop nesting, recursion depth, and allocation sizes.
  • Layer 2 (Algorithm-Tag Verification): Checks for structural evidence of the required algorithm (e.g., lazy propagation code) and ensures forbidden source algorithms are avoided.
  • Layer 3 (Calibrated Runtime Scaling): Measures execution times across increasing input sizes and fits them to a power-law model to detect suboptimal scaling.

Using this verifier, the paper introduces complexity-aware metrics like OPTT (Optimal Time Complexity Rate), OPTS (Optimal Space Complexity Rate), and TRAPRATE (the rate at which a model falls into the old-solution template).

Figure 2: ALGOBENCH benchmark construction pipeline. Source problems from competitive-programming platforms are transformed by 10 rule-based operators and then filtered through 4 quality gates. The three-layer complexity verifier certifies the OptT/OptS labels for accepted problems.

Datasets

The framework started with 300 seed source problems collected from competitive programming platforms (Codeforces, AtCoder, Kattis, and LeetCode Hard). Applying the transformation operators yielded 1,212 candidate variants. After filtering through the quality gates (which had an overall acceptance rate of 49.3%), the final benchmark resulted in 598 accepted variants. The main experiments were conducted on a primary split of 420 problems.

Key Insights and Ideas

  • The RAG Anchor Trap: While Retrieval-Augmented Generation (RAG) generally improves code generation, providing the original source problem as context can backfire. It often anchors the model to the old, invalid template, significantly increasing the TRAPRATE (e.g., Gemini 2.5 Flash's trap rate jumped from 3.6% to 30.0% under RAG).
  • Correct But Suboptimal: High functional correctness (pass@k) masks severe algorithmic deficiencies. Many models generate code that passes basic test cases but fails to scale, resulting in a large gap between pass@5 and OPTT.
  • Failures are Algorithmic, Not Syntactic: Manual error analysis revealed that 64.1% of LLM failures were purely algorithmic (42.3% falling into the old-solution trap and 21.8% being too slow). Only 9.0% of failures were due to ordinary implementation bugs.

Key Results

  • Performance Drop: When moving from original source problems to shifted ALGOBENCH variants, older models saw an average pass@1 drop of 31.6%, while the latest generation models (like GPT-5.4 and Claude Opus 4.5) still dropped by 33.3%.
  • Complexity Mismatch: For GPT-5.4, while it achieved a decent success rate on some variants, it suffered a 26.7% gap between its pass@5 score and its actual optimal time complexity rate (OPTT).
  • Hardest Transformations: Objective Perturbation (OP) proved to be the most challenging operator, with multiple models scoring 0% correctness, demonstrating that changing the underlying optimization goal completely breaks template-based generation.

Limitations and Future Work

  • Language Support: The deterministic complexity verifier currently only supports Python and C++. Extending support to Java, Go, and Rust is left for future work.
  • Domain Coverage: The dataset is heavily focused on standard competitive programming paradigms. Certain mathematical and algorithmic domains—such as geometry, string algorithms, and number theory—are currently underrepresented.

Summary updated

BibTeX
@misc{song2026algobench,
  author = {Xinyuan Song and Zekun Cai and Liang Zhao},
  title = {{AlgoBench: Benchmarking Algorithmic Adaptation in Code Generation}},
  year = {2026},
  eprint = {2607.00062},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2607.00062},
}
Figure