优先队列的decrease-key操作如何实现?

leonardWang 2010-03-13 03:57:40
lg(n)复杂度的前提是已经知道元素在队列数组中的位置了
但是Extract-Min和Insert操作都会打乱原有的位置
难道用个哈希表来不断维护位置信息?
其实问题就是如果只允许向优先队列插入不同的Key(如果已存在且插入的Key对应的Value要小 则更新)[优先队列是以value为比较的最小堆]
比如是优先队列实现Dijsktra算法
...全文
1120 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
leonardWang 2010-03-15
  • 打赏
  • 举报
回复
看了下算法导论 找到答案了。。
Not surprisingly, we can use a heap to implement a priority queue. In a given application, such as job scheduling or event-driven simulation, elements of a priority queue correspond to objects in the application. It is often necessary to determine which application object corresponds to a given priority-queue element, and vice-versa. When a heap is used to implement a priority queue, therefore, we often need to store a handle to the corresponding application object in each heap element. The exact makeup of the handle (i.e., a pointer, an integer, etc.) depends on the application. Similarly, we need to store a handle to the corresponding heap element in each application object. Here, the handle would typically be an array index. Because heap elements change locations within the array during heap operations, an actual implementation, upon relocating a heap element, would also have to update the array index in the corresponding application object. Because the details of accessing application objects depend heavily on the application and its implementation, we shall not pursue them here, other than noting that in practice, these handles do need to be correctly maintained.

sharp_man 2010-03-15
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 leonardwang 的回复:]

看了下算法导论 找到答案了。。
Not surprisingly, we can use a heap to implement a priority queue. In a given application, such as job scheduling or event-driven simulation, elements of a priority queue correspond ……
[/Quote]
算法导论,经典啊,没读完~
FancyMouse 2010-03-15
  • 打赏
  • 举报
回复
嗯。给dij这类算法服务的堆的确需要另开一个指针数组。

33,008

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧