How to optimize Dijkstra algorithm for a single shortest path between 2 nodes?
Posted
by Nazgulled
on Stack Overflow
See other posts from Stack Overflow
or by Nazgulled
Published on 2010-04-16T20:22:28Z
Indexed on
2010/04/16
23:53 UTC
Read the original article
Hit count: 348
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 <
?
© Stack Overflow or respective owner