我正在开发一个应用程序,它有一个包含数字行的大数组,
transNum[20000][200]//this is the 2d array containing the numbers and always keep track of the line numbers
我正在使用嵌套循环来查找最常见的项目。这是
for(int i=0/*,lineitems=0*/;i<lineCounter;i++)
{
for(int j=0,shows=1;j<lineitem1[i];j++)
{
for(int t=i+1;t<lineCounter;t++)
{
for(int s=0;s<lineitem1[t];s++)
{
if(transNum[i][j]==transNum[t][s])
shows++;
}
}
if(shows/lineCounter>=0.2)
{
freItem[i][lineitem2[i]]=transNum[i][j];
lineitem2[i]++;
}
}
}
当我使用像 test[200][200] 这样的小输入数组进行测试时,这个循环工作正常并且计算时间是可以接受的,但是当我尝试处理包含 12000 行的数组时,计算时间太长了,所以我我在想是否有其他方法来计算频繁项而不是使用这个循环。我只是在 10688 行上进行了测试,得到所有频繁项的时间是 825805 毫秒,这太昂贵了。