What's Up with O(1)?

前端 未结 13 2109
既然无缘
既然无缘 2020-12-22 17:40

I have been noticing some very strange usage of O(1) in discussion of algorithms involving hashing and types of search, often in the context of using a dictionary type provi

13条回答
  •  有刺的猬
    2020-12-22 18:10

    I can see what you're saying, but I think there are a couple of basic assumptions underlying the claim that look-ups in a Hash table have a complexity of O(1).

    • The hash function is reasonably designed to avoid a large number of collisions.
    • The set of keys is pretty much randomly distributed, or at least not purposely designed to make the hash function perform poorly.

    The worst case complexity of a Hash table look-up is O(n), but that's extremely unlikely given the above 2 assumptions.

提交回复
热议问题