Show the output of the following code:
public class Test {
public static void main(String[] args) {
WeightedGraph<Character> graph = new WeightedGraph<>();
graph.addVertex(‘U’);
graph.addVertex(‘V’);
graph.addVertex(‘X’);
int indexForU = graph.getIndex(‘U’);
int indexForV = graph.getIndex(‘V’);
int indexForX = graph.getlndex(’X’);
System.out.println(“indexForU is ” + indexForU);
System.out.println(“indexForV is ” + indexForV);
System.out.println(“indexForX is ” + indexForV);
graph.addEdge(indexForU, indexForV, 3.5);
graph.addEdge(indexForV, indexForU, 3.5);
graph.addEdge(indexForU, indexForX, 2.1);
graph.addEdge(indexForX, indexForU, 2.1);
graph.addEdge(indexForV, indexForX, 3.1);
graph.addEdge(indexForX, indexForV, 3.1);
WeightedGraph<Character>.MST mst
= graph.getMinimumSpanningTree();
graph.printWeightedEdges();
System.out.println(mst.getTotalWeight{));
mst.printTree();
}
}
Want to see the full answer?
Check out a sample textbook solutionChapter 29 Solutions
Instructor Solutions Manual For Introduction To Java Programming And Data Structures, Comprehensive Version, 11th Edition
Additional Engineering Textbook Solutions
Starting Out with C++: Early Objects
Starting Out with Python (3rd Edition)
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Computer Science: An Overview (12th Edition)
Artificial Intelligence: A Modern Approach
- class Solution(object): def longestCommonPrefix(self, strs): result ="" for i in strs[0]: for j in strs[1]: for k in strs[2]: if i == j and i == k: result+=i if len(result) >0: return result else: return result IndexError: list index out of range for j in strs[1]: Line 5 in longestCommonPrefix (Solution.py) ret = Solution().longestCommonPrefix(param_1) Line 31 in _driver (Solution.py) _driver() Line 41 in <module> (Solution.py) can someone explain why this is wrong?arrow_forwardclass WaterSort { Character top = null; // create constants for colors static Character red= new Character('r'); static Character blue = new Character('b'); static Character yellow= new Character('g'); // Bottles declaration public static void showAll( StackAsMyArrayList bottles[]) { for (int i = 0; i<=4; i++) { System.out.println("Bottle "+ i+ ": " + bottles[i]); } } public static void main(String args[]) { //part 1 //create the bottle StackAsMyArrayList bottleONE = new StackAsMyArrayList<Character>(); System.out.println("\nbottleONE:"+ bottleONE+ " size:" + bottleONE.getStackSize()+" uniform? "+ bottleONE.checkStackUniform());…arrow_forwardComputer Science java programarrow_forward
- public class Geometry{public static void main(String[] args){//asks for user's choice Scanner in = new Scanner(System.in);displayMenu();selectOption(choice);System.out.println("Enter your choice (1-3): ");int choice1 = in.nextInt();System.out.println("Thanks for using the Geometry Calculator - Goodbye!");//Prints if input is a number that is not one of the choiceswhile(choice1 < 1 || choice1 > 3 ){System.out.println("Invalid choice. Please enter 1 - 3: ");choice1 = in.nextInt();}}/**Displays the menu*/public static void displayMenu(){System.out.println("Welcome to the Geometry Calculator Application");System.out.println("1. Calculate the Area of a Circle");System.out.println("2. Calculate the Area of a Rectangle");System.out.println("3. Calculate the Area of a Triangle");}/** This method calculates the area of the circle@return the area of the circle*/public static double circle()// calculates the area of the circle{Scanner in = new Scanner(System.in);System.out.println("What is…arrow_forwardpublic class GameList {Game head;public GameList() {head = null;}public void addFront(String n, int min) {Game g = new Game(n, min);g.next = head;head = g;}} Add a tail pointerarrow_forwardclass TenNums {private: int *p; public: TenNums() { p = new int[10]; for (int i = 0; i < 10; i++) p[i] = i; } void display() { for (int i = 0; i < 10; i++) cout << p[i] << " "; }};int main() { TenNums a; a.display(); TenNums b = a; b.display(); return 0;} Write a copy constructor for the above class TenNums. Make sure it performs deep copy. Group of answer choices TenNums(const TenNums& b) { p = b.p;} TenNums(const TenNums& b) { p = new int[10]; for (int i = 0; i < 10; i++) p[i] = b.p[i];} TenNums(const TenNums b) { p = new int[10]; for (int i = 0; i < 10; i++) p[i] = b.p[i];} TenNums(const TenNums b) { p = b.p;}arrow_forward
- class TenNums {private: int *p; public: TenNums() { p = new int[10]; for (int i = 0; i < 10; i++) p[i] = i; } void display() { for (int i = 0; i < 10; i++) cout << p[i] << " "; }};int main() { TenNums a; a.display(); TenNums b = a; b.display(); return 0;} Continuing from Question 4, let's say I added the following overloaded operator method to the class. Which statement will invoke this method? TenNums TenNums::operator+(const TenNums& b) { TenNums o; for (int i = 0; i < 10; i++) o.p[i] = p[i] + b.p [i]; return o;} Group of answer choices TenNums a; TenNums b = a; TenNums c = a + b; TenNums c = a.add(b);arrow_forwardCourse: Data Structure and Algorithims Language: Java Kindly make the program in 2 hours. Task is well explained. You have to make the proogram properly in Java and attach output screen with program: Restriction: Prototype cannot be change you have to make program by using given prototype. TAsk: classBSTNode { Node left; Node right; int data; publicBSTNode(int _data);// assign data to_data and assign left and right node to null } class BST { BSTNoderoot; public BST();// assign root to null void insert(int data);// this function insert the data in tree which maintain property of BST boolean Search(int key); this function search the data in bst and return true if key is found else return false public void EvenPrint(Node n)// this function only print the data which are even, make this function resursive public void OddPrint(Node n)// this function only print the data which are odd, make this function resursive public void PrimePrint(Node n)// this function only…arrow_forwardpackage ch08.apps;import ch08.maps.*; public class HMapDriver { public static void main(String[] args) { boolean result; HMap<String, String> test; test = new HMap<String, String>(10,0.75); /*String s = null;test.put(s,"value");test.put("s",null);System.out.println("Expect 'null':\t" + test.get("s"));System.out.println("Expect 'true':\t" + test.contains("s"));test = new ArrayListMap<String, String>();*/ System.out.println("Expect 'true':\t" + test.isEmpty()); System.out.println("Expect '0':\t" + test.size()); System.out.println("Expect 'null':\t" + test.put("1", "One")); System.out.println("Expect 'false':\t" + test.isEmpty()); System.out.println("Expect '1':\t" + test.size()); System.out.println("Expect 'One':\t" + test.put("1", "One")); System.out.println("Expect 'false':\t" + test.isEmpty()); System.out.println("Expect '1':\t" + test.size()); test.put("2", "Two"); test.put("3", "Three");…arrow_forward
- the code: class HighArray { private long[] a; private int nElems; public HighArray(int max) { a = new long[max]; nElems = 0; } public void insert(long value) { a[nElems] = value; nElems++; } public boolean find(long searchKey) { int j; for (j = 0; j < nElems; j++) if (a[j] == searchKey) break; if (j == nElems) return false; else return true; } public long getMax() { if (nElems == 0) return 01; else { long max = a[0]; for (int i = 1; i < nElems; i++) { if (a[i] > max) max = a[i]; } return max; } } public boolean delete(long value) { int j; for (j = 0; j < nElems; j++) if (value == a[j]) break; if (j == nElems) return false; else { for (int k = j; k < nElems; k++) a[k] = a[k + 1]; nElems--; return true; } } public void display() { for (int j = 0; j < nElems; j++) System.out.print(a[j] + " "); System.out.println(""); }} public class HighArrayApp { public static void main(String[] args) { int maxSize =…arrow_forwardFirst snippet public static void main(String[] args) { Dog aDog = new Dog("Max"); Dog oldDog = aDog; // we pass the object to foo foo(aDog); // aDog variable is still pointing to the "Max" dog when foo(...) returns aDog.getName().equals("Max"); // true aDog.getName().equals("Fifi"); // false aDog == oldDog; // true } public static void foo(Dog d) { d.getName().equals("Max"); // true // change d inside of foo() to point to a new Dog instance "Fifi" d = new Dog("Fifi"); d.getName().equals("Fifi"); // true } Second snippt public static void main(String[] args) { Dog aDog = new Dog("Max"); Dog oldDog = aDog; foo(aDog); // when foo(...) returns, the name of the dog has been changed to "Fifi" aDog.getName().equals("Fifi"); // true // but it is still the same dog: aDog == oldDog; // true } public static void foo(Dog d) { d.getName().equals("Max"); // true // this changes the name of d to be "Fifi" d.setName("Fifi"); } What is the difference between the first code snippet and the second?…arrow_forwardAssume Student and GradeBook classes are defined as follows: public class Student { int id; double testsMarks[]; public double getAverage(){ double sum = 0; for(double marks : testsMarks) { sum+=marks; } return sum/testsMarks.length; } } import java.util.ArrayList; public class GradeBook { String subject; ArrayList<Student> students; public Student getStudentWithMinAverage(){ } } Define the body of getStudentWithMinAverage method that shall return the student object from students ArrayList who got minimum average marks in the class. (Please write minimum code and make use of provided code, making no change in classes' structure)arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education