I'm trying to run Dijkstra's algorithm and I need to implement a decreaseKey
function. I'm having trouble doing it. I read one solution here but it uses a lot of memory by storing a hash map in the heap. Is there a way to implement decreaseKey
without a hash map and still maintain O(log n) time?
So far my decreaseKey
function takes two parameters: vertex and newDistance. When I call decreaseKey(vertex * v, int newDistance)
, the algorithm has to find the index where vertex 'v' is stored and then change its distance. I can't figure out how to 'find' the vertex to get its index and keep it in O(log n) time.