让 A 是一个数组[1..n],其中有零和一。func ()是复杂度为 theta(m) 的函数。对于给定的伪代码,复杂度是多少?
counter=0;
for(i=0;i<n;i++)
{
if(a[i]==1)
counter++;
else
func();
}
根据我的说法,函数 func() 最多被调用 n 次的最坏情况是当数组完全用 zeros 填充时。因此,由于 func() 的 theta 命名为 theta(m)
上述代码的复杂性是 :theta(mn) ....??? 如果没有,请帮助我进行适当的验证。