Shailesh Tainwala
Shailesh Tainwala

Reputation: 6507

Estimating running time for large inputs

An algorithm having worst-case running time of O(N^2) took 30secs to run for input size N=20. How long will the same algorithm take for input size N=400 ?

Upvotes: 0

Views: 87

Answers (1)

djna
djna

Reputation: 55937

O(n^2) implies proportionality to the square of n (see this guide). So

 T = K (n^2)
30 = K (20^2)
 K = 30 / 400

Hence time for 400 items

   = (30 / 400)( 400 ^ 2 )

So that 12000 seconds.

Now, that's not necessarily true unless you know that the original 20 item test was a worst case scenario, if it isn't then we have a bad estimate of K. Even if if we have a good estimate of K so we we know the worst case scenarion for 400 items, we don't know that these 400 items will take that long.

Upvotes: 3

Related Questions