c - Why is the run-time efficiency for this code O(n^2)? -


Sorry, I'm new in bigger analysis. I need some help with it:

I have the following code segment:

  int sum; {If (n & lt; 1000) sum ++ for (int i = 0; i & lt; n; ++ i); Other zodiac + Fu (n); }   

The solution key says that it is O (N ^ 2) analysis, but I do not understand why the loop interates only once, so where comes from n ^ 2 is?

I'm having trouble with another one:

 for  (int i = 0; i & lt; n + 100; ++ i) { For (int j = 0; j and lt; i + n; ++ j) yoga = yoga + j; } For (int k = 0; k & lt; n + n + n; ++ k) {c [k] = c [k] + sum; }   

They come by O (N ^ 3), but I do not even know how it happens. I know that there are 3 loops, but they are not nested, so where does n ^ 3 come from?

1) What could this happen with the implementation of foo () If foo () is o (n) , this method will be o (n ^ 2)

2) internal Loop goes to i * n , where i goes to n , thus it is quadratic in n The third loop in the two loops o (n ^ 3) total is only o (n) so analysis can be ignored.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -