Big O when adding together different routines

The sum is indeed the worst of the three for Big-O.

The reason is that your function’s time complexity is

(n) => 3n + nlogn + nlogn

which is

(n) => 3n + 2nlogn

This function is bounded above by 3nlogn, so it is in O(n log n).

You can choose any constant. I just happened to choose 3 because it was a good asymptotic upper bound.

Leave a Comment