I have a question, here is the loop:
for (i=0; i < n; ++i) for (j = 3; j < n; ++j) { ... }
I kind of understand how to calculate the big-oh, but I'm not quite sure how to do this. The outer loop executes n times, and the inner loop executes i times for each value of i. The difficulty should be N ^ 2 (I think). Can you guys talk about how this is calculated? I understand some of them, but not all.
This (n*(n-3)) = nΒ²-3n, but for the very large nit is close to nΒ². Therefore, to designate Big-Oh, I would write O(nΒ²), because you -3ncan ignore it.
(n*(n-3)) = nΒ²-3n
n
nΒ²
O(nΒ²)
-3n
: n , (n-3) .
(n-3)
O (n ^ 2). , "...". O (1), , O (n ^ 2). , n-3 . 1 , O (1). , n * (n-3) . , O (1), O (n * (n-3)) = O (n ^ 2).
, : , . , , , O (mn 2), m - , , ( n, ).
, , , n 2 - 3n O (n 2). , , n 2 - 3n & le; cn 2 c - . = 2 n 2 - 3n & le; n 2 + n 2 , , .
, O (n ^ 2), . - :
for (int x=0; x < width; x++) { for (int y=0; y < height; y++) { // Do something on a specific pixel in the image in constant time } }
O (n) O (n ^ 2), n , . , "n ^ 2" . , , "n" , .
, , n-3 - j, 3. n , . , , , . , . !
Formally, you can use Sigma Notation to get the exact number of iterations and, therefore, determine the growth order.
Source: https://habr.com/ru/post/1750917/More articles:Calling a function from a template derived class - c ++Mac suitable for python programming? - pythonShould I always use the GL_ARGB format for all textures in OpenGL? - c ++How do you return a pointer to a base class with a virtual function? - c ++What is a strong dosage method? - securitycyclic properties in struct-C - cA video chat / conference SDK for .NET that works? - .netreliable server-side dynamic form engine for ASP.NET - asp.netRemove "headheading" from the homepage - Joomla! - joomlaWhat is the difference between a keystore and a private key in the context of signing an application? - software-distributionAll Articles