For a homework assignment, I’ve been asked to calculate the runtime of various algorithms. The part that is stumping me is the 2^N, because the size of N is so large.
Assuming a 2^N algorithm with a a data size N=1000 takes 5 seconds to execute, calculate the runtime for data sizes {2000, 3000, 10000}
Now, 2^2000/2^1000 = 2^1000 by the property of exponent division. The result is 5.071509e+301 seconds to execute on a data set of 2000 items.
How can I give a number for the next two sizes? 2^2000 and 2^9000 both return infinity in any calculator that I use. The professors hint is that 2^10 is approximate to 10^3, which means that 1024 is approximate to 1000.
The function of time complexity is f(N) = c * 2N.
Since f(1000) = 5, we can solve for c = 5 / 21000.
So f(N) = 5 * 2N – 1000, and f(k * 1000) = 5 * 2(k – 1)*1000.
The blockade seems to be with calculating 2n, so I will guide you on this.
I will take one of your example to demonstrate the method:
21000 = 210 * 100 = (210)100 ≈ (103)100 = 103 * 100 = 10300 = 1e300
That is using your teacher’s hint, another way to calculate the number more accurately is:
21000 = 101000 * log102 = 10301.03 = 100.03 * 10301 = 1.0715e301
(As you can see, the more accurate method will be 10.7 times more than the result from the approximate method)