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  
Dedicated Servers  
Actuate Whitepapers 
VeriSign Whitepapers 
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 / 17
    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
     
    Iron Speed
     
    ADVERTISEMENT

    AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th -1:00PM EST. Register Today!

    Learning About the Graph Construct using Games, Part 1 - Adjacency List Representation


    (Page 3 of 7 )

    The adjacency list method is a different representation that is quite good when graphs are not dense enough. How does it work? This is simple. All it does is store a series of linked lists, one linked list per node. Each linked list stores the edges coming out of a certain node.

    In other words, the first linked list stores the ids of all nodes node 1 is connected to. The second linked list stores the ids of all nodes node 2 is connected to, and so on. Fir example, if we look at the following graph: 
     


    Fig 3.
    This graph…

    It would be represented that way:

     

    Fig 3b.
    … is represented by this adjacency list.


    Notice that the number of linked lists is equal to the number of nodes. The first linked list is empty, since node one is not connected to anything. The second linked list has two elements, since node two is connected to both node one and node three. We are basically using an array of linked lists. I hope this expression doesn’t scare you. It is simpler than it sounds.

    What are the advantages of this representations?

    1. If the graph is not very dense, this representation is great, because it doesn’t waste memory locations for non-existent edges.
    2. It is easy to list all of the edges coming out of a node. The time taken is exactly equal to the number of edges, unlike what happens when using adjacency matrices.

    What are the disadvantages?

    1. If the graph is very dense, (for example, we have a fully connected graph), the memory taken is more than that taken by adjacency matrices, because of the extra allocation for the pointers in the linked list.
    2. To answer the question “Does an edge exist between nodes A and B?”, you must visit all nodes of the linked list of A (as opposed to looking up one entry when using adjacency matrix).

    The bottom line is, adjacency lists shine when graphs are not very dense. On the other hand, an adjacency matrix is great when graphs are very dense.

    This is going to be the last bit of theory, before we jump straight into the first game.

    Before we drift away from the topic of representation, I want to quickly touch on a very important point. It is about important variations.

    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?


    Iron Speed





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