Code Examples
  Home arrow Code Examples arrow Page 3 - An Insight into 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

An Insight into Graphs
By: Gabor Bernat
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2009-05-06

    Table of Contents:
  • An Insight into Graphs
  • The Theory
  • Graphs and programming
  • Adjacent List Representation in C

  • 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


    An Insight into Graphs - Graphs and programming


    (Page 3 of 4 )

    Now that we've finished our discussion of theory, we can start with the proper programs and algorithms. However, as sad as it is, we cannot draw up the graph for coding languages, so we need to code it somehow. There exists several representation modes; each of them will be more or less adequate to a specific algorithm, and to achieve maximal efficiency we need to use the correct one.

    There are around seven types of representation, however I will present only a couple of them in detail, as the rest will have little importance to the algorithms we are going to study later on.

    The first and the most important one is the adjacent list, where for every vertex  is enumerated all the vertexes with which it has a direct connection (though for  directed graphs, only the out-going edges will be taken into account). Realizing this in code is a little more complicated, so I have allocated it to it the next page.

    The edge list is the enumeration of the edges with the syntax from node to node. This can be easily made with a matrix of 2 X m(number of edges). This is the one used most of the time when you read in the graph, as it makes it easy to add and remove edges.

    The adjacent matrix will have n columns and n rows, where at the i-th row and j-th column will be:

    ---> k if there exists k number of edges between "i" and "j" if "i" is not equal with "j".

    ---> h if, there exists h number of loop edges if "i" equal "j".

    ---> 0 if there exists no edge between "i" and "j".

    Furthermore, there exists the circle matrix representation, the incidence matrix or the cut matrix; however, I will not discuss these as they are too rarely used; search for them on the Internet if you are interested. The last one will be the representation of trees.

    This is done most of the time with a single array of n, where the "i"-th place will be the number of its ancient. The root item will be -1 or 0 depending on implementation. This way we can even determine the road from the root to a leaf by applying recursive calls to this array.

    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 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek