Armyx's blog

By Armyx, history, 9 years ago, In English

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 ?

  • Vote: I like it
  • +1
  • Vote: I do not like it

| Write comment?
»
9 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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.