Development Cycles
  Home arrow Development Cycles arrow Page 5 - 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  
Moblin 
JMSL Numerical Library 
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 1
By: Mohamed Saad
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 18
    2005-02-23

    Table of Contents:
  • Learning About the Graph Construct using Games, Part 1
  • Representing a Graph
  • Adjacency List Representation
  • Variations on graph representation
  • Weighted Edges
  • Labelled nodes
  • Building the Graph

  • 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 1 - Weighted Edges


    (Page 5 of 7 )

    This is easier than the previous case. In our previous examples, we were only interested in the existence of an edge. In some applications, edges also have weights on them. For example, in the cities and highways example, we could put the length of a highway as a weight for the edge between two cities. This will allow us to find the shortest path between two cities precisely.

    How could we add weighted edges to the graphs we just created? This one is easy. For an adjacency matrix, we just write the weight of the edge in the corresponding entry in the matrix rather than just “1” and “0”. Notice that in some applications, “0” is a valid weight. In this case, it can’t be used as a “no-edge” value. We will have to look for another value in this case. For example, this graph: 
     


    Fig 4.
    Graphs with weighted edges…

    Would be represented by this array: 
     


    Fig 4b.
    … can still be represented using adjacency matrix

    We have used an symbol in place of non-existent edges. In reality, we can use any invalid value to denote that no edge exists here.

    In the case of an adjacency list, we can add a new field in every node of every linked list, which holds the weight of that edge.

    For example, the same graph above would be represented like this:

     

    Fig 4c. … Adjacency list representation of weighted graphs

    The first node in the first linked list, means that node a is connected to node f with a weight of 12. (Notice that node counting starts at 0 for obvious reasons!)

    More Development Cycles Articles
    More By Mohamed Saad


     

    DEVELOPMENT CYCLES ARTICLES

    - 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
    - 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







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