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

Bipartite Graphs
By: Gabor Bernat
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2009-06-04

    Table of Contents:
  • Bipartite Graphs
  • The Problem
  • The Colorize Code Source
  • The Solution

  • 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


    Bipartite Graphs - The Problem


    (Page 2 of 4 )

    The first and most important question is, how do we divide a given graph into two individual sets? We could also write a program that will ask for the data from two different files, or ask for the vertexes one after another and only then add the edges.

    However, this is a time-intensive job, and we will decrease the re-usability of the program. Any little modification would mean a major modification in the code. We want to make it as user-friendly as possible, so whoever adds the data in the input file should only add the edges representing the efficiency.

    The issue, translated again into the language of graphs, is to find out if the graph is bipartite, and if so, make the split into set A and set B. A pair graph is one within which the edges are not directed, and can be split in two individual sets where every edge has one end in the first set and the other end in the second set.

    When can any kind of graph be split into two types of sets? This can be done only if all of the basic circle system's components have a length that is also a pair number. Now again, if you are not familiar with the statement of circle systems, you can just read my article entitled Circles and Connectivity in Graphs.

    Before you jump in to see if this is correct, there is a shorter solution. It is possible with the Breadth-First Search. This search visits the edges by level. First, it drops by the root. It then visits all of the direct neighbors (also called children). It next visits the children of all the children of the root (of course skipping the ones that were already touched). Repeat these steps until you have no more edges to visit.

    If we follow this idea we can add all the odd numbered edges (in the parent tree) to set one and the others to set B. To determine invalid graph input, it is only a matter of testing to see if the bottom-most leaf in the tree and the root have the same color.

    This process is also called coloring of the graph's nodes with two colors. Therefore, we will refer to this as the colorizing process. However, assume that we have the correct input. With this search, we can count how many nodes we added to which color and return the number of the color which is less used, to make it clear which one of them has more elements. This can save us an extra iteration.

    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