Code Examples
  Home arrow Code Examples arrow Page 2 - Shortest Path Algorithms in Graphs
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
CODE EXAMPLES

Shortest Path Algorithms in Graphs
By: Gabor Bernat
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2009-05-27

    Table of Contents:
  • Shortest Path Algorithms in Graphs
  • The gradual approximation
  • The Topological Order-Based Algorithm
  • Dijkstra’s Algorithm

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Shortest Path Algorithms in Graphs - The gradual approximation


    (Page 2 of 4 )

    Strangely enough, there is no algorithm that can tell us just the shortest road between two points. All of the techniques calculate the minimal road from a single source to all the other vertexes. At least no mathematician has found a way to this day, so feel free to look into building your own. 

    The gradual approximation reuses the fundamental of optimality. This implies that a shortest paths sub-road is also shortest road. This means, to put it simply, that if the shortest road from Berlin to Paris is via Luxembourg, then the road between Paris to Luxembourg is also a shortest route.

    From this comes three conclusions. One is the fact that, from roads containing fewer edges, we can build longer ones (so if we find that the road from Paris to Luxembourg is a shortest one, we can determine from this, eventually, the shortest road from Paris to Berlin).

    Second is that the result will be a tree whose root is the source vertex. All of the following algorithms somehow build the roads as a tree growing out from the source vertex at each step, adding another edge to the tree. The minimal roads will form a tree, and the solution in the end will be a tree, and from this it follows that it will contain n-1 edges.

    The third conclusion is the following equation, where SR is an acronym for Shortest Road:

    SR(s, v) = SR(s, u) + SR (u, v)

    Moreover, the algorithm solving the problem may be summed up in the following steps. First, we start from the array of distances where we guesstimate the distance to the other vertexes to infinity. The root from the source vertex to the source vertex is zero.

    We will make gradual approximations to the best solution systematically by checking the following expression and applying it if the idiom turns out to be true:

    if (distance[v] > distance[u] + edgeDistance[u] [v])

    {

    distance[v] > distance[u] + edgeDistance[u] [v];

    ancient[v] = u;

    }

    The edgeDistance two-dimensional array is a weight matrix that in fact contains the weight of the edges. If there is no edge between two vertexes, this will be infinity. Now you can see why we need to define infinity as something that allows us to add infinity to infinity.

    The upper step is to be repeated until we build a tree, at which point, from the parent array, we can also tell through which points our shortest road travels. At every approximation, we will add another edge to the tree.

    The trick is to make these approximations in the right order and at the right time. The following three algorithms (two in this article and one in the next) differ only by how they find the right order in which to make these approximations. They are different because they solve another problem, and need to take into account another complication factor, as we will see as we examine the techniques.

    More Code Examples Articles
    More By Gabor Bernat


     

    CODE EXAMPLES ARTICLES

    - Bipartite Graphs
    - Connectivity in Graphs
    - The Ford-Fulkerson Algorithm
    - Critical Paths
    - The Bellman-Ford and Roy-Floyd Algorithms
    - Shortest Path Algorithms in Graphs
    - Minimum Spanning Tree
    - Articulation Edges and Vertexes
    - Circles and Connectivity in Graphs
    - Depth-First Search in Graphs
    - Breadth-First Search in Graphs
    - The Prufer Code and the Floyd-Warshall Algor...
    - An Insight into Graphs
    - Coding a Custom Object with WSC
    - Creating a Custom Object with WSC





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek