Priority Queue with a find function - Fastest Implementation

前端 未结 7 2169
一向
一向 2021-02-07 13:24

I am looking at implementing a priority queue with an added requirement, a find/search function which will tell whether an item is anywhere within the queue. So the functions wi

7条回答
  •  故里飘歌
    2021-02-07 13:44

    Radix trees with a min-heap property will provide the properties you need. This will actually give you constant time complexities for your operations. For example, if we look at this Haskell implementation, all three operations you mention have time complexity O(min(n,W)). Where n is the number of elements, and W is the number of bits in an int (32 or 64).

提交回复
热议问题