Table of Contents
Fetching ...

Towards a Measure of Algorithm Similarity

Shairoz Sohail, Taher Ali

TL;DR

Algorithm comparison is fundamentally hard due to uncomputability in general, but constraining the domain enables meaningful similarity metrics. The authors propose EMOC, an evaluation-memory-operations-complexity embedding that maps algorithm implementations into a feature vector comprised of $E$, $M$, $O$, and $C$ components, yielding a vector of length $1 + N + K + M$ and enabling downstream tasks. They validate EMOC on the PACD dataset, showing utility for clustering, clone detection, and measuring novelty in LLM-generated programs, and demonstrate conditions under which diversity increases (e.g., larger models, more novel prompts) using formal experiments. The work provides code, data, and a path toward reproducible algorithm-similarity research with practical impact on clone detection and program synthesis.

Abstract

Given two algorithms for the same problem, can we determine whether they are meaningfully different? In full generality, the question is uncomputable, and empirically it is muddied by competing notions of similarity. Yet, in many applications (such as clone detection or program synthesis) a pragmatic and consistent similarity metric is necessary. We review existing equivalence and similarity notions and introduce EMOC: An Evaluation-Memory-Operations-Complexity framework that embeds algorithm implementations into a feature space suitable for downstream tasks. We compile PACD, a curated dataset of verified Python implementations across three problems, and show that EMOC features support clustering and classification of algorithm types, detection of near-duplicates, and quantification of diversity in LLM-generated programs. Code, data, and utilities for computing EMOC embeddings are released to facilitate reproducibility and future work on algorithm similarity.

Towards a Measure of Algorithm Similarity

TL;DR

Algorithm comparison is fundamentally hard due to uncomputability in general, but constraining the domain enables meaningful similarity metrics. The authors propose EMOC, an evaluation-memory-operations-complexity embedding that maps algorithm implementations into a feature vector comprised of , , , and components, yielding a vector of length and enabling downstream tasks. They validate EMOC on the PACD dataset, showing utility for clustering, clone detection, and measuring novelty in LLM-generated programs, and demonstrate conditions under which diversity increases (e.g., larger models, more novel prompts) using formal experiments. The work provides code, data, and a path toward reproducible algorithm-similarity research with practical impact on clone detection and program synthesis.

Abstract

Given two algorithms for the same problem, can we determine whether they are meaningfully different? In full generality, the question is uncomputable, and empirically it is muddied by competing notions of similarity. Yet, in many applications (such as clone detection or program synthesis) a pragmatic and consistent similarity metric is necessary. We review existing equivalence and similarity notions and introduce EMOC: An Evaluation-Memory-Operations-Complexity framework that embeds algorithm implementations into a feature space suitable for downstream tasks. We compile PACD, a curated dataset of verified Python implementations across three problems, and show that EMOC features support clustering and classification of algorithm types, detection of near-duplicates, and quantification of diversity in LLM-generated programs. Code, data, and utilities for computing EMOC embeddings are released to facilitate reproducibility and future work on algorithm similarity.

Paper Structure

This paper contains 28 sections, 2 equations, 6 figures, 1 table.

Figures (6)

  • Figure 1: Levels of abstraction in algorithm implementation
  • Figure 2: Utilizing EMOC Embeddings to Classify Sorting Algorithm Implementations from PACD (Test acc = 79.1%)
  • Figure 3: Utilizing EMOC embeddings to measure diversity of LLM generated sorting algorithms
  • Figure 4: Directly encouraging novelty by modifying prompt
  • Figure 5: Diversity of generated algorithms by LLM size
  • ...and 1 more figures