Manuscript Offprint

arXiv:2611.09791

Assessing the Impact of Retrieval-Augmented Generation on Algorithmic Problem-Solving

Gabriel Souza Baggio, Gabriel Machado Lunardi, Guilherme Medeiros Machado, Subhankar Maity, Faiza Belbachir, José Palazzo Moreira de Oliveira

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

Abstract

Competitive programming problems pose distinctive challenges for Large Language Models, as they demand not only proficient code generation but also advanced algorithmic reasoning. This study presents a Retrieval-Augmented Generation approach specifically designed to enhance the capacity of Large Language Models to address such problems. Our approach integrates an embedding-based retrieval mechanism and a similarity search algorithm to identify analogous problems within a knowledge database, employing a dynamically adjusted threshold to mitigate retrieval noise. We conducted an evaluation using the CodeContests dataset, focusing on the test split problems that exhibit similarity to instances from the training split. The experimental framework considered three conditions: (i) problems provided solely with their original descriptions, (ii) problems supplemented with randomly selected examples from the training split, and (iii) problems augmented with similar examples retrieved through the proposed method. In addition, we incorporated a Min-K membership inference analysis to examine whether the generated code solutions were influenced by potential memorization of training data within the evaluated Large Language Models. This complementary perspective enables a deeper understanding of model behavior by distinguishing genuine generalization through retrieval from implicit recall of pretraining samples. Performance was assessed using both pass rates and the CodeForces Elo rating of the problems. The results provide empirical evi-dence that similarity-based retrieval substantially enhances Large Language Models performance in competitive programming scenarios, offering an scalable framework for improving code generation in algorithmic problem-solving contexts.

Keywords: Retrieval-Augmented Generation, Large Language Models, Code Generation, Programming Problems, Information Retrieval

1. Introduction

Large Language Models (LLMs) have demonstrated proficiency in solving generic problems across various professional domains [1, 2, 3]. Although some evaluation benchmarks indicate high performance — such as on HumanEval, where GPT-4o [4] and Claude-3.5-Sonnet [5] achieved precision scores of 90% and 92%, respectively [6] —, other benchmarks show that LLMs exhibit limitations on competitive programming tasks [7, 8, 9, 10]. For instance, in the analysis by Zheng et al. [8], Claude-3.5-Sonnet achieved a 0% precision rate on medium and hard problems and only 14.1% on easy ones. In the same benchmark, even the best-performing LLMs, such as Gemini-2.5-Pro [11] and DeepSeek-R1 [12], could not solve a single hard problem.

These errors typically arise due to a lack of specific contextual knowledge and a limited understanding of underlying data structures, leading to hallucinations — outputs that are syntactically invalid or logically inconsistent [13]. Under a deeper epistemological analysis, it becomes evident that Large Language Models (LLMs) operate on opinion-based trajectories—that is, on the formulation of statements not necessarily grounded in verifiable evidence, but rather derived from inferences or interpretations constructed within a limited context of knowledge. Hallucination, in this sense, may be understood as the generation of a perception or belief that, while internally coherent, does not correspond to empirical reality. In LLMs, this phenomenon arises because the model “believes” it is producing a consistent and contextually appropriate response, even though such a response lacks factual support.To mitigate this, Retrieval-Augmented Generation (RAG) [14, 15] has been proposed as a mechanism to ground the model’s outputs in relevant external knowledge by, with an Information Retrieval (IR) algorithm, retrieving contextually similar information from a structured corpus [14, 15]. This work investigates how RAG can be used to enhance the problem-solving capabilities of LLMs.

The proposition for applying RAG in this context is based on two key observations. First, studies indicate that problems within competitive programming repositories often share underlying algorithmic patterns and solution structures [16, 17]. Second, the practice of providing relevant examples in the prompt (few-shot prompting) is an established technique for improving LLM performance on complex tasks [18, 19]. Based on this, the hypothesis is that a RAG system that retrieves previously solved problems with analogous characteristics to a target problem can provide the model with relevant context and reduce hallucination.

To achieve this, we developed an Information Retrieval (IR) pipeline that employs embedding similarity with a dynamic threshold [20]. We evaluated this system on the CodeContests dataset [21], which is divided into a training set of 13,328 problems and a test set of 165 problems. In addition to the problem title and statement, each sample includes metadatdynamig programming, bitwise operations). The training split served as the knowledge base from which we retrieved similar examples to augment the LLM prompts for solving the problems in the test set. The correctness of the generated solutions was then evaluated using the CodeForces [22] judge system, allowing us to measure the impact of the retrieved context on the model's performance.

The evaluation involves three distinct prompting strategies: (i) a zero-shot baseline using only the original description, (ii) a random retrieval baseline retrieving unrelated problems from the knowledge base, and (iii) the proposed similarity-based RAG approach retrieving contextually aligned examples. Our analyses demonstrate that the similarity-based retrieval consistently outperforms both baselines, validating the hypothesis that retrieving analogous problems improves LLM reasoning on complex programming tasks. Furthermore, the Min-K membership inference results reveal that many generated code lines correspond to known training patterns, underscoring the importance of disentangling memorization effects from genuine reasoning improvements. Together, these findings provide a dual epistemic safeguard: RAG anchors outputs in external knowledge, while membership inference verifies their originality and data provenance. See Figure 1 for a graphical overview of the system architecture and execution pipeline.

The main contributions of this paper are summarized as follows:

  1. We design a RAG framework tailored to competitive programming tasks, integrating an embedding-based similarity search with an adaptive thresholding mechanism to retrieve contextually relevant problems while minimizing retrieval noise.

Figure

Figure 1: System Architecture and Execution Pipeline

  1. We construct a comprehensive experimental setup using the CodeContests dataset, evaluating six prominent LLMs across three prompting strategies, zero-shot, random retrieval, and RAG-based enhancement, to systematically quantify the effect of similarity-driven retrieval on code generation performance.

  2. We introduce a complementary Min-K Membership Inference analysis to assess model exposure and memorization biases, providing a novel perspective on the interplay between retrieval-based augmentation and pretraining data recall.

  3. We present an integrated evaluation pipeline combining RAG effectiveness and membership inference insights, offering a dual perspective on both performance improvement and epistemic grounding in competitive programming contexts.

  4. Finally, we discuss the implications of these findings for the design of future reasoning-oriented LLMs and outline directions for extending this work to upcoming state-of-the-art models such as Gemini 3 and GPT-5.

References (36)