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) MUS

ID: 3575128 • Letter: #

Question

(USING TEXTBOOK INTRODUCTION TO JAVA PROGRAMMING 10TH EDITION; PROBLEM 28.9) MUST BE DONE IN JAVA

(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

import java.util.*; public abstract class AbstractGraph implements Graph { protected List vertices; // Store vertices protected List neighbors; // Adjacency lists /** Construct a graph from edges and vertices stored in arrays */ protected AbstractGraph(int[][] edges, V[] vertices) { this.vertices = new ArrayList(); for (int i = 0; i