Why heap is better than binary tree to represent a priority queue?
问题 In a (max) heap it is easy to find the biggest item in O(1) time, but to actually remove it you need complexity of O(log(n)) . So if the insertion and deletion from a heap is both O(log(n)) , what are the advantages of a heap over binary tree for representing a priority queue? 回答1: Heaps use less memory. They can be implemented as arrays and thus there is no overhead for storing pointers. (A binary tree CAN be implemented as an array, but there is likely to be many empty "gaps" which could