Text Result Behavior Type-1 ✓ ✓ ✗ Type-2 ✓ ✗ ✗ Type-3 ✗ ✓ ✓ Type-4 ✗ ✓ ✗
Inaddition , wecurateadatasettosystematicallyassesswhetherexistingcodesimilaritymetricseffectivelycapturealgorithmicsimilarity . Algorithmicsimilaritycanbecharacterizedalongthreedimensions :(1) textualappearance ,(2) outputs / results , and (3) proceduralbehavior ( i . e ., thestepstakentoderiveresults ). Thisyieldseightpossiblesimilaritytypes , asdetailedinTable 2.2 . Weexcludetrivialcasesinwhichallthreedimensionsareeitherentirelysimilarorentirelydissimilar , aswellasinfeasiblescenariosinwhichabehaviorallysimilaralgorithmproducesdivergentoutputs . Consequently , ourdatasetconstructionfocusesonthefourremainingnon - trivialtypes ( Type -1 toType -4).
Accordingly , ourdatasetconsistsoffourdistincttypesofalgorithmpairs , designedtodisentanglesimilaritiesintext , results , andbehavior . Below , weprovidebriefexplanationsandrepresentativeexamplesforeachtype . DetailedspecificationsforindividualdatapairsarepresentedinAppx . § A .
• Type 1: High text similarity, different behaviors, similar results. These pairs consist of algorithms that are textually similar but exhibit different behaviors. A typical example is matrix multiplication, where subtle differences in the order of i,j,k lead to divergent internal computations, despite a high degree of code-level overlap. • Type 2: High text similarity, different behaviors and results. These algorithms are similar in text, but a small, critical change (e.g., a parameter or a conditional statement) not only alters their behavior but also yields different final outputs. • Type 3: Low text similarity, similar behaviors and results. This category contains algorithms implemented in diverse ways (e.g., an iterative vs. a recursive implementation of Depth-First Search) but that produce the same behavior and results. • Type 4: Low text similarity, different behaviors, similar results. Algorithms of this type are distinct not only in their code implementation but also in their behavior. However, they produce the same final output. For example, both quicksort and bubblesort yield a sorted array, but their behavior when swapping each subarray is completely different.
Table 2: Average similarity on four types of data calculated by various metrics. Method Type Method Name Type-1 Type-2 Type-3 Type-4 Based on Token ROUGE 0.95 0.96 0.70 0.47 BLEU 0.83 0.94 0.42 0.16 CrystalBLEU 0.97 0.99 0.68 0.51 Based on Structure AST 0.96 1.00 0.76 0.57 Combine Token and Structure CodeBLEU 0.97 0.94 0.91 0.75 Based on Embedding CodeBertScore 0.84 0.97 0.60 0.38 Jina-Code-Embedding 0.99 0.99 0.90 0.84 Qwen3-Embedding-0.6B 0.94 0.93 0.87 0.73 Based on Execution Results – 1.00 0.00 1.00 1.00 Based on Execution Trace Exe-Trace+BLEU 0.86 0.95 0.61 0.54 Exe-Trace+Jina-Code-Emb 1.00 1.00 0.87 0.77 Exe-Trace+Qwen3-Emb-0.6B 0.99 1.00 0.91 0.78 Based on behavior (Ours) BehaveSim 0.56 0.73 1.00 0.46
Weevaluatesixcategoriesofcodesimilaritymetricsonthecurateddataset :❶ Token - levelmetrics , includingROUGE , BLEU , andCrystalBLEU ;❷ Structure - levelmetrics , suchasASTsimilarity ;❸ Hybridmetrics , suchasCodeBLEU , whichcombinestokenandstructuralfeaturesviaaweightedaverage ;❹ Embedding - basedmetrics , includingCodeBERTScore ( Zhou et al., 2023 ) andcosinesimilarityoftwoembeddingmodels , Jina - Code - Embedding ( Günther et al., 2023 ) andQwen 3- Embedding -0.6 B ( Zhang et al., 2025 ) ;❺ Execution - basedmetrics , whichevaluatewhethertwoalgorithmsyieldidenticalresultsonthesamesetofinputs .❻ Execution - trace - basedmethods . Wetracetheinternalvariabledynamicsofalgorithmsusing pysnooper , convertingthetracesintotokensandembeddings , andmeasuretheirsimilarityviaN - Grammethods ( e . g ., BLEU ) andembeddingmodels ( Jina - Code - Embedding , Qwen 3- Embedding -0.6 B ).
WereporttheaveragesimilarityvalueoneachtypeofdatainTable 2 , withresultsonindividualdatapairswithineachtypelistedinAppx . § A . Weobservefromtheresultsthat :
• Both static similarity methods (token-, structure-, and embedding-based methods) and execution-trace-based methods consistently yield high similarity for Type-1 and Type-2 data, which have similar code. However, they fail to measure Type-3 pairs, which have similar behavior but dissimilar code, indicating they cannot distinguish algorithmic behavior. • The Execution-based method correctly identifies Type-3 and Type-4 pairs as having identical results. It cannot distinguish between Type-1 and Type-4 pairs, as both produce identical final outputs despite exhibiting different behaviors, suggesting that simply checking outputs is insufficient for evaluating behavioral similarity. • Although execution-trace-based methods incorporate dynamic execution information, they still exhibit high similarity on Type-1 and Type-2 pairs, as execution traces may contain excessive noise information (e.g., variable state changes) that obscures the underlying problem-solving logic.
Insummary , theresultsdemonstratethatexistingalgorithmicsimilaritymetricsconsistentlyfailtodistinguishbetweenproblem - solvingbehaviors .