D
D
Dmitry Potylitsyn2018-04-23 22:10:17
Algorithms
Dmitry Potylitsyn, 2018-04-23 22:10:17

Why does the complexity of the algorithm not match?

Hello!
I deal with the algorithms according to Cormen, along the way I try to remember the checkmate. basis from the appendices to the book. And I found this example:
5ade2e4b25651630403112.png
From the output, according to the formula, it is clear why the complexity is n^2 . But ... after all, in practice, the algorithm is coded something like this:

let result = 0;
for(let i = 1; i <= 3; i++){
   result += i;
}
return result;

And here already the complexity is - n . Why? What am I missing?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynn "Coffee Man", 2018-04-23
@Naararouter

This is not the complexity, but the asymptotics. Those. The sum of natural numbers grows as n grows as n^2
https://ru.wikipedia.org/wiki/%C2%ABO%C2%BB_%D0%B1
... in the context of the complexity of algorithms, but in general this is a common mathematical notation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question