Code Examples
  Home arrow Code Examples arrow 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


    (Page 1 of 4 )

    I need more time. I do not have time for this. These are probably the two sentences that we use the most these days. It has often been observed that time is money -- and accomplishing a task in fewer steps can save time (and thus money). With graphs, this can be expressed as finding the shortest path, and has a number of practical applications. This eighth part of a 13-part article series on graphs takes a close look at ways to solve this common problem.

    The following practical problem occurs. A new public person transport company arrives in town. They have a central bus station. They make a little survey in the town to determine which streets would have more clients. Now, given this favorable rate information about each street, we need to build the optimal routes, so we make the most cash with the least investment.

    Another chapter in my series about graphs starts here. In this and the next part, the central problem concerning us will be to determine the minimal road between vertexes inside graphs (therefore for everything that may be represented by graphs). Today we are going to examine two methods, leaving two more for a future article.

    Today we you will learn about Dijkstra’s Algorithm and the minimal road calculation based on topological order. Next time we will determine the same thing using the Bellman-Ford technique and the Roy-Floyd algorithm. Nevertheless, so you can understand what we will be discussing today, you should start with some basic knowledge that I already covered in my earlier articles.

    First, you need to know the definition of graphs and trees, and how we can represent them in our programs (read An Insight into Graphs). Second, you should be familiar with the concepts like the fundamental circle system and the topological sort. For this you may want to read my articles entitled Circles and Connectivity in Graphs and Depth-First Search in Graphs.

    When you have a general grasp of these concepts, you may read on. For solving the problem, we will use an array of n items where index v will show us the distance between the points from where we search for the minimal road to the others. In the future, we will refer to this as the root vertex (you will see why later).

    Therefore, if the v is our root vertex, at index v in our array, it will be zero, as we already are in that point and no longer need to make any future steps; the distance is zero accordingly. If there exists no road between the root vertex and index, v the distance is infinity. In our programming world, we will settle for an INT_MAX divided by two (so we can add these up).

    By definition, if there is a circle whose overall weight is negative, the distance of the points related to the circle is minus infinity. This is obvious, as we can always make a shorter path by just making another lap around the circle, eventually finishing up at minus infinity. The approach used by all of the algorithms I am going to show to you is the gradual approximation.

    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 4 Hosted by Hostway
    Stay green...Green IT