Code Examples
  Home arrow Code Examples arrow Page 2 - 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 - The Theory


    (Page 2 of 4 )

    Now, despite what you might think from the title, I will not embark on a deep adventure into the waters related to the theory shores. Following the quote starting this article, I will try to keep everything as simple as possible -- but not a bit simpler. This is the starting point of an article series, throughout which I will endeavor to explain the main points of interest of the graphs in use to this day.

    I will try to present all of this from the point of view of the programmer, putting  the mathematical parts in the background. So you'll see no mathematical theory proofs here, sorry. However, every presentation of an algorithm will be accompanied by some pure code snippet in the language of C (maybe mixed in with a little C++; nevertheless, there will be no object-oriented programming involved).

    Regardless, we still need some minimal theoretical knowledge to understand the future articles, so here it goes, as compressed and straightforward as possible.

    Every graph is composed of n vertexes (objects) and m edges (links between the objects). Edges that have the same starting point and ending point are called loop edges. You can see one in the graph below at vertex number 3. Multiple edges are the ones that have the same start and end, just like the two between vertexes one and five on the image below:

    Simple graphs are those that contain no loop or multiple edges. Two vertexes are considered neighbors if an edge exists between them. For example, on the upper graph, vertex one and two are neighbors.

    Isolated vertexes are vertexes that have no edge attached to them (vertex 6 is the correct illustration for this). Further, we can declare in and out degrees for vertexes. This will show how many edges come into (in) and go out from a specific vertex. For instance the vertex four has an in-degree of two (edges coming from vertices three and five) and out-degree of one (edge towards vertex five).

    The in- and out-degree of a vertex will be equal if the graph's edges are not directed. A graph is k regular if every vertex has a degree equivalent to k. A walk is a consecutive sequence of edges between two points. If this sequence will not go through any of the vertexes twice, it is called a road. A circuit is a closed road (aka the start and the end are the same). If none of the edges stays twice in the succession, we're talking about a trail.

    We can also define the complement of a graph, sub graph and complete graph, as the three images below illustrates.

    --Graph A--

     

    --Graph B --

     

    --Graph C --

    -Graph C -

    A complete graph is one inside which there exists an edge between all of the vertexes, as in the Graph C. Graph A and Graph B are sub-graphs of Graph C, as we can obtain them by removing an arbitrary number of edges or vertices and the edges related to them. Graph A is the complement of Graph B and vice versa, because if we put the two together, they will provide a complete graph.

    Inside a connected graph, there exists a road between any two of the points. Here the graph is not directed. In a strongly connected graph (which is also directed), there exists a road in both directions between any two vertices. Graphs inside which there are no circles are called forests. The ones that are also connected are simply called referred. Inside a tree, vertexes that have only one edge attached to them are leafs.

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