Finding an appropriate data structure

前端 未结 3 879
离开以前
离开以前 2021-01-24 14:19

I have N keys.

I need to find a data structure which i can do with the following operations :

  1. building it in O(N)

  2. finding min in O(1)

3条回答
  •  庸人自扰
    2021-01-24 14:59

    Simple sorted Array would solve the problem for #2 #3 and #4. But the construction of it would take O(nn). However, there are no restrictions put on space complexity. I am thinking hard to use Hashing concept during the construction of the data structure which would bring down the order to O(n).

    Hope this helps. Will get back if I find a better solution

提交回复
热议问题