开发者

tight (Θ) bound

Can someone explain this to me? Such as this:

Given a function:

for k = 1 to lg(n)
  for j = 1 to开发者_如何学Go n
    x=x+1

How would I analyze the tight (Θ) bound?


Your function is Θ(log n · n): The outer loop is repeated log n times and the inner loop n times (for each iteration of the outer for), so x=x+1 is executed log n · n times in total. And since the number of repetitions is fixed, the lower and upper bound is the same.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜