3 ms·
Right, for all practical purposes if the reader assumes the words are from the English language, you can assume that comparisons will be constant (both from the
by krackers 4y ago
Right, for all practical purposes if the reader assumes the words are from the English language, you can assume that comparisons will be constant (both from the pedantic CS perspective since words are bounded in length, and also from a practical perspective since the bound is small, and with SIMD can be done fast enough for most words). See also responses from https://news.ycombinator.com/item?id=35550842 https://news.ycombinator.com/item?id=35550842 and https://news.ycombinator.com/item?id=35551114 https://news.ycombinator.com/item?id=35551114 which say the same better than I could.
It feels really disingenuous when interview questions start off posing a seemingly innocent problem where the intuitive and practical answer is usually the one that'd you go for if you wanted to implement this in the real-world, then as soon as you answer the interviewer turns around and throws a hidden assumption at you. You could argue that the point of the interview is to have the candidate suss out these things, but it's usually a one-way discussion where you're not allowed to even question if the assumptions make sense in the real-world (which is what you ultimately care about).
And if the words are truly big enough to be an issue then you better start being rigorous and benchmarking different approaches rather than just handwaving big-o.
Ultimately when you get down to it, the whole point seems to see if the interviewee can be led down the pre-determined golden path, even if the path is only fools gold.