Priority queues support a 'decrease key' operation (https://en.wikipedia.org/wiki/Priority_queue#Summary_of_running_times), it is needed for a number of best first search type algorithms. It should run in O(log n) time. Does scala.collection.mutable.PriorityQueue support this efficiently?
Looking through the API docs the closest thing I can find is
def update (idx: Int, elem: A) : Unit
Replaces element at given index with a new value.
But there are two potential problems with this… firstly one has to find the element and it's not clear what the time complexity of findIndexOf
is.* Second it looks like update
allows the value to be increased as well as decreased; it's not clear whether that can be implemented efficiently.
*See e.g. How to implement O(logn) decrease-key operation for min-heap based Priority Queue? for proof that this can be done efficiently.
Does anyone know what the time complexity of update is?