Блог пользователя Armyx

Автор Armyx, история, 9 лет назад, По-английски

I used to program in c++ and I know that dijkstra implemented on priority_queue works faster than the one implemented using set. What is the best dijkstra implementation in java ? Should I use TreeSet or Priority queue ?

  • Проголосовать: нравится
  • +1
  • Проголосовать: не нравится

»
9 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Since you only care about the minimum element in Dijkstra, I believe that Priority Queue will be better. I think it's less work to maintain a heap than a TreeMap for the sole purpose of getting the minimum element.

Also, most top JAVA coders I saw always used a PriorityQueue, I guess if TreeMap was more efficient for that purpose, they would have done it.