Why is accessing an element of a dictionary by key O(1) even though the hash function may not be O(1)?

后端 未结 8 1079
独厮守ぢ
独厮守ぢ 2020-12-13 23:53

I see how you can access your collection by key. However, the hash function itself has a lot of operations behind the scenes, doesn\'t it?

Assuming you have a nice h

8条回答
  •  攒了一身酷
    2020-12-14 00:09

    O(1) doesn't mean instant. O(1) means constant without regard to the size of the data. The hash function takes a certain amount of time, but that amount of time doesn't scale with the size of the collection.

提交回复
热议问题