Exercise 1.2-3

What is the smallest value of n such that an algorithm whose running time is \(100n^2\) runs faster than an algorithm whose running time is \(2n\) on the same machine?

I wrote algorithm_compare.py to calculate that the lowest value of \(n\) that satisfies this condition is 15.

algorithm_compare.py:

def run_time_01(n):
    return 100 * n ** 2


def run_time_02(n):
    return 2 ** n


n = 2
while True:
    if run_time_01(n) < run_time_02(n):
        print("Lowest value of n is " + str(n))
        break
    else:
        n += 1