title: How to optimize Dijkstra algorithm for a single shortest path between 2 nodes?
body: <p>I was trying to understand <a href="http://compprog.files.wordpress.com/2008/01/dijkstra.c" rel="nofollow noreferrer">this implementation</a> 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.</p>
  
  <p>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 <code>d[]</code> or <code>prev[]</code> cause those arrays aggregate some important data for the shortest path calculation.</p>
  
  <p>The only thing I can think of is stopping the algorithm when the path is found, that is, break the cycle when <code>mini = destination</code> when it's being marked as visited.</p>
  
  <p>Is there anything else I could do to make it better or is that enough?</p>
  
  <p><strong>EDIT:</strong><br>
  While I appreciate the suggestions given to me, people still fail to answer exactly what I questioned. All I want to know is how to optimize the algorithm to only search the shortest path <strong>between 2 nodes</strong>. I'm not interested, for now, in all other general optimizations. What I'm saying is, in an algorithm that finds all shortest paths from a node X to all other nodes, how do I optimize it to only search for a specific path?</p>
  
  <p>P.S: I just noticed that the <code>for</code> loops start at <code>1</code> until <code>&lt;=</code>, why can't it start at <code>0</code> and go until <code>&lt;</code>?</p>