Which is faster, Hash lookup or Binary search?

后端 未结 17 2536
你的背包
你的背包 2020-12-02 06:47

When given a static set of objects (static in the sense that once loaded it seldom if ever changes) into which repeated concurrent lookups are needed with optimal performanc

17条回答
  •  萌比男神i
    2020-12-02 07:07

    This is more a comment to Bill's answer because his answer have so many upvotes even though its wrong. So I had to post this.

    I see lots of discussion about what is the worst case complexity of a lookup in hashtable, and what is considered amortized analysis / what is not. Please check the link below

    Hash table runtime complexity (insert, search and delete)

    worst case complexity is O(n) and not O(1) as opposed to what Bill says. And thus his O(1) complexity is not amortized since this analysis can only be used for worst cases (also his own wikipedia link says so)

    https://en.wikipedia.org/wiki/Hash_table

    https://en.wikipedia.org/wiki/Amortized_analysis

提交回复
热议问题