PriorityQueue/Heap Update

前端 未结 6 720
礼貌的吻别
礼貌的吻别 2020-12-05 07:07

Does Java have an easy way to reevaluate a heap once the priority of an object in a PriorityQueue has changed? I can\'t find any sign of it in Javadoc, but the

6条回答
  •  眼角桃花
    2020-12-05 07:27

    Depending on the implementation of the data structure, there may not be a faster way. Most PQ/heap algorithms do not provide an update function. The Java implementation may not be any different. Notice that though a remove/insert makes the code slower, it is unlikely to result in code with a different runtime complexity.

    Edit: have a look at this thread: A priority queue which allows efficient priority update?

提交回复
热议问题