开发者

Calculating Time Complexity

Need some Help Regarding how to calculate the t开发者_如何学Pythonime complexity of a function. e.g.

while(x<N)
{
   while(y<N)
     {
       stat 1;
       if(..)
          stat;
     }
}

thanks.


If you are new to Big O notation and have the patience to learn from the best, watch the first 2 video lessons from this MIT algorithms course. This was delivered by Leiserson himself.


the above code snippet is bounded above by O(N^2) and below by a constant...

that is when x and y are both 0, and x = y = N respectively...


Assuming x and y start from 0 and are incremented by 1 in each corresponding loop, it looks like O(N^2).

If you want to compute the exact number of instructions, you should post some concrete code.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜