Boost Fibonacci Heap Decrease Operation

混江龙づ霸主 提交于 2019-12-10 17:56:16

问题


The new 'heap' boost library includes a fibonacci heap. The complexity of each implementation can be seen here: http://www.boost.org/doc/libs/1_51_0/doc/html/heap/data_structures.html.

My question is this: Why is the fibonacci heap decrease operation O(log(N)), while the increase operation is O(1)?

I would like to experiment with using the fibonacci heap in Dijkstra's algorithm, which is heavily dependent upon a fast decrease operation.


回答1:


According to http://www.boost.org/doc/libs/1_51_0/doc/html/heap/concepts.html

boost.heap implements priority queues as max-heaps to be consistent with the STL heap functions. This is in contrast to the typical textbook design, which uses min-heaps.

The textbook/wikipedia Fibonacci heap has the highest priority element with the lowest value, aka a min-heap (e.g. "1" is higher priority than "2"). STL and Boost (for consistency with STL) reverse the definition so that the highest priority has the highest value, aka a max-heap (i.e. a "2" higher priority than "1").

Essentially it means that decrease and increase have inverse meanings between textbook and Boost.

If you want to get a min-heap (like the textbook definitions), you must first defined an appropriate boost::heap::compare functor for your fibonacci_heap (see an example here: Defining compare function for fibonacci heap in boost), then call increase whenever you decrease the value associated with a heap element (and are thus increasing the priority) and vice-versa.



来源:https://stackoverflow.com/questions/12698431/boost-fibonacci-heap-decrease-operation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!