﻿<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD with MathML3 v1.2 20190208//EN" "http://dtd.nlm.nih.gov/publishing/3.0/journalpublishing3.dtd">
<article
    xmlns:mml="http://www.w3.org/1998/Math/MathML"
    xmlns:xlink="http://www.w3.org/1999/xlink" dtd-version="3.0" xml:lang="en" article-type="short-communications-source-code">
  <front>
    <journal-meta>
      <journal-id journal-id-type="publisher-id">IJMEBAC</journal-id>
      <journal-title-group>
        <journal-title>International Journal of Mathematical, Engineering, Biological and Applied Computing</journal-title>
      </journal-title-group>
      <issn pub-type="epub">2832-5273</issn>
      <issn pub-type="ppub"></issn>
      <publisher>
        <publisher-name>Science Publications</publisher-name>
      </publisher>
    </journal-meta>
    <article-meta>
      <article-id pub-id-type="doi">10.31586/ijmebac.2022.448</article-id>
      <article-id pub-id-type="publisher-id">IJMEBAC-448</article-id>
      <article-categories>
        <subj-group subj-group-type="heading">
          <subject>Short Communications &amp; Source Code</subject>
        </subj-group>
      </article-categories>
      <title-group>
        <article-title>
          Check if a Graph is Bipartite or not &#x00026;#x26; Bipartite Graph Coloring using Java
        </article-title>
      </title-group>
      <contrib-group>
<contrib contrib-type="author">
<name>
<surname>Marappan</surname>
<given-names>Raja</given-names>
</name>
<xref rid="af1" ref-type="aff">1</xref>
<xref rid="cr1" ref-type="corresp">*</xref>
</contrib>
<contrib contrib-type="author">
<name>
<surname>Raja</surname>
<given-names>Sarveshvara</given-names>
</name>
<xref rid="af2" ref-type="aff">2</xref>
</contrib>
<contrib contrib-type="author">
<name>
<surname>Raja</surname>
<given-names>Shakthigaa</given-names>
</name>
<xref rid="af3" ref-type="aff">3</xref>
</contrib>
<contrib contrib-type="author">
<name>
<surname>Raja</surname>
<given-names>Saraswatikaniga</given-names>
</name>
<xref rid="af4" ref-type="aff">4</xref>
</contrib>
      </contrib-group>
<aff id="af1"><label>1</label> School of Computing, SASTRA Deemed University, Thanjavur, India</aff>
<aff id="af2"><label>2</label> Independent Researcher; raja.sarveshvara@gmail.com</aff>
<aff id="af3"><label>3</label> Independent Researcher; raja.shakthigaa@gmail.com</aff>
<aff id="af4"><label>4</label> Independent Researcher; r.saraswatikaniga@gmail.com</aff>
<author-notes>
<corresp id="c1">
<label>*</label>Corresponding author at: School of Computing, SASTRA Deemed University, Thanjavur, India
</corresp>
</author-notes>
      <pub-date pub-type="epub">
        <day>18</day>
        <month>09</month>
        <year>2022</year>
      </pub-date>
      <volume>1</volume>
      <issue>2</issue>
      <history>
        <date date-type="received">
          <day>18</day>
          <month>09</month>
          <year>2022</year>
        </date>
        <date date-type="rev-recd">
          <day>18</day>
          <month>09</month>
          <year>2022</year>
        </date>
        <date date-type="accepted">
          <day>18</day>
          <month>09</month>
          <year>2022</year>
        </date>
        <date date-type="pub">
          <day>18</day>
          <month>09</month>
          <year>2022</year>
        </date>
      </history>
      <permissions>
        <copyright-statement>&#xa9; Copyright 2022 by authors and Trend Research Publishing Inc. </copyright-statement>
        <copyright-year>2022</copyright-year>
        <license license-type="open-access" xlink:href="http://creativecommons.org/licenses/by/4.0/">
          <license-p>This work is licensed under the Creative Commons Attribution International License (CC BY). http://creativecommons.org/licenses/by/4.0/</license-p>
        </license>
      </permissions>
      <abstract>
        Nowadays, graphs including bigraphs are mostly used in various real-world applications such as search engines and social networks. The bigraph or bipartite graph is a graph whose vertex set is split into two disjoint vertex sets such that there is no edge between the same vertex set. The bipartite graphs are colored using only two colors. This article checks if a given graph is bipartite or not and finds the color assignments of the bipartite graph using Java implementation.
      </abstract>
      <kwd-group>
        <kwd-group><kwd>Bigraphs</kwd>
<kwd>Bipartite Graphs</kwd>
<kwd>Graph Coloring</kwd>
<kwd>Social Networks</kwd>
<kwd>Color Assignments</kwd>
<kwd>Vertex Coloring</kwd>
<kwd>Search Engines</kwd>
</kwd-group>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec1">
<title>Introduction</title><p>A bigraph or bipartite graph G is a graph whose vertex set V(G) can be partitioned into two disjoint vertex sets such that there is no edge between the same vertex set [
<xref ref-type="bibr" rid="R1">1</xref>,<xref ref-type="bibr" rid="R2">2</xref>]. These graphs are said to be 2-colorable graphs that can be colored using only two colors [
<xref ref-type="bibr" rid="R3">3</xref>]. This article checks if a given graph is bipartite or not using Java implementation. The complete bipartite graph or biclique is a graph in which every vertex in one set is incident with every vertex in the other set. The bipartite graph is shown inFigure <xref ref-type="fig" rid="figfigure 1"> figure 1</xref>. The complete bipartite graphs are shown in figures 2 and 3 [
<xref ref-type="bibr" rid="R4">4</xref>,<xref ref-type="bibr" rid="R5">5</xref>]. The bipartite graphs are applied in social networks and search engines. These graphs are also used to represent the binary relations between two object types [
<xref ref-type="bibr" rid="R6">6</xref>,<xref ref-type="bibr" rid="R7">7</xref>].</p>
<fig id="fig1">
<label>Figure 1</label>
<caption>
<p>Bipartite graph</p>
</caption>
<graphic xlink:href="448.fig.001" />
</fig><fig id="fig2">
<label>Figure 2</label>
<caption>
<p>Complete bipartite graph</p>
</caption>
<graphic xlink:href="448.fig.002" />
</fig><fig id="fig3">
<label>Figure 3</label>
<caption>
<p>Complete bipartite graphs</p>
</caption>
<graphic xlink:href="448.fig.003" />
</fig></sec><sec id="sec2">
<title>Implementation in Java</title><p>The java implementation to check if the given graph is bipartite or not is given below. The color assignment of the bipartite graph is also printed.</p>
<p></p>
<p>import java.util.*;</p>
<p>public class bipartiteCheck</p>
<p>{</p>
<p>    static List&lt;List&lt;Integer&gt;&gt; adjList;</p>
<p>    static void edgeAddition(int a, int b)</p>
<p>   {</p>
<p>    adjList.get(a).add(b);</p>
<p>    adjList.get(b).add(a);</p>
<p>   }</p>
<p>static boolean bipartiteCheckEx(int n)</p>
<p>{</p>
<p>// not colored &#x26;#x02013; &#x26;#x02018;n&#x26;#x02019;        </p>
<p>// colored blue &#x26;#x02013; &#x26;#x02018;b&#x26;#x02019;   </p>
<p>// colored yellow &#x26;#x02013; &#x26;#x02018;y&#x26;#x02019;</p>
<p>char colorAssignment[
] = new char[n];</p>
<p>for (int j = 0; j &lt; n; j++)</p>
<p>            colorAssignment[j] = 'n';</p>
<p>Queue&lt;Integer&gt; queue = new LinkedList&lt;&gt;();</p>
<p>queue.add(0);</p>
<p>colorAssignment[
] = 'b';</p>
<p>while (!queue.isEmpty())</p>
<p>{</p>
<p>int h = queue.poll();</p>
<p>char ch = colorAssignment[h];</p>
<p>for(int g : adjList.get(h))</p>
<p>{</p>
<p>   if(colorAssignment[g] == ch) return false;</p>
<p>   if(colorAssignment[g] == 'n')</p>
<p>  {</p>
<p>     if(ch == 'b')</p>
<p>                        colorAssignment[g] = 'y';</p>
<p>                    else </p>
<p>                        colorAssignment[g]  = 'b';</p>
<p>     queue.add(g);                         </p>
<p>                }</p>
<p>            }</p>
<p>        }</p>
<p> for (int j = 0; j &lt; n; j++)</p>
<p>           System.out.println("color["+j+"]="+colorAssignment[j]);</p>
<p> return true;</p>
<p> }</p>
<p> public static void main(String ax[
]){</p>
<p>        int n = 4;</p>
<p>        adjList = new ArrayList&lt;&gt;();</p>
<p>        for(int j = 0; j &lt; n; j++)</p>
<p>            adjList.add(new ArrayList&lt;&gt;());</p>
<p>        </p>
<p>        edgeAddition(0, 1);</p>
<p>        edgeAddition(0, 2);</p>
<p>        edgeAddition(0, 3);</p>
<p>        edgeAddition(1, 3);</p>
<p>        edgeAddition(2, 3);</p>
<p>        System.out.println("Graph 1");</p>
<p>        if(bipartiteCheckEx(n))</p>
<p>            System.out.println("Bipartite graph");</p>
<p>        else </p>
<p>            System.out.println("Not a bipartite graph");</p>
<p></p>
<p>        adjList = new ArrayList&lt;&gt;();</p>
<p>        for(int i = 0; i &lt; n; i++)</p>
<p>            adjList.add(new ArrayList&lt;&gt;());</p>
<p>        </p>
<p>        edgeAddition(0, 1);</p>
<p>        edgeAddition(0, 2);</p>
<p>        edgeAddition(1, 3);</p>
<p>        edgeAddition(2, 3);</p>
<p>        System.out.println("Graph 2");</p>
<p></p>
<p>        if(bipartiteCheckEx(n))</p>
<p>            System.out.println("Bipartite graph ");</p>
<p>        else </p>
<p>            System.out.println("Not a bipartite graph");</p>
<p>        </p>
<p>        n = 8;</p>
<p>        adjList = new ArrayList&lt;&gt;();</p>
<p>        for(int j = 0; j &lt; 8; j++)</p>
<p>            adjList.add(new ArrayList&lt;&gt;());</p>
<p>        </p>
<p>        edgeAddition(0, 1);</p>
<p>        edgeAddition(0, 2);</p>
<p>        edgeAddition(0, 4);</p>
<p>        edgeAddition(3, 1);</p>
<p>        edgeAddition(3, 2);</p>
<p>        edgeAddition(3, 7);</p>
<p>        edgeAddition(5, 1);</p>
<p>        edgeAddition(5, 4);</p>
<p>        edgeAddition(5, 7);</p>
<p>        edgeAddition(6, 2);</p>
<p>        edgeAddition(6, 4);</p>
<p>        edgeAddition(6, 7);   </p>
<p>        System.out.println("Graph 3");</p>
<p></p>
<p>        if(bipartiteCheckEx(n))</p>
<p>            System.out.println("Bipartite graph ");</p>
<p>        else </p>
<p>            System.out.println("Not a bipartite graph");</p>
<p>        n = 8;</p>
<p>        adjList = new ArrayList&lt;&gt;();</p>
<p>        for(int j = 0; j &lt; 8; j++)</p>
<p>            adjList.add(new ArrayList&lt;&gt;());</p>
<p>        </p>
<p>        edgeAddition(0, 1);</p>
<p>        edgeAddition(0, 2);</p>
<p>        edgeAddition(0, 4);</p>
<p>        edgeAddition(3, 1);</p>
<p>        edgeAddition(3, 2);</p>
<p>        edgeAddition(3, 7);</p>
<p>        edgeAddition(3, 5);</p>
<p>        edgeAddition(5, 1);</p>
<p>        edgeAddition(5, 4);</p>
<p>        edgeAddition(5, 7);</p>
<p>        edgeAddition(6, 2);</p>
<p>        edgeAddition(6, 4);</p>
<p>        edgeAddition(6, 7);   </p>
<p>        edgeAddition(1, 7);   </p>
<p>        System.out.println("Graph 4");</p>
<p></p>
<p>        if(bipartiteCheckEx(n))</p>
<p>            System.out.println("Bipartite graph ");</p>
<p>        else </p>
<p>            System.out.println("Not a bipartite graph");</p>
<p>        </p>
<p>        n = 8;</p>
<p>        adjList = new ArrayList&lt;&gt;();</p>
<p>        for(int j = 0; j &lt; 8; j++)</p>
<p>            adjList.add(new ArrayList&lt;&gt;());</p>
<p>        </p>
<p>        edgeAddition(0, 5);</p>
<p>        edgeAddition(0, 6);</p>
<p>        edgeAddition(0, 7);</p>
<p>        edgeAddition(1, 5);</p>
<p>        edgeAddition(1, 6);</p>
<p>        edgeAddition(1, 7);</p>
<p>        edgeAddition(2, 5);</p>
<p>        edgeAddition(2, 6);</p>
<p>        edgeAddition(2, 7);</p>
<p>        edgeAddition(3, 5);</p>
<p>        edgeAddition(3, 6);</p>
<p>        edgeAddition(3, 7);</p>
<p>        edgeAddition(4, 5);</p>
<p>        edgeAddition(4, 6);</p>
<p>        edgeAddition(4, 7);</p>
<p>        System.out.println("Graph 5");</p>
<p></p>
<p>        if(bipartiteCheckEx(n))</p>
<p>            System.out.println("Bipartite graph ");</p>
<p>        else </p>
<p>            System.out.println("Not a bipartite graph");</p>
<p>    }</p>
<p>}</p>
<p></p>
</sec><sec id="sec3">
<title>Results</title><p>The execution and the result of the Java program is shown inFigure <xref ref-type="fig" rid="figfigure 4"> figure 4</xref>. The graphs 1, 2, 3, 4 and 5 are given as the inputs and the results are shown in figures from 5 to 9 respectively. The program outputs the color assignments of the bipartite graphs.</p>
<fig id="fig4">
<label>Figure 4</label>
<caption>
<p>Execution &#x00026; result of the Java code</p>
</caption>
<graphic xlink:href="448.fig.004" />
</fig><fig id="fig5">
<label>Figure 5</label>
<caption>
<p>Graph 1 (Not a bipartite graph)</p>
</caption>
<graphic xlink:href="448.fig.005" />
</fig><fig id="fig6">
<label>Figure 6</label>
<caption>
<p>Graph 2 (Bipartite graph)</p>
</caption>
<graphic xlink:href="448.fig.006" />
</fig><fig id="fig7">
<label>Figure 7</label>
<caption>
<p>Graph 3 (Bipartite graph)</p>
</caption>
<graphic xlink:href="448.fig.007" />
</fig><fig id="fig8">
<label>Figure 8</label>
<caption>
<p>Graph 4 (Not a Bipartite graph)</p>
</caption>
<graphic xlink:href="448.fig.008" />
</fig><fig id="fig9">
<label>Figure 9</label>
<caption>
<p>(Bipartite graph)</p>
</caption>
<graphic xlink:href="448.fig.009" />
</fig><p></p>
<p></p>
<p></p>
</sec><sec id="sec4">
<title>Conclusions &#x00026;#x26; Future Work</title><p>This research presented the method to check if the given graph is bipartite or not. The color assignment of the bipartite graph is also obtained and the method is executed on some of the sample graphs and the results are presented. New strategies will be developed for bipartite graphs using the various soft computing methods [
<xref ref-type="bibr" rid="R8">8</xref>,<xref ref-type="bibr" rid="R9">9</xref>,<xref ref-type="bibr" rid="R10">10</xref>,<xref ref-type="bibr" rid="R11">11</xref>,<xref ref-type="bibr" rid="R12">12</xref>,<xref ref-type="bibr" rid="R13">13</xref>,<xref ref-type="bibr" rid="R14">14</xref>,<xref ref-type="bibr" rid="R15">15</xref>,<xref ref-type="bibr" rid="R16">16</xref>].</p>
</sec>
  </body>
  <back>
    <ref-list>
      <title>References</title>
      
<ref id="R1">
<label>[1]</label>
<mixed-citation publication-type="other">Lewis R.M.R.: A Guide to Graph Coloring, Algorithms and Applications. Springer International Publishing Switzerland (2016)
</mixed-citation>
</ref>
<ref id="R2">
<label>[2]</label>
<mixed-citation publication-type="other">Tommy R. Jensen, Bjarne Toft: Graph Coloring Problems. John Wiley &#x00026; Sons.
</mixed-citation>
</ref>
<ref id="R3">
<label>[3]</label>
<mixed-citation publication-type="other">Marappan, R., Sethumadhavan, G. Solution to Graph Coloring Using Genetic and Tabu Search Procedures. Arab J Sci Eng 43, 525-542 (2018). https://doi.org/10.1007/s13369-017-2686-9
</mixed-citation>
</ref>
<ref id="R4">
<label>[4]</label>
<mixed-citation publication-type="other">Marc Demange; T&#x00131;naz Ekim; Bernard Ries; Cerasela Tanasescu: On some applications of the selective graph coloring problem. European Journal of Operational Research (2014)
</mixed-citation>
</ref>
<ref id="R5">
<label>[5]</label>
<mixed-citation publication-type="other">G. Sethumadhavan and R. Marappan, "A genetic algorithm for graph coloring using single parent conflict gene crossover and mutation with conflict gene removal procedure," 2013 IEEE International Conference on Computational Intelligence and Computing Research, 2013, pp. 1-6, doi: 10.1109/ICCIC.2013.6724190.
</mixed-citation>
</ref>
<ref id="R6">
<label>[6]</label>
<mixed-citation publication-type="other">Philippe Galinier; Alain Hertz: A survey of local search methods for graph coloring. Computers &#x00026; Operations Research 33(9), 2547-2562 (2006)
</mixed-citation>
</ref>
<ref id="R7">
<label>[7]</label>
<mixed-citation publication-type="other">Marappan, R.; Sethumadhavan, G. Complexity Analysis and Stochastic Convergence of Some Well-known Evolutionary Operators for Solving Graph Coloring Problem. Mathematics 2020, 8, 303. https://doi.org/10.3390/math8030303
</mixed-citation>
</ref>
<ref id="R8">
<label>[8]</label>
<mixed-citation publication-type="other">R. Marappan and G. Sethumadhavan, "A New Genetic Algorithm for Graph Coloring," 2013 Fifth International Confer-ence on Computational Intelligence, Modelling and Simulation, 2013, pp. 49-54, doi: 10.1109/CIMSim.2013.17.
</mixed-citation>
</ref>
<ref id="R9">
<label>[9]</label>
<mixed-citation publication-type="other">Sanjukta Bhowmick; Paul D. Hovland, Improving the Performance of Graph Coloring Algorithms through Backtracking, ICCS 2008, Part I, LNCS 5101, pp. 873-882, 2008.
</mixed-citation>
</ref>
<ref id="R10">
<label>[10]</label>
<mixed-citation publication-type="other">Henning Hasemann, Juho Hirvonen, Joel Rybicki, and Jukka Suomela, Deterministic Local Algorithms, Unique Identifi-ers, and Fractional Graph Colouring, Springer-Verlag Berlin Heidelberg, pp. 48-60, 2012.
</mixed-citation>
</ref>
<ref id="R11">
<label>[11]</label>
<mixed-citation publication-type="other">S. Balakrishnan, T. Suresh and R. Marappan, "Solving Graph Coloring Problem Using New Greedy and Probabilistic Method," 2022 8th International Conference on Advanced Computing and Communication Systems (ICACCS), 2022, pp. 1992-1995, doi: 10.1109/ICACCS54159.2022.9785139.
</mixed-citation>
</ref>
<ref id="R12">
<label>[12]</label>
<mixed-citation publication-type="other">Wen Sun, Jin-Kao Hao, Yuhao Zang, Xiangjing Lai, A solution-driven multilevel approach for graph coloring, Applied Soft Computing, Volume 104, 2021, 107174, https://doi.org/10.1016/j.asoc.2021.107174.
</mixed-citation>
</ref>
<ref id="R13">
<label>[13]</label>
<mixed-citation publication-type="other">Marappan, R., Bhaskaran, S. New evolutionary operators in coloring DIMACS challenge benchmark graphs. Int. j. inf. tecnol. (2022). DOI: https://doi.org/10.1007/s41870-022-01057-x
</mixed-citation>
</ref>
<ref id="R14">
<label>[14]</label>
<mixed-citation publication-type="other">Donatello Conte, Giuliano Grossi, Raffaella Lanzarotti, Jianyi Lin, Alessandro Petrini: Analysis of a parallel MCMC algo-rithm for graph coloring with nearly uniform balancing, Pattern Recognition Letters, Volume 149, 2021, Pages 30-36, https://doi.org/10.1016/j.patrec.2021.05.014.
</mixed-citation>
</ref>
<ref id="R15">
<label>[15]</label>
<mixed-citation publication-type="other">Angelini P.; Bekos M. A.; De Luca F.; Didimo W.; Kaufmann M.; Kobourov S.; Montecchiani F.; Raftopoulou C. N.; Ro-selli V.; Symvonis A.: Vertex-Coloring with Defects. Journal of Graph Algorithms and Applications (2017)
</mixed-citation>
</ref>
<ref id="R16">
<label>[16]</label>
<mixed-citation publication-type="other">Sennaiyan, B., &#x00026; Suresh, T. (2022). Graph Coloring on Bipartite Graphs. International Journal of Mathematical, Engi-neering, Biological and Applied Computing, 1(2), 56-60.
</mixed-citation>
</ref>
    </ref-list>
  </back>
</article>