Tree Sampling for Reinforcement Learning in Automated Algorithm Design with LLMs

Rui Zhang, Ping Guo, Liyong Lin, Zhichao Lu, Qingfu ZhangNeurIPS 2026

TL;DR

When Large Language Models (LLMs) design new algorithms, a brilliant conceptual idea is often discarded simply because its single generated code implementation had a minor bug or a bad hyperparameter. Algorithm Tree Policy Optimization (ATPO) fixes this by branching each natural-language idea into a tree of multiple executable code candidates, allowing reinforcement learning to separately judge the potential of an idea from the quality of its code. By giving credit where credit is due, LLMs learn genuine algorithmic intuition that transfers across unseen problem instances and completely different search frameworks.

What Problem Does This Paper Address?

Using LLMs for Automated Algorithm Design (LLM-AAD)—like DeepMind’s FunSearch or AlphaEvolve—typically treats the LLM as a frozen generator inside an evolutionary loop: prompt the model with good past programs, test the new ones, keep the winners, and repeat.

Recently, researchers started adding online Reinforcement Learning (RL) so the LLM itself improves from evaluator feedback during the search. However, existing RL methods rely on linear rollouts: one prompt yields one natural-language idea/plan, which yields one code snippet, receiving one final score.

Figure 1: Overview of the LLM-AAD framework with online policy optimization and comparison of rollout structures. (a) The search framework repeatedly selects existing algorithms to construct prompts that guide the generation of new algorithms, while evaluator feedback from the online rollout is used to optimize the policy. (b) Existing methods follow a linear rollout, with each sampled trajectory containing one idea/plan and one code candidate. The training signal is derived solely from the evaluation of the final code candidate. (c) Our tree-based rollout branches each prompt into multiple ideas and each idea into multiple code implementations, enabling idea-level potential estimation from multiple implementations and separate training signals for ideas and code.

Here is the catch: a single code execution is a terrible proxy for an idea's true worth. If the LLM dreams up a clever heuristic for the Traveling Salesman Problem but makes a syntax error or picks a poor weight (0.5 instead of 0.1), outcome-level RL punishes both the code and the underlying idea. Intermediate reasoning gets noisy credit, steering the search away from promising conceptual territory.

Methods

ATPO plugs directly into standard search backbones (FunSearch, EoH, and OpenEvolve) without altering their outer population loops. What’s new is how it generates candidates and updates the LLM policy (via LoRA and Group Relative Policy Optimization, or GRPO):

  1. Two-Level Tree Sampling: Instead of a linear chain, each search prompt branches into $N_I$ distinct natural-language ideas, and each idea branches into $N_C$ executable code implementations (e.g., $4 \times 4 = 16$ leaves per prompt).
  2. Optimistic Idea Aggregation: Leaf codes are scored by the task evaluator (with penalties for syntax or runtime errors). To score a parent idea, ATPO doesn't take a plain average—because an idea's value lies in its achievable potential, not its worst attempt. Instead, it takes a temperature-controlled softmax over the Top-$K$ best child codes.
  3. Two-Level Credit Assignment: ATPO computes two distinct normalized advantages: an inter-idea advantage (comparing different ideas under the same prompt) and a within-idea advantage (comparing sibling code implementations of the same idea). These signals update the model either as a weighted trajectory-wide scalar or via disjoint token masks (training idea tokens solely on idea advantages, and code tokens on code advantages).
  4. Breakthrough Replay Buffer: Alongside the standard program database, ATPO caches "breakthrough prompts"—contexts that yielded historical best scores—replaying them once if the search stagnates.
Figure 2: Overall pipeline integrating ATPO into an LLM-AAD search framework. (a) Existing LLM-AAD search methods, such as FunSearch and AlphaEvolve, maintain an evolving population of candidate programs, iteratively select promising algorithms to construct prompts, request LLMs to generate new algorithms, and update the population for future exploration. (b) For each selected prompt, we perform a tree-structured rollout: we first generate multiple idea candidates and then expand each idea into multiple code implementations, which are executed and scored by the task evaluator. (c) Code-level scores are computed for each leaf and aggregated upward into idea-level scores. We estimate idea-level advantages by comparing ideas generated under the same prompt, and code-level advantages by comparing implementations of the same idea. (d) The resulting prompt, idea, and code tokens are assembled into training batches for policy optimization. Valid algorithms and breakthrough prompts are registered in the population and the replay buffer, respectively.

Datasets

ATPO requires no supervised fine-tuning (SFT) datasets; it learns purely online from evaluator feedback on three classic combinatorial benchmarks adapted from the LLM4AD platform:

  • Admissible Set Problem (ASP): Constrained mathematical set construction.
  • Online Bin Packing (OBP): Sequential, online decision-making.
  • Traveling Salesman Problem (TSP): Constructive routing heuristics.

No new benchmarks are introduced, though the authors generate held-out test instances using separate random seeds to test generalization.

Key Insights and Ideas

  • Naive RL can actually hurt algorithm search: Standard GRPO underperforms the frozen base LLM in several settings! Without tree branching, noisy single-sample code failures actively mislead the policy away from good ideas.
  • True conceptual transfer: Because ATPO rewards ideas based on reliable multi-code estimates rather than lucky instance-specific quirks, an LLM trained inside FunSearch can be dropped zero-shot into EoH or OpenEvolve and immediately accelerate search on unseen instances.
  • Search and RL are symbiotic: Ablations show that RL without an evolving search population stagnates due to repetitive prompts, while search without RL hits a ceiling because the generator never internalizes feedback.
  • Bigger models aren't automatically better: On ASP and OBP, Qwen2.5-1.5B frequently matches or beats Qwen2.5-7B, echoing prior findings that raw parameter count doesn't guarantee better heuristic exploration.

Key Results

Under a matched budget of 20,000 evaluator calls using Qwen2.5-1.5B and Qwen2.5-7B, ATPO consistently lowers the average relative optimality gap (lower is better) of the top-5 discovered algorithms:

  • Big wins on TSP (Qwen2.5-7B): Integrating ATPO slashes FunSearch's relative gap from 11.31% to 7.90% (whereas standard GRPO worsened it to 13.41%). With OpenEvolve, ATPO drops the gap from 13.23% to 8.35%.
  • Cross-Search Generalization: Taking a Qwen2.5-7B policy trained via FunSearch + ATPO and deploying it zero-shot on held-out TSP instances (2,000-evaluation budget) beats both base and GRPO-trained models across all frameworks—for example, improving EoH from 15.20% (base) to 11.26%.
  • Top-$K$ vs. Mean: Using Top-$K$ idea aggregation beats simple mean averaging on ASP (6.17% vs. 6.74% gap), confirming that ideas should be judged by their best instantiations.

Limitations and Future Work

  • Compute vs. Evaluator Budget: Comparisons strictly match the number of algorithm evaluations (20,000), not wall-clock time, GPU-hours, or generated tokens.
  • Finite Sampling & Parsing Quirks: Four code samples per idea reduce variance but remain vulnerable to sampling luck. Furthermore, marker-based text parsing doesn't strictly prevent the LLM from leaking code details into the idea segment (or vice versa).
  • Not a universal sweep & narrow transfer: ATPO occasionally trails standard GRPO (e.g., EoH on TSP: 9.05% vs. 8.89%) or the base model (FunSearch 1.5B on OBP). Also, policy transfer is only demonstrated within the same problem type, not across entirely different domains (like TSP to Bin Packing).
  • Future Directions: Dynamically allocating more code samples to high-uncertainty ideas, and deduplicating/cleaning rollout trajectories to better coordinate evolutionary search databases with online RL updates.

Summary updated

Abstract

Large Language Model-based Automated Algorithm Design (LLM-AAD) has shown promising results across diverse domains by coupling LLMs with iterative search. Recent efforts have begun to combine this paradigm with reinforcement learning (RL), using reward feedback from algorithm evaluators to update the LLM and better guide subsequent algorithm generation. However, these methods still rely primarily on outcome-level supervision. As a result, intermediate ideas and plans receive no direct credit, even though they guide the direction of algorithm design. We introduce Algorithm Tree Policy Optimization (ATPO), a reinforcement learning method that can be integrated into the algorithm-generation stage of existing LLM-based automated algorithm design methods. ATPO employs tree-based sampling to expand each idea into multiple executable code implementations, using their evaluation outcomes to estimate idea-level quality and provide structured credit at both the idea and code levels. Experiments integrating ATPO with FunSearch, EoH, and OpenEvolve demonstrate improvements over their original counterparts. The learned policy also transfers to held-out problem instances and alternative search methods, suggesting its potential to generalize within the same AAD task. Source code is available at https://github.com/RayZhhh/atpo-aad.
BibTeX
@inproceedings{zhang2026tree,
  author = {Rui Zhang and Ping Guo and Liyong Lin and Zhichao Lu and Qingfu Zhang},
  title = {{Tree Sampling for Reinforcement Learning in Automated Algorithm Design with LLMs}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=Doxqy5ndUy},
}
Figure