Development Cycles
  Home arrow Development Cycles arrow Page 3 - Learning About the Graph Construct using G...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
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? 
DEVELOPMENT CYCLES

Learning About the Graph Construct using Games, Part II
By: Mohamed Saad
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 26
    2005-03-15

    Table of Contents:
  • Learning About the Graph Construct using Games, Part II
  • Dijkstra's algorithm
  • Algorithm in action
  • Floyd-Warshall algorithm
  • Back to the water problem

  • 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


    Learning About the Graph Construct using Games, Part II - Algorithm in action


    (Page 3 of 5 )

    This is the whole idea behind the algorithm. If it is still unclear, here is a quick example of this algorithm in action.

    In this graph…

    We want to find shortest paths starting at node A.

    Here are the arrays again in case you have forgotten them

    At first, we choose the smallest distance to an unvisited node (see the arrays we created above), so we choose the node e. Its entry at distance is 5, and it is not visited yet.

    Now, we check to see if going from a to e, and then to any other node makes any improvements, and indeed, we find that the path to f is improved. Now, we can move to f with a cost of 9, (move from a to e, which costs 5, and then move from e to f, which costs 4) so we update it.

    Also, the path to c has been improved. The cost was infinity, now c can be reached with a cost of only 15. We update this one too. The arrays now become:

    Next, we choose the smallest non-visited distance, so we pick f this time (its distance is only 9). We find that the path to d has been improved from infinity to only 29.

    The arrays become:

    The third time, we pick c, the distance to d is now improved from 29 to only 20.

    The arrays become:

    We keep doing the same, till the shortest path is found to every node.

    We end up with

    We can now easily know the shortest path from node a to any node.

    For example, to get the path from node a to node d, we keep following the previous array till we reach node 0 (0 is the index of node a).

    We get d à 2 (this is c) à 4 (this is e) à 0 (this is a)

    So, the path is aàeàcàd, whose length is 20.

    That was the first algorithm; it wasn't very hard, was it?

    Now, let's move on to the other algorithm.

    More Development Cycles Articles
    More By Mohamed Saad


     

    DEVELOPMENT CYCLES ARTICLES

    - Branch and Bound Algorithm Technique
    - Dynamic Programming Algorithm Technique
    - Genetic Algorithm Techniques
    - Greedy Strategy as an Algorithm Technique
    - Divide and Conquer Algorithm Technique
    - The Backtracking Algorithm Technique
    - More Pattern Matching Algorithms: B-M
    - Pattern Matching Algorithms Demystified: KMP
    - Coding Standards
    - A Peek into the Future: Transactional Memory
    - Learning About the Graph Construct using Gam...
    - Learning About the Graph Construct using Gam...
    - Learning About the Graph Construct using Gam...
    - How to Strike a Match
    - Entity Relationship Modeling






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT