The automated recognition of algorithm implementations can support many software maintenance and re-engineering activities by providing knowledge about the concerns present in the code base. Moreover, recognizing inefficient algorithms like Bubble Sort and suggesting superior alternatives from a library can help in assessing and improving the quality of a system. Approaches from related work suffer from usability as well as scalability issues and their accuracy is not evaluated. In this paper, we investigate how well our approach based on the abstract syntax tree of a program performs for automatic algorithm recognition. To this end, we have implemented a prototype consisting of: A domain-specific language designed to capture the key features of an algorithm and used to express a search pattern on the abstract syntax tree, a matching algorithm to find these features, and an initial catalog of "ready to use" patterns. To create our search patterns we performed a web search using the algorithm name and described key features of the found reference implementations with our domain-specific language. We evaluate our prototype on a subset of the BigCloneEval benchmark containing algorithms like Fibonacci, Bubble Sort, and Binary Search. We achieve an average F1-score of 0.74 outperforming the large language model Codellama which attains 0.35. Additionally, we use multiple code clone detection tools as a baseline for comparison, achieving a recall of 0.62 while the best-performing tool reaches 0.20.
翻译:算法的自动识别可以通过提供代码库中关注点的知识来支持许多软件维护和重构活动。此外,识别低效算法(如冒泡排序)并从库中推荐更优替代方案,有助于评估和提升系统质量。现有相关方法存在可用性和可扩展性问题,且其准确性未得到评估。本文研究了基于程序抽象语法树的方法在自动算法识别中的表现。为此,我们实现了一个原型系统,包含:一种针对算法关键特征设计的领域特定语言,用于在抽象语法树上表达搜索模式;一种匹配算法以定位这些特征;以及一个初始的“即用型”模式库。通过搜索算法名称,我们利用该领域特定语言描述了参考实现的关键特征来构建搜索模式。我们在BigCloneEval基准的子集(包含斐波那契数列、冒泡排序和二分查找等算法)上评估了原型系统。我们取得了0.74的平均F1分数,优于大语言模型Codellama(0.35)。此外,我们使用多个代码克隆检测工具作为基线进行比较,在召回率达到0.62的同时,表现最佳的工具仅为0.20。