Code Examples
  Home arrow Code Examples arrow Page 4 - Circles and 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

Circles and Connectivity in Graphs
By: Gabor Bernat
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 2
    2009-05-19

    Table of Contents:
  • Circles and Connectivity in Graphs
  • Circles and the Base Circle System
  • Strong connective components
  • Show it 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


    Circles and Connectivity in Graphs - Show it in C


    (Page 4 of 4 )

    Quite ingenious, is it not? Moreover, here is our modified BFS algorithm. First, we call a simple DFS to tell us the inverse order of how we leave the vertexes; this will be saved inside the topological array, as shown in the previous article.  Second, we invert the graph inside the inverseList array and finally call the DPS in the right order. Here is what this looks like when translated into C:

    void DFS_inver(int vertex)

    {

     

          printf(" %d ", vertex);

     

          pListIt p;

          color[vertex] = GRAY;

          for (p = inverseList[vertex]; p != NULL; p = p -> p_next)

                if (!color[p -> value])

                {                

                      DFS_inver(p -> value);

                }    

    }    

     

     

    for (i = 0 ; i < n; ++i)

          if (!color[topological_order[i]])

                      {

                            callCount++;

                            printf("n%d) ", callCount);

                            DFS_inver(topological_order[i]);

     

                      }

     

    This way we will get as result for the upper graph the result:

     

    The strong connected components of the graph

     

    1)  1  8  5  2  12  11  9  6  3  10  18  14  20  15  19

    2)  4

    3)  17

    4)  13  22  16

    5)  21

    6)  7

    With this, we have solved all the problems for today. Now if we want to tell what points on the map can be reached from a certain point, all we need to do is enter the map's information as input and read the result from the output file. Here is the C source file that contains all of the techniques discussed in this article. Feel free to explore it and try it out for different inputs.

                                                    -->BDF.zip<--     

    I would like to thank you for reading through my article and invite you to tell me your thoughts related to it here on the blog or over at our friendly forum on Dev Hardware. The subject of our next article will be articulation edges and vertexes, so if you are interested make sure to come back. Until the next time we meet, Live With Passion!


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

     

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