When would I want to use a heap?

后端 未结 6 568
醉梦人生
醉梦人生 2021-01-29 23:29

Besides the obvious answer of a Priority Queue, when would a heap be useful in my programming adventures?

6条回答
  •  误落风尘
    2021-01-30 00:03

    The characteristic of a heap is that it is a structure that maintains data semiordered; thus, it is a good tradeoff between the cost of maintaining a complete order and the cost of searching through random chaos. That characteristic is used on many algorithms, such as selection, ordering, or classification.

    Another useful characteristic of a heap is that it can be created in-place from an array!

提交回复
热议问题