我正在使用 Rabin–Karp 算法来检查任何两个源代码文件的抄袭所以首先我简单地在 c# 中实现它的算法,但它的平均和最佳情况运行时间是空间 O(p) 中的 O(n+m) ,但其最坏情况时间为 O(nm)。
public void plagiarism(string [] file1, string [] file2)
{
int percent = 0;
for (int i = 0; i <(file1.Length - file2.Length +1); i++)
{
for (int j = 0; j < file1.Length; j++)
{
if (file1[i + j - 1] != file2[j])
{
}
percent++;
Console.WriteLine(percent);
}
Console.WriteLine("not copied");
}
}
那么如何通过使用滚动哈希函数来提高效率,因为这比这更好..