def findMax(f,c):
n=1
while f(n) <= c:
n += 1
return n
This is a higher-order python function that given function f and a maximal count,
c returns the largest n such that f(n) ≤ c. This works but not when n gets too large for e.g f(10**6)
. How can I make this algorithm run O(log n) time so it can facilitate f(10**6)
using the function below?
def f(n):
return math.log(n, 2)