How to optimize Dijkstra algorithm for a single shortest path between 2 nodes?
- by Nazgulled
Hi,
I was trying to understand this implementation in C of the Dijkstra algorithm and at the same time modify it so that only the shortest path between 2 specific nodes (source and destination) is found.
However, I don't know exactly what do to. The way I see it, there's nothing much to do, I can't seem to change d[] or prev[] cause those arrays aggregate some important data for the shortest path calculation.
The only thing I can think of is stopping the algorithm when the path is found, that is, break the cycle when mini = destination when it's being marked as visited.
Is there anything else I could do to make it better or is that enough?
P.S: I just noticed that the for loops start at 1 until <=, why can't it start at 0 and go until <?