logoalt Hacker News

alexfoo • today at 3:57 PM • 1 reply • view on HN

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.


Replies

bee_rider • today at 5:01 PM

O(n + m) is also practically nice to give a general idea of what you mean, without spoiling anything for folks who are still working on it.