Manuscript Offprint

arXiv:2610.19157

DivAlgo: A systematic evaluation of algorithmic diversity for code generation models

Anubhav Jangra, Smaranda Muresan

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

ABSTRACT

Code generation models are actively being used in professional and educational settings. However, the competence of large language models (LLMs) to generate algorithmically diverse code remains largely unknown. We propose the DivAlgo benchmark, a large-scale dataset constituting algorithmically diverse solutions to programming problems. We also introduce a lightweight similarity metric to enable large-scale evaluation. Our experiments across 24 modern code generation models found that uncontrolled model-generated code is significantly less diverse than human solutions (capturing ∼\sim31% of human diversity), and even the best diverse code generation strategy could achieve only ∼\sim70% of human diversity. Moreover, while it was possible to steer the models to generate solutions based on human strategies, they were unable to reproduce the diversity of the human solutions. These findings indicate the limitations of code generation models in capturing the algorithmic diversity humans exhibit, and that overexposure to model-generated code can narrow programmers' algorithmic vocabulary. 1^{1}

1 INTRODUCTION

Using coding agents and LLMs to perform programming tasks has become ubiquitous not only in software development jobs but also in computer science education and research. The swift adoption of these systems has outpaced scrutiny of their outputs, with users overrelying on model-generated code (Shah et al., 2025; Khati et al., 2025). Much effort to improve LLMs for code generation has focused on executable correctness, using post-training techniques such as reinforcement learning with verifiable rewards (RLVR) that optimize for solution correctness (Lambert et al., 2024; Shao et al., 2024; Wang et al., 2026; Li et al., 2026; Zeng et al., 2025). However, relying solely on functional correctness as the objective in these learning strategies often concentrates generations on repeated implementations, as examined by Le Bronnec et al. (2026) using a plagiarism detection system for code diversity (Prechelt et al., 2002). If a model is unable to generate the breadth of approaches that humans can develop, then its widespread use narrows the ‘algorithmic vocabulary’ encountered and learned from. Moreover, solution homogeneity has direct engineering costs, as diverse implementations are the foundation of N-version fault tolerance (Almeida et al., 2026).

Thus, investigating the algorithmic diversity of model generated solutions has become an important area of research with contribution in code similarity metrics, such as, lexical or embedding overlaps (Ren et al., 2020; Feng et al., 2020), execution behavior similarity (Zhang & Lu, 2026), code diversity benchmarks (Zhang & Lu, 2026; Narula et al., 2026) and approaches to increase the diversity of model generated algorithmic solutions (Lee et al., 2025; Le Bronnec et al., 2026). Building on the prior work, we ask three research questions: RQ1: How diverse are model-generated solutions compared to human-written solutions? RQ2: How much algorithmic overlap exists between solutions from different models for the same task? RQ3: Can models generate solutions that follow the same strategies adopted by humans? These questions encompass three different notions of algorithmic diversity: within a model, across models, and relative to specific human strategies.

We make three main contributions. First, our new benchmark, DivAlgo, allows us to investigate algorithmic overlap at three levels of granularity: data structures, techniques, and program-

1^{1}Implementation of the work is available at https://github.com/anubhav-jangra/divalgo.

Problem (problem id: p02684)

The Kingdom of Takahashi has N towns, numbered 1 through N.

There is one teleporter in each town. The teleporter in Town i (1 ≤ i ≤ N) sends you to Town A.

Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there.

Help the king by writing a program that answers this question.

Constraints

• 2≤N≤2×1052 \leq N \leq 2 \times 10^{5}

• 1≤Ai≤N1 \leq A_{i} \leq N

• 1≤K≤10181 \leq K \leq 10^{18}

Input

Input is given from Standard Input in the following format:

NK

A1A2…ANA_{1}A_{2} \ldots A_{N}

Output

Print the integer representing the town the king will be in if he starts at Town 1 and uses a teleporter exactly K times from there.

Solution A

Start following the teleporters from town 1, remembering the step at which each town was first reached. The first repeated town reveals a cycle and its length; the remaining steps are reduced modulo that length and walked directly.

#include<iostream> #include<algorithm> using namespace std; int main(void) { int a[200001], b[200001], c[200001], i, j, n, ans, rep; long long int k; cin>>n>>k; for(i=1; i<=n; i++) {cin>>a[i]; b[i]=0; c[i]=0;} ans=0; i=1; while(i) { if(b[i]=0){b[i]=1; c[i]=ans;} else{rep=ans-c[i]; break;} i=a[i]; ans++; if(ans==k){cout<<i; return 0;} } k=k-c[i]; k=k+rep; for(j=0; j<k; j++) {i=a[i];} cout<<i; }

Solution B

Precompute a table that keeps track of where every town teleport lands after 1, 2, 4, 8, ..., 2632^{63} teleporters by using a composition of previous rows twice. Write K in binary, and obtain the answer by chaining one jump for each set bit of K.

#include <bits/stdc++.h> #define int long long using namespace std; const int N = 265 + 5; int n, m, t[N][64]; signed main() { cin >> n >> m; for(int i = 1; i <= n; ++i) cin >> t[i][0]; for(int j = 1; j <= 63; ++j) for(int i = 1; i <= n; ++i) t[i][j] = t[t[i][j] - 1][j - 1]; int ans = 1; for(int i = 63; i < -1; --i) { if(n & (111 << i)) ans = t[ans][i]; } cout << ans << '\n'; return 0; }

Ontology labels paradigm technique data structures array time O(N) · space O(N)

Is the pair algorithmically distinct?

PDG

CodeXEmbed

CodeX-SFT

0.77

0.76

0.55

Gemini-3.1-flash-lite

GPT-5.4-mini

distinct

distinct

Figure 1: Illustrative example from our algorithmic diversity benchmark’s test split demonstrating two algorithmically distinct solutions for the same problem. Solution A solves the problem using the simulation paradigm with an array data structure, whereas Solution B adopts a bitmasking paradigm with the binary lifting technique using a 2D matrix data structure. Both solutions have different time and space complexity. The bar graphs show the code similarity of the two solutions, and the labels show the LLM judgments. The ticks in the bar graph indicate the similarity thresholds, below which the solution pair is considered algorithmically diverse in the respective metric space.

ming paradigms. It contains two algorithmically distinct human solutions, along with a pool of human-written solutions for population-level analysis (see Figure 1 for an example). We systematically constructed the benchmark from CodeContest+ (Wang et al., 2025) via cascaded filtration across distinct code similarity metrics and LLM-judge ensembles, yielding a high-quality, large-scale dataset (Section 3). Second, to answer the three research questions at scale, we introduce a distilled and validated lightweight similarity metric and use the Vendi score (Friedman & Dieng, 2022) with this metric to estimate the number of distinct algorithms in a population of solutions (Section 4.2). Third, we thoroughly evaluate the capabilities of a large set of LLMs to generate diverse solutions, answering our three research questions. For RQ1, we show that uncontrolled sampling (for 24 LLMs) yields considerably less diverse solutions than human solutions, with the best model achieving 31% diversity compared to human solutions. Even when using diverse code generation strategies such as temperature variations, verbalized sampling Zhang et al. (2025), and iterative constrained generation Ye et al. (2025), we can only achieve up to 70.5% diversity relative to human solutions with an equal number of samples (Section 5.1). For RQ2, pooling unconditioned solutions across all 24 models is less effective than using a single model with an appropriate prompting strategy, as we found that the models systematically aligned with the more popular human solution approach (Section 5.2). For RQ3, even when the models were steered to generate solutions corresponding to both representative human solutions, they were unable to reproduce the diversity of the overall human solutions (Section 5.3).

References (66)