Search code examples
big-ocomplexity-theorytime-complexityspace-complexity

If a>=b then O(a+b)=O(a)?


I'm trying to understand better the idea of O(n), so I'm wonder about this:

If we know that a>=b so O(a+b)=O(a)?
I know that O(a)+O(a)=O(2a)=O(a), but I'm wondering if it's true for something that it's smaller then a, I mean - if O(a+b)=O(a).

I think that it's true because a+b=O(2a), but I'd like to know if I'm wrong...

(P.S. it will be true if a and b are constants?)

Thank you!


Solution

  • You're totally correct in simplifying O(a+b) = O(a) as per this case.

    It's so because

     a>=b (given)
     O(a+b) <= O(a+a) = O(2a) = O(a) // as clearly mentioned by you.
    

    Example :-

    Let's assume

    a = n; b = log(n).
    

    Then,you can see

    O(a+b) = O(n+log(n)) = O(n) = O(a).