←back to thread

688 points samwho | 1 comments | | HN request time: 0s | source
Show context
ryeats ◴[] No.45019141[source]
O(1) in many cases involves a hashing function which is a non-trivial but constant cost. For smaller values of N it can be outperformed in terms of wall clock time by n^2 worst case algorithms.
replies(2): >>45019209 #>>45025666 #
svara ◴[] No.45019209[source]
I mean, true obviously, but don't say that too loud lest people get the wrong ideas. For most practical purposes n^2 means computer stops working here. Getting people to understand that is hard enough already ;)

Besides, often you're lucky and there's a trivial perfect hash like modulo.

replies(3): >>45019368 #>>45022282 #>>45023070 #
b52_ ◴[] No.45019368[source]
What do you mean? Modulo is not a perfect hash function... What if your hash table had size 11 and you hash two keys of 22 and 33?

I also don't understand your first point. We can run n^2 algorithms on massive inputs given its just a polynomial. Are you thinking of 2^n perhaps?

replies(3): >>45020015 #>>45021292 #>>45057972 #
1. Panzer04 ◴[] No.45021292[source]
n^2 is probably the worst offender of these algorithms - it's fast enough to get into production and slow enough to blow up once you start using it.

Rockstar infamously wasted five minutes loading GTAV because they had an n^2 algorithm in the startup sequence.