Why use heap instead of binary tree when implementing priority queue?

后端 未结 5 1450
鱼传尺愫
鱼传尺愫 2021-02-15 23:31

It seems to me that the only advantage of heap over binary tree is to find the smallest item in the heap in complexity of O(1) instead of O(log(2)n) in binary tree.

When

5条回答
  •  后悔当初
    2021-02-15 23:53

    If you use a find or search operation a lot then a balanced binary tree is preferred. Line segments intersection code use balanced trees instead of heaps because of this one reason.

提交回复
热议问题