Difference between priority queue and a heap

后端 未结 5 1271
我在风中等你
我在风中等你 2021-01-30 16:38

It seems that a priority queue is just a heap with normal queue operations like insert, delete, top, etc. Is this the correct way to interpret a priority queue? I know you can b

5条回答
  •  [愿得一人]
    2021-01-30 17:12

    A priority queue is an abstract datatype. It is a shorthand way of describing a particular interface and behavior, and says nothing about the underlying implementation.

    A heap is a data structure. It is a name for a particular way of storing data that makes certain operations very efficient.

    It just so happens that a heap is a very good data structure to implement a priority queue, because the operations which are made efficient by the heap data strucure are the operations that the priority queue interface needs.

提交回复
热议问题