Shinwoo Park , Joonghyuk Hahn , Elizabeth Orwig , Sang-Ki Ko , Yo-Sub Han
{"title":"Advanced code time complexity prediction approach using contrastive learning","authors":"Shinwoo Park , Joonghyuk Hahn , Elizabeth Orwig , Sang-Ki Ko , Yo-Sub Han","doi":"10.1016/j.engappai.2025.110631","DOIUrl":null,"url":null,"abstract":"<div><div>It is a crucial task to predict the algorithmic time complexity for estimating the efficiency of a software code. Since the problem is known to be undecidable in theory, there is no 100% accurate tools to solve the problem. Even humans often make mistakes when analyzing the time complexity of code, and this process requires considerable effort and time to thoroughly examine the code. Therefore, we aim to develop an automated method for analyzing code time complexity. We observe that solution codes submitted for coding problems in competitive programming contests tend to have similar time complexities due to constraints such as time limits and functional requirements of the problems. Based on this observation, we propose a contrastive learning-based training strategy that aligns solution codes for the same competitive programming problem. Our training strategy clusters codes with similar time complexities by using both natural language problem descriptions and a single reference code per problem as anchors. This design enables the model to capture core algorithmic features such as loops and recursion more accurately. Experiments in three scenarios – in-dataset, cross-dataset, and cross-language – demonstrate substantial gains on pre-trained code models, consistently surpassing existing methods in both accuracy and generalizability. Our proposed training strategy yields an average 12.54% improvement over cross-entropy-based training, and an 8.01% improvement over data augmentation-based contrastive learning.</div></div>","PeriodicalId":50523,"journal":{"name":"Engineering Applications of Artificial Intelligence","volume":"151 ","pages":"Article 110631"},"PeriodicalIF":8.0000,"publicationDate":"2025-07-01","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"0","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"Engineering Applications of Artificial Intelligence","FirstCategoryId":"94","ListUrlMain":"https://www.sciencedirect.com/science/article/pii/S0952197625006311","RegionNum":2,"RegionCategory":"计算机科学","ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"2025/3/28 0:00:00","PubModel":"Epub","JCR":"Q1","JCRName":"AUTOMATION & CONTROL SYSTEMS","Score":null,"Total":0}
引用次数: 0
Abstract
It is a crucial task to predict the algorithmic time complexity for estimating the efficiency of a software code. Since the problem is known to be undecidable in theory, there is no 100% accurate tools to solve the problem. Even humans often make mistakes when analyzing the time complexity of code, and this process requires considerable effort and time to thoroughly examine the code. Therefore, we aim to develop an automated method for analyzing code time complexity. We observe that solution codes submitted for coding problems in competitive programming contests tend to have similar time complexities due to constraints such as time limits and functional requirements of the problems. Based on this observation, we propose a contrastive learning-based training strategy that aligns solution codes for the same competitive programming problem. Our training strategy clusters codes with similar time complexities by using both natural language problem descriptions and a single reference code per problem as anchors. This design enables the model to capture core algorithmic features such as loops and recursion more accurately. Experiments in three scenarios – in-dataset, cross-dataset, and cross-language – demonstrate substantial gains on pre-trained code models, consistently surpassing existing methods in both accuracy and generalizability. Our proposed training strategy yields an average 12.54% improvement over cross-entropy-based training, and an 8.01% improvement over data augmentation-based contrastive learning.
期刊介绍:
Artificial Intelligence (AI) is pivotal in driving the fourth industrial revolution, witnessing remarkable advancements across various machine learning methodologies. AI techniques have become indispensable tools for practicing engineers, enabling them to tackle previously insurmountable challenges. Engineering Applications of Artificial Intelligence serves as a global platform for the swift dissemination of research elucidating the practical application of AI methods across all engineering disciplines. Submitted papers are expected to present novel aspects of AI utilized in real-world engineering applications, validated using publicly available datasets to ensure the replicability of research outcomes. Join us in exploring the transformative potential of AI in engineering.