Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(USING TEXTBOOK INTRODUCTION TO JAVA PROGRAMMING 10TH EDITION; PROBLEM 28.9) (Ge

ID: 3575011 • Letter: #

Question

(USING TEXTBOOK INTRODUCTION TO JAVA PROGRAMMING 10TH EDITION; PROBLEM 28.9)

(Get Bipartite sets):

Recall that a graph is Bipartite if its vertices can be divided into two disjoint sets such that no edges exit between vertices in the same set.

Add a new method in AbstractGraph with the following header toreturn two Bipartite sets if the graph is Bipartite:

public List<List<Integer>> getBipartite();

The method should return a List that contains two sublists, each of which contains a set of vertices. If the graphis not bipartite, the method returns null.

Explanation / Answer

#inlcude<stdio.h>

#define v

bool isBipartite(in g[][v] , int src)

{

int colorArr[v];

for(int i =0 ;i<v;i++)

colorArr[i] = -1;

colorArr[src] = 1;

queue<int> q;

q.push(src);

while(!q.empty())

{

int u=q.front();

q.pop();

for(int v =0;v<V;++v)

{

if(G[u][v] && colorArr[v ]== -1)

{

colorArr[v] = 1 - colorArr[u];

q.push(v);

}

else if(G[u][v] && colorArr[v] == colorArr[u])

returm false;

}

return true;

}

int main()

{

int G[][V] = {{0,2,1,2,},{1,1,1,0},{0,1,0,0}};

if(isBipartite(G,0))

{

printf("yes");

}

else{

bipartiteGraph[allelements_List] := Module{ G1,E1,C1,C2,CC,vert},

G1= Graph[

MapThread[

undirectedEdge,{sort[allelements][[all, 1]],

Sort[elements][[all,2]]}]];

E1=vertexlist[G1];

C1 = Transpose[ { select[E],integer q],

Table[{0,j},{j, 1 , 0 ,-1/(Length[select[E1 , integer Q]] -1)}]}

C2 = Transpose[{complement[E1, select [E1 , Integer Q]],Table[{1,j},{j,1,0,-1/Length[Complement[e1,Select[E1,Integer Q]]] - 1)}]}];

CCC=join[C1,C2];

vrt = CCC[[[Table[Position[CCC , E1[[i]]] , {i,length[CCC]}][all , 1, 1]],2]];

Graph[MapThread[

UndirectedEdge, {Sort[elements][[all, 1]],

Sort[allelements][[all,2]]},vertexcord -->G[][V],

VertexLabels --> "Name" , VertexLabelstyle -->16,Imagepadding -->20]