Development Cycles
  Home arrow Development Cycles arrow 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  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
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 / 25
    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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Learning About the Graph Construct using Games, Part II


    (Page 1 of 5 )

    In this second article in a three part series, we learn about two famous algorithms that can be used to solve the classic shortest path problem, and finally get the solution to the water jug division task set in the first part (no fair reading ahead to find it!).

    Welcome back! This is part two of the three part series entitled "Playing games with graphs." In part one, we gave an introduction to graphs, and introduced the problem of water division. We saw how we can construct the graph for this problem. Today, we are going to handle finding the shortest path from the source node to the destination node.

    Recall from part one that in the graph constructed, a node represented a state of the jugs. The initial state was "8","0","0" or 8 liters in the first jug, with other two jugs empty. We constructed a graph of all possible states that can be reached. We needed to find the shortest path from the node "8","0","0" to the node "4","4","0"

    Shortest path problem

    The shortest path problem is quite straightforward. Given two nodes in a graph, it is necessary to find the shortest path between them. Luckily for us, the shortest path problem is an easy problem to solve, unlike the longest path problem, which surprisingly, is a very hard problem to solve. This is one of the rare occasions in life where the more useful problem is also the easier one. But let's set theory aside for now, we have a task to do.

    There are two very famous algorithms for finding the shortest path in a graph. Those are the ones we are going to introduce here.

    The first algorithm starts with a node, and proceeds to find the shortest path from this node to all other nodes in the graph. This is called the single-source all-destination shortest path for obvious reasons. This algorithm was devised by Dijkstra.

    The other algorithm just finds the shortest path from every node in the graph to every other node. This is obviously called all-source all-destination. This algorithm was developed by Floyd and Warshall.

    As you may imagine, the Floyd-Warshall algorithm is a little harder to comprehend than Dijkstra's algorithm (simply because it does more). We are going to present both ideas first, and then we are going to show all the details behind Dijkstra's algorithm to solve the problem at hand.

    More Development Cycles Articles
    More By Mohamed Saad


     

    DEVELOPMENT CYCLES ARTICLES

    - 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
    - Tame the Beast by Matching Similar Strings
    - 5 Web Design Tips You Can't Live Without
    - Practising Best Practises in Your Software D...
    - The Art of Modelling: Part 1
    - Thoughts on the Craft of Programming: Abstra...
    - Hi 5: Part 4
    - Domain Modeling: Leveraging the Heart of RUP...
    - Quality Vs Speed: Paradox Lost?







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