Priority Queue with a find function - Fastest Implementation

前端 未结 7 2149
一向
一向 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:47

    IIRC search/find on a heap is O(n) whereas on a tree it is O(log(n)) and the other standard PQ operations are the same.

    Heaps are only empirically more efficient by some constant factor, so if its a big queue a tree should be better, if its small you need to test and profile. its all good to know in theory whats faster, but if those constant factors are large it may be completely irrelevant for sufficiently small data sets.

提交回复
热议问题