Code Examples
  Home arrow Code Examples arrow Page 3 - Connectivity in 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

Connectivity in Graphs
By: Gabor Bernat
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2009-06-03

    Table of Contents:
  • Connectivity in Graphs
  • Back to the Basics
  • K Connectivity
  • The k Node Connectivity

  • 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


    Connectivity in Graphs - K Connectivity


    (Page 3 of 4 )

    There are two types of connectivity in graphs, connectivity of the edges and connectivity of the vertexes. Whenever we talk about connectivity, we first refer to it as of the edges. When we want to talk about vertexes, we need to talk about K Vertex Connectivity. What is covered under this name?

    Connectivity refers to the fact that there exists a road between any two nodes. K Connectivity says that, if we eliminate any number less than k of that type of component (any one) from the graph, we will still get a connected graph. Of course, if we eliminate vertexes we also delete the edges related to them.

    So how does this tie in with a war in Vietnam? Let there be n military bases. Each one of them can communicate with a specific number of other bases. The connections build up a graph with directed edges inside it. The connections can be mutual; if this is the case, we can just add an edge in both directions.

    The information arrives at headquarters that the enemy has eliminated k military bases. The question is, can we remain calm, considering the way that our bases can connect with the other remaining bases? This is node connectivity. We can imagine a case when the edges are relevant. For instance, we talk about roads, and if k instances of them got bombed, could we still reach all the cities?

    From the definition you can already see that the connectivity of nodes is a much more serious trait than of vertexes, and we will see immediately why this is true. From the definition of connectivity, we can sense that we are talking about individual roads. In order for us to still be able to reach a point when an edge or vertex is eliminated, we must have an alternative road we can use to get there. 

    Connectivity in fact hides the number of individual roads between a point and all the rest inside the graph. In the case of edge connectivity we are talking about different edges, while in the case of node connectivity, the vertexes through which the road passes have to be different.

    So the source will be the vertex itself, which we are observing, while the terminal handles all the ends. The algorithm is simple. Consider the graph and iterate through every different vertex pair. Let every edge have a capacity of one. Call the Ford-Fulkerson algorithm for each pair to calculate the number of different (alternative) roads.

    If the capacity is the maximum flow that can travel through, the graph will be just like this. All that we have to do is to pick the smallest number from this, and that will tell us how many edges we can delete and still be able to contact any military base. Note that we can pick for removal any one of the edges, not just a collection of them, as long as we choose k number of them.

    Here it is all this implemented in C code. We need to reset the current flow number to zero before each call.

    int kConnectedEdge(Vertex**& neighborMatrix, Node*& list, const int& n)

    {

     

    int i = 0, j = 0, curKCon = 0;

    int k = INFINITY;

     

    for( i=1; i <= n-1; ++i)

    for( j=i+1; j<= n; ++j)

    {

    int a =0, b = 0;

     

    for (a = 1; a <= n; ++a)

    for (b = 1; b <= n ; ++b)

    {

    neighborMatrix[a][b].flowValue = 0;

    }

     

    curKCon = Ford_Fulkelson(neighborMatrix, list, i , j, n);

     

    if (curKCon < k)

    {

    k = curKCon;

    }

    }

     

    return k;

    }

    Here is an example graph:

    With our algorithm, all this will look as follows, as we need to double every edge and add the direction to them:

     

    The result in the output file is correct:

    The input graphs edge connectivity is 3

     

    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