Dmitry  Yaremenko
Dmitry Yaremenko

Reputation: 2580

Is it formally correct to say that 2*n = O(2*n)?

Yes, it is obvious fact that 2*n = O(n), and O(n) is shorter notation than O(2*n), but if we write O(2*n) - would it be incorrect?

I don't see any conflicts in the definition... There exists M: |2*n| <= M * |2*n| for all x >= x0

Or it would be just not accepted in math/programming community to write like that?

Upvotes: 0

Views: 40

Answers (1)

Has QUIT--Anony-Mousse
Has QUIT--Anony-Mousse

Reputation: 77475

By definition,

O(n) = O(2n)

because n in O(2n) and 2n in O(n).

thus both is correct. But it is convention to use the shortest notation of a class, and if you are asked about the complexity class in a test, they may be referring to the shortest name.

Upvotes: 2

Related Questions