Remix.run Logo
▲ stephencanon 2 hours ago

Since m < n by definition, O(n+m) is O(n).

Similarly, there can be no O(m log m) solution, because you have to read every line in general.

▲alexfoo 2 hours ago | parent [-]

Sure, it was shorthand, every algorithm has to be at least O(n) as you have to read in every value at least once. It [Algo (c)] is roughly O(n + (m log m)) but the computation involved generally means that the 'm log m' portion will almost certainly dominate, so the 'O(n)' part is mostly redundant.

A n = 2 billion line input with a valid deterministic solution could have m = 1 billion unique numbers (which means 'm log m' likely dominates), or it could have as few as m = 6 unique numbers in which case the O(n) part will likely dominate. Basic O() notation is too coarse a measure to capture this nuance.