In the given java code, below, help with the two methods. public boolean connected() and public Graph kruskalMST() ? import java.util.*; public class Graph {                                 static class Vertex implements Comparable {                                                                 int value;                                                                 Vertex(int val) {                                                 value = val;                                 }                                   public String toString() {                                                 return Integer.toString(value);                                 }                                                                 //This is not a great hashCode                                 public int hashCode() {                                                 return value;                                 }                                   //Compare vertices                                 public boolean equals(Object o) {                                                 Vertex v = (Vertex)o;                                                 return compareTo(v)==0;                                                                                 }                                                                 public int compareTo(Vertex v) {                                                 return value - v.value;                                 }                                                 }                                 static class Edge {                                 Vertex from, to;                                 int weight;                                   public Edge(Vertex from, Vertex to, int weight) {                                                                                 this.from = from;                                                 this.to = to;                                                 this.weight = weight;                                 }                                                                 public Edge(Vertex from, Vertex to) {                                                 this.from = from;                                                 this.to = to;                                                 this.weight = 1;                                 }                                   public String toString() {                                                 return "(" + from + "<->" + to + ", " + weight + ")";                                 }                                                 }                                 static class DisjointSet {                                 Map source = new HashMap<>();                                                                 public DisjointSet(Set vertices) {                                                 for(Vertex v: vertices)                                                                 source.put(v,v);                                 }                                                                 // Find the root of the set in which Vertex v belongs.                     private Vertex find(Vertex v)                     {                         //Vertex v is the root                         if (source.get(v).equals(v)) {                             return v;                         }                                           //recurse until we find the root                         return find(source.get(v));                     }                                       //merge the two sets                     private void union(Vertex u, Vertex v)                     {                         //find the root of the sets in which Vertex u and Vertex v belong                         Vertex x = find(u);                         Vertex y = find(v);                                           source.put(x, y); //now x and y have the same root                     }                                                 }                                 TreeSet vertices;                 ArrayList edges;                                 public Graph(TreeSet vertices, ArrayList edges) {                                 this.vertices = vertices;                                 this.edges = edges;                 }                                   public boolean connected() {                                 return false;                                                     }                                 public Graph kruskalMST(){         //use this to sort the edges                                 Comparator compareWeights = (Edge e1, Edge e2) -> e1.weight-e2.weight;                                   return new Graph(vertices,edges)                                                 }   }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

In the given java code, below, help with the two methods. public boolean connected() and public Graph kruskalMST() ?

import java.util.*;

public class Graph {

               

                static class Vertex implements Comparable<Vertex> {

                               

                                int value;

                               

                                Vertex(int val) {

                                                value = val;

                                }

 

                                public String toString() {

                                                return Integer.toString(value);

                                }

                               

                                //This is not a great hashCode

                                public int hashCode() {

                                                return value;

                                }

 

                                //Compare vertices

                                public boolean equals(Object o) {

                                                Vertex v = (Vertex)o;

                                                return compareTo(v)==0;

                                               

                                }

                               

                                public int compareTo(Vertex v) {

                                                return value - v.value;

                                }

                               

                }

               

                static class Edge {

                                Vertex from, to;

                                int weight;

 

                                public Edge(Vertex from, Vertex to, int weight) {

                               

                                                this.from = from;

                                                this.to = to;

                                                this.weight = weight;

                                }

                               

                                public Edge(Vertex from, Vertex to) {

                                                this.from = from;

                                                this.to = to;

                                                this.weight = 1;

                                }

 

                                public String toString() {

                                                return "(" + from + "<->" + to + ", " + weight + ")";

                                }

                               

                }

               

                static class DisjointSet {

                                Map<Vertex,Vertex> source = new HashMap<>();

                               

                                public DisjointSet(Set<Vertex> vertices) {

                                                for(Vertex v: vertices)

                                                                source.put(v,v);

                                }

                               

                                // Find the root of the set in which Vertex v belongs.

                    private Vertex find(Vertex v)

                    {

                        //Vertex v is the root

                        if (source.get(v).equals(v)) {

                            return v;

                        }

                 

                        //recurse until we find the root

                        return find(source.get(v));

                    }

                 

                    //merge the two sets

                    private void union(Vertex u, Vertex v)

                    {

                        //find the root of the sets in which Vertex u and Vertex v belong

                        Vertex x = find(u);

                        Vertex y = find(v);

                 

                        source.put(x, y); //now x and y have the same root

                    }

                               

                }

               

                TreeSet<Vertex> vertices;

                ArrayList<Edge> edges;

               

                public Graph(TreeSet<Vertex> vertices, ArrayList<Edge> edges) {

                                this.vertices = vertices;

                                this.edges = edges;

                }

               

 

                public boolean connected() {

                                return false;

 

 

                               

                }

               

                public Graph kruskalMST(){

        //use this to sort the edges

                                Comparator<Edge> compareWeights = (Edge e1, Edge e2) -> e1.weight-e2.weight;

 

                                return new Graph(vertices,edges)

                               

                }

 

}

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

can you help with driver test code?

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Generic Type
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education