previous | start | next

Priority Queue Implementation - answer?

The cost is the sum of insertions plus the deletions.

  1. Unordered List
              N insertions costs N  (really some small constant times N)
              15 deletions costs about 15N (may have to search all items)
              Total = 16N
             
    
  2. MaxHeap implementation
                N insertions costs Nlog(N)
                15 deletions costs about 15log(N)
                Total = Nlog(N) + 15log(N)
             
    

    If log(N) > 16 (that is, N > 216 ~ 65000), max heap is more expensive.



previous | start | next