4

I am not sure if this is a valid question.

Let's assume there is an O(n^3) algorithm which sorts 100 numbers per day with a computing power x.

How many numbers will it be able to sort if the computing power is doubled ie., 2x .

I understand that i din't define 'computing power'. Please correct the question if it is ambiguous or wrong.

1
  • 2
    Cubed root of 2*(100^3), floored? 125 (non-floored is 125.99, so 126 may be a better answer). Commented Jun 29, 2011 at 6:27

2 Answers 2

7

Big O notation does not give you eact time (real computer time). It is a method that try to understand effiency of algorithms independent of cpu or other specific computer features.

In mathamatics perpective, you can say that O(n^2) is more efficient than O(n^3). But in an engineer view point, for some values of n , O(n^3) can be better than O(n^2). This methods just says that for suffieciently large n, O(n^2) will be more efficient than O(n^3).

There is a good introduction to algorithm analsysis in you tube. First chapter is good for explaning those things: MIT 6.046J / 18.410J Introduction to Algorithms

The Big O notation can only say that for the same machine, for sufficiently large n, O(n^2) is better than O(n^3). But for the same algorithm i think you can not make direct propotion betweeen computer power and output. If we double the computer power, the output doubled? Maybe yes but may be not. I think we can not say such a thing by just looking algorithm Big O.

enter image description here

Sign up to request clarification or add additional context in comments.

5 Comments

"for some values of n , O(n^3) can be better than O(n^2)". More precisely: for some values of n, some algorithms in O(n^3) can be better than some algorithms in O(n^2).
Completly right - best example: Linear Programming. An optimpization method often used int mathematics and business. The thing is: The used algorithm is O(2^n) (worst case), but for almost all practical problems it performs bettern than a theoretical fast method (e.g. ellipsoid) with complexity O(n^4). Furthermore today the execution time is NOT limited by the computing power of the CPU, but by the IO bandwidth of the CPU. It does help you anything if you make your computations twice as fast, if you still dont get enough data in it.
He is not comparing two different algorithms with the same complexity but the same algorithm and implementation with two different loads. As he is working on a days scale, probably, the algorithm is already very near to its asymptotic behaviour (in CPU usage) and the big O expression can be used to get a good estimation of computation time requirements for other datasets.
@salva Yea you are right Salva.He talks about for the same algorihtm, if we double the computer power, will the sorted output doubled?(Direct propotion)? Hard to say just using Big O...
@Vapuru: I have replied you in my answer to the OP (it was too big to be posted here!)
5

N = 100 may be not big enough to be able to assume that the algorithm has already reached its asymptotic behaviour in terms of CPU usage, and so using the big O expression to extrapolate CPU usage for bigger datasets may generate erroneous results.

Though, you can try to determine if you are already on the asymptotic zone, measuring the CPU usage for datasets of other sizes (for instance, 50, 80, 120, etc.) and seeing how they fit on a t = C*N^3 curve, being C a constant to be determined.

If the fit is "good enough" after some given N, you can use the same curve to make predictions of CPU usage for bigger datasets.

In any case, you should consider those predictions as the lower limit of the CPU time required to compute some dataset because in practice, other computing resources as memory, caches or IO can become the bottleneck over the CPU usage.

Update: in response to Vapuru post and its comments:

For a typical O(N^3) algorithm the number of operations performed by a specific implementation is t = a + b * N + c * N^2 + d * N^3 (there may be other components, as log N, but as you will see, it doesn't actually matter). So, for two given data sets of size N1 and N2 you can calculate t1 and t2 respectively.

For the given OP problem, t2 / t1 = 2, so (a + b * N2 + c * N2^2 + d * N2^3) / (a + b * N1 + c * N1^2 + d * N1^3) = 2 and for N1 and N2 big enough that expression can be approximated as (d * N2^3)/(d * N1^3) = 2 that can be further simplified as (N2/N1)^3 = 2 and so N2 = N1 * 2^(1/3).

That means that for big datasets, doubling the processing time (or doubling the processing speed and keeping time unchanged), allows to increase the size of the dataset approximately by a factor of 2^(1/3), that's 1.26 or a 26%.

In practice, other factors besides CPU speed may affect performance, so actually it should be read as N2/N1 < 1.26.

2 Comments

So it means if you double computer power, you can sort 100*1.26 = 126 inputs...More clearly if you double the computer power(what ever it means) the sorted items are less than N2 < 126 ?
@Vapuru: Well, as I have written before, 100 may not be big enough for d*N^3 to be an acceptable approximation of the algorithm cost. Though, that hypotheses can be experimentally tested and if it holds, then N2 < 126.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.