开发者

tight (Θ) bound

开发者 https://www.devze.com 2022-12-31 17:18 出处:网络
Can someone explain this to me? Such as this: Given a function: for k = 1 to lg(n) for j = 1 to开发者_如何学Go n

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

精彩评论

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