T (n) in big O

When calculating T (n), the complexity of 1n is usually represented as just n?

For example, in the following Python code:

def Average(aList):
    x = len(aList)
    total = 0
    for item in aList:
        total = total + item
    mean = total / n
    return mean

      

Now by doing T (n) the function starts with 2 assignments, 1 loop which is 1n assignments and 1 assignment after the loop giving

T (n) = 1n + 3

will discard 1, giving n + 3, giving O (n)?

+3


source to share


3 answers


Order naming is an increase in algorithmic complexity rather than a specific number of operations.

So O (3n) grows at the same rate as O (n), so multiplicative and additive constants are eliminated. Think about the odds, if you double the "n" value, then in both cases the timings are doubled.



Slower growing components are ignored. In the limit, O (n + 3) grows at about the same rate for O (n). In this respect, it grows at about the same rate as O (10n + log (n) + 7).

The key idea in notation for order is what happens as "n" grows. This is not about counting all specific transactions.

+2


source


"Big O" (or Landau) denotes all constants, since they do not affect the growth of the function / complexity. Hence 1n + 3 will be O (n), not O (1n + 3) or O (n + 3).



This is because of the linearity of this function. Something like 2n would also be O (n), because a factor of 2 just factors the output of the function, but doesn't affect the "intensity / speed" at which your function grows.

+1


source


This is "Big O" notation . The addition of constants drops out and is also multiplied by a constant.

The big o

0


source







All Articles