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

后端 未结 5 1722
予麋鹿
予麋鹿 2021-02-15 23:21

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-16 00:04

    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.

提交回复
热议问题