Java

Moderators: zibadian
Number of threads: 7836
Number of posts: 18235

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Re: Dijkstra's shortest path Posted by pcs2112 on 19 Dec 2007 at 9:44 AM
: Please formulate your problem.

need help understanding how to code

1  function Dijkstra(Graph, source):
 2      for each vertex v in Graph:           // Initializations
 3          dist[v] := infinity               // Unknown distance function from s to v
 4          previous[v] := undefined
 5      dist[source] := 0                     // Distance from s to s
 6      Q := copy(Graph)                      // All nodes in the graph are unoptimized - thus are in Q
 7      while Q is not empty:                 // The main loop
 8          u := extract_min(Q)               // Remove best vertex from priority queue; returns source on first iteration
 9          for each neighbor v of u:         // where v has not yet been considered
10              alt = dist + length(u, v)
11              if alt < dist[v]              // Relax (u,v)
12                  dist[v] := alt
13                  previous[v] := u
14      return previous[]

Thread Tree
pcs2112 Dijkstra's shortest path on 19 Dec 2007 at 8:32 AM
IDK Re: Dijkstra's shortest path on 19 Dec 2007 at 9:32 AM
pcs2112 Re: Dijkstra's shortest path on 19 Dec 2007 at 9:44 AM
IDK Re: Dijkstra's shortest path on 19 Dec 2007 at 10:19 AM
pcs2112 Re: Dijkstra's shortest path on 19 Dec 2007 at 10:22 AM
IDK Re: Dijkstra's shortest path on 19 Dec 2007 at 11:48 AM



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.