Answer the question
In order to leave comments, you need to log in
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:
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;
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question