Introduction
While Large Language Models (LLMs) have become remarkably proficient at generating functionally correct code, they often suffer from a "creative rut." Current evaluation benchmarks primarily focus on functional correctness—measured by metrics like Pass@k—which ignores whether a model is capable of exploring multiple distinct approaches to a single problem. This research introduces a framework to measure algorithmic diversity, revealing that even the most advanced models tend to generate redundant solutions compared to the varied logic employed by humans.
The Need for Algorithmic Diversity
In software engineering and education, correctness is only half the story. Algorithmic diversity is essential for building robust systems that avoid single points of failure and for providing students with multiple ways to understand a problem (e.g., an iterative vs. a recursive solution). Existing metrics like CodeBLEU or CodeBERTScore are insufficient for this task as they focus on syntax or surface-level semantics rather than the underlying algorithmic logic.
Measuring How Models "Think"
The researchers propose a systematic framework to quantify diversity through three key components:
- AlgoSim: An instruction-tuned LLM (Llama-3.1-8B) acts as a judge, analyzing pairs of code snippets to determine if they share the same underlying logic, regardless of variable names or minor implementation details.
- Clustering: Solutions are grouped into "algorithmic clusters" based on these similarity predictions.
- New Metrics:
- DA@K (Distinct Algorithms at K): The expected number of unique algorithms found when sampling $K$ solutions.
- EA (Effective Number of Algorithms): An entropy-based measure of how evenly a model distributes its "ideas" across different approaches.
- ADC (Algorithmic Diversity Curve): A visualization of how the number of unique algorithms grows as more solutions are generated.
Experimental Insights
The study utilized the APPS dataset, focusing on problems from AtCoder and CodeForces across three difficulty levels: Introductory, Interview, and Competition.
The "Correctness vs. Diversity" Trade-off
High-performing proprietary models like GPT-4o are excellent at finding the correct solution but are surprisingly redundant. They tend to converge on a single "best" path. In contrast, open-source models like DeepSeek often explore more varied (though sometimes less accurate) algorithmic territory.
Humans vs. AI
As shown in the Algorithmic Diversity Curves, humans remain significantly more creative than any model tested. For instance, in the AtCoder-introductory set, humans averaged approximately 3 distinct algorithms per problem at $K=25$, while the best models hovered around 2. This gap persists across all difficulty levels.
Enhancing Diversity
Two primary methods were found to mitigate redundancy:
- Extreme Sampling Temperatures: Increasing the sampling temperature (up to 1.4) boosts diversity, though it eventually leads to a sharp decline in functional correctness as the model begins to generate invalid code.
- Model Merging: Combining solutions from different model families (e.g., Qwen, DeepSeek, and GPT) is more effective than simply generating more samples from a single model. On CodeForces, merging three model families resulted in a diversity boost of up to +0.244 in normalized diversity metrics.
Limitations and Future Directions
The study identifies several challenges, including the high computational cost of using an LLM as a judge (AlgoSim) and the inherent subjectivity of what constitutes a "different" algorithm. Furthermore, for high-difficulty "Competition" level problems, models often fail to generate enough correct solutions to allow for a meaningful diversity measurement. Future research may explore diversity within the "failure space"—analyzing how models explore different incorrect paths for complex problems.
Summary updated