Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Complexity for 2n^2 + n

If a problem of complexity 2n^2 + n can be solved in 24 units of time for n = 2, how long does it take for n = 4?

I was told that the answer is 48. But I believe it should be 24^2 because the complexity of the algorithm is O(n^2).

Appreciate if anyone could enlighten me.

like image 825
Paul Brown Avatar asked Mar 06 '26 21:03

Paul Brown


1 Answers

The complexity O(f(n)) comprises all computations that take c*f(n)+d amount of time, where c and d are constants. If d=0 then:

In the case for n=2 and complexity O(2n^2+2) being 24:

24 = (2*2^2 + 2)*c, hence c = 24/10 = 2.4

Now we compute for n=4:

(2*4^2+4)*2.4= 36*2.4 = 86.4 units of time

If d is not 0 the c = (24-d)/10 and for n=4 it would take

36*(24-d)/10 +d = 86.4 +0.9d

So, it is impossible for the answer to be 48, which additionally implies a linear algorithm

like image 106
Candide Avatar answered Mar 09 '26 13:03

Candide