似乎他们都让你检索最小值,这是我对Prim算法所需要的,并强制我删除并重新插入一个键来更新它的值。使用一个优于另一个是否有任何优势,不仅仅是这个例子,但一般来说?
Seems they both let you retrieve the minimum, which is what I need for Prim's algorithm, and force me to remove and reinsert a key to update its value. Is there any advantage of using one over the other, not just for this example, but generally speaking?
推荐答案一般来说,它使用堆来跟踪最小元素的工作量较少。
Generally speaking, it is less work to track only the minimum element, using a heap.
树更有条理,需要更多计算才能维护该组织。但是如果你需要访问任何键,而不仅仅是最小值,那么堆就不够了,并且树的额外开销是合理的。
A tree is more organized, and it requires more computation to maintain that organization. But if you need to access any key, and not just the minimum, a heap will not suffice, and the extra overhead of the tree is justified.
更多推荐
什么时候应该在PriorityQueue上使用TreeMap,反之亦然?
发布评论