When should I use a TreeMap over a PriorityQueue and vice versa?

后端 未结 8 2179
南旧
南旧 2020-12-23 11:46

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 advanta

8条回答
  •  难免孤独
    2020-12-23 12:10

    Rule of thumb about it is:

    TreeMap maintains all elements orderly. (So intuitively, it takes time to construct it)

    PriorityQueue only guarantees min or max. It's less expensive but less powerful.

提交回复
热议问题