Say for a given positive integer number n
, you have to find a level k
so that
1 + 2 + 3 + ... + k = S
is below or equals n
but S + k + 1
is above n
.
For example in python:
def find_level(n):
level = 1
while n > 0:
n -= level
level += 1
return level - 1
What is the O magnitude of this function?
find_level
is not a function in the mathematical sense. It is an algorithm. Big Oh only works to describe the growth rate of mathematical functions. So, do you want to describe the growth rate of the function that is computed by thefind_level
algorithm? – Jörg W Mittag Jun 30 '19 at 15:13find-level
algorithm," then yeah, that's what he wants. I'm not a mathematician; I would call it "the Big O of the function," and would feel just fine doing so. – Robert Harvey Jul 01 '19 at 04:04