Code Examples
  Home arrow Code Examples arrow Depth-First Search 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

Depth-First Search in Graphs
By: Gabor Bernat
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 5
    2009-05-12

    Table of Contents:
  • Depth-First Search in Graphs
  • The code snippet and classification
  • Putting it together
  • The topological order

  • 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


    Depth-First Search in Graphs


    (Page 1 of 4 )

    Anyone or anything that can search effectively will eventually make a major impact on its environment. For a prime example just look at Google -- from a simple search engine came one of the largest companies in the world of IT. So here, in this article, we will discuss a good search algorithm for graphs. What importance may it yield in the future?

    Last time I presented the breadth-first search and as I told you then, I am continuing this series of articles about graphs with the second main search algorithm: the depth-first search. Our objective is to visit all points of the graph by starting from a root item and traveling through the edges.

    During this article I will focus just as much on the application of the depth-first search algorithm as on the technique itself, so beyond the search itself we are going to solve issues like determining if there is a circle in the graph, the basic circle system of a graph, and categorizing the edges according the depth-first search.

    We will sort the tree into a topological order; during a future article, we will find the strong connected components of a graph, and the disconnecting set. These are those edges that, if we remove them, we will increase the number of strongly connected components in the graph (articulation edges). In addition, of course, we will look at the bond, which is the same, but for a set of vertexes (articulation vertexes).

    The depth first search's short description is as follows. Visit the root item. Visit the child of that item, and follow on with the child of that item and so on until we find the "bottom" of the graph. Now step back and visit the second child of the previous item, and so on.

    The main difference between this and the breadth-first search is that, while the breadth-first search will first visit all the neighbors of the root item and continue only after doing this, the DFS will visit a vertex and immediately step ahead to the child of that item if it is possible. Otherwise, it steps back and tries to do the same with the second vertex, after that with the third (if it exists of course) until it has visited all of the neighbor edges. When we arrive at a child item, the same plan is applied.

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