loading...

Discussion on: Using the big O notation in the wild

Collapse
tiborveresired profile image
tiborveres-ired

lookup[id] is not constant but O(log n)

Collapse
peternycander profile image
Peter Nycander Author

Interesting! I had no idea, thanks! Which data structure is actually being used? I thought it was a hash table...

Collapse
tiborveresired profile image
tiborveres-ired

well. it could be a hash table, but then it's even worse (for big n-s)
as with hash table and big n-s there will be hash collisions, so it needs to do a find in the collision list
best case would be a balanced tree

Thread Thread
peternycander profile image
Peter Nycander Author

Hmm, I wonder at what n you start to get enough collisions for it to matter in practice. I guess it is up to the implementation, and up to the browsers to create a good heuristic.

When I have used SpiderMonkey (and node.js to some extent) solve problems on kattis, I have never run into a problem of object lookup being a bottleneck. Maybe in some special case?

Thread Thread
tiborveresired profile image
tiborveres-ired

in practice it never causes problem
i suspect modern js engines are able to switch implementation based on the object "shape"