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’);
int indexForU = graph.get Index(‘U’);
int indexForV = graph.get Index(‘V’);
System.out.println(“indexForU is ” + indexForU);
System.out.println(“indexForV is ” + indexForV);
graph.addEdge(indexForU, indexForV, 2.5);
System.out.println(“Degree of U is ” +
graph.getDegree(indexForU));
System.out.println(“Degree of V is ” +
graph.getDegree(indexForV));
System.out.println(“Weight of UV is ” +
graph.getWeight(indexForU, index0fV));
}
}
Want to see the full answer?
Check out a sample textbook solutionChapter 29 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Additional Engineering Textbook Solutions
Problem Solving with C++ (10th Edition)
Programming in C
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Starting Out With Visual Basic (7th Edition)
Digital Fundamentals (11th Edition)
C Programming Language
- I need help with my Optimizing the intermediate code to improve the efficiency of the generated machine code. I need to improve the effixiency of the generated machine code import java.util.*; public class SimpleCalculator { private final String input; private int position; private boolean hasDivByZero = false; private Map<String, String> symbolTable; private List<String> instructions; public SimpleCalculator(String input) { this.input = input; this.position = 0; this.symbolTable = new HashMap<>(); this.instructions = new ArrayList<>(); } public static void main(String[] args) { SimpleCalculator calculator = new SimpleCalculator("3 + 5 * (2 - 1)"); calculator.parseExpression(); if (calculator.hasDivByZero) { System.out.println("Error: division by zero"); } else { System.out.println("Result: " + calculator.instructions); } } public void parseExpression() { String t1 = parseTerm(); while (true) { String op = null; if (consume('+')) { op = "+"; } else if…arrow_forwardIn java, Implement a method that removes all duplicates. Keep the first instance of the element but remove all subsequent duplicate elements.public void removeDuplicates() see the picture for the right output. Given files: Demo6.java public class Demo6 { public static void main(String[] args) { MyLinkedList<String> list = new MyLinkedList<>(); TestBench.addToList(list); TestBench.addToList(list); TestBench.addToList(list); TestBench.addToList(list); for (int x = 0; x < list.size(); x += 1 + x/3) { System.out.println("Removing element at index: " + x); list.remove(x); } System.out.println("Result"); System.out.println(list); System.out.println("Shuffling"); list.shuffle(7777); System.out.println(list); System.out.println("Removing duplicates (keeping first instance)"); list.removeDuplicates(); System.out.println(list); }} TestBench.java import java.util.AbstractList; public class TestBench { public static…arrow_forwardWe were given the following code to solve a Pentomino puzzle, several methods might need to be added or editted to solve the problem. The program should take in an input of 3 4 5 6 for 3x20 4x15 5x12 6x10 grids. Then output the number of correct solutions for them (respectively its 2, 368, 1010, and 2339) import java.util.ArrayList;import java.util.LinkedList;import java.util.List; public class DLX { class DataNode { DataNode L, R, U, D; ColumnNode C; public DataNode() { L = R = U = D = this; } public DataNode(ColumnNode c) { this(); C = c; } DataNode linkDown(DataNode node) { node.D = this.D; node.D.U = node; node.U = this; this.D = node; return node; } DataNode linkRight(DataNode node) { node.R = this.R; node.R.L = node; node.L = this; this.R = node; return node;…arrow_forward
- Create a Graph test client that reads a graph from the command-line parameter input stream and outputs it using function toString() { [native code] } ()arrow_forwardmake this code runableInt main(void)//Input array containing edges of the graph//(X,Y,W)tuple represents an edge from 'x' to y' having weight w'struct Edge edges I= {0,1,4.).(1,2,4).(2,0,4),(2,1,4)int n=size of (edges)/size of (edges|0]);struct Graph *graph=createGraph(edges,n);return 0; static int minsum=100000;static voidgetMinPathSum(Dictionary<int,ArrayList>graph,bool[visited,ArrayLinecessary,int source,int dest,int currsum)if(src==dest) bool flag=true;for each(int i in necessary)if(!visitedi])flag=false;break: if (flag )minsum=Math. Min(minsum,currsum);return;elselvisited[src]=true;for(auto node:graph[src]) if (Ivisited[node.first])visited [node.first])=true;getMinPathSum(graph, visited,necessary,node.first,dest,currsum+node.second);visited [node.first]=false;arrow_forwardAdd comments to the code and display outputInt main(void)//Input array containing edges of the graph//(X,Y,W)tuple represents an edge from 'x' to y' having weight w'struct Edge edges I= {0,1,4.).(1,2,4).(2,0,4),(2,1,4)int n=size of (edges)/size of (edges|0]);struct Graph *graph=createGraph(edges,n);return 0; static int minsum=100000;static voidgetMinPathSum(Dictionary<int,ArrayList>graph,bool[visited,ArrayLinecessary,int source,int dest,int currsum)if(src==dest) bool flag=true;for each(int i in necessary)if(!visitedi])flag=false;break: if (flag )minsum=Math. Min(minsum,currsum);return;elselvisited[src]=true;for(auto node:graph[src]) if (Ivisited[node.first])visited [node.first])=true;getMinPathSum(graph, visited,necessary,node.first,dest,currsum+node.second);visited [node.first]=false;arrow_forward
- Write a program that outputs the nodes of a graph in a breadth first traversal. in c ++ 10 0 1 3 -9991 4 -9992 5 -9993 2 -9994 -9995 7 8 -9996 4 7 -9997 -9998 -9999 7 8 -999 #include <iostream> #include <fstream> #include <iomanip> #include <cassert> using namespace std; template <class Type> struct nodeType { Type info; nodeType<Type> *link; }; template <class Type> class linkedListIterator { public: linkedListIterator() { current = nullptr; } linkedListIterator(nodeType<Type> *ptr) { current = ptr; } Type operator*() { return current->info; } linkedListIterator<Type> operator++() { current = current->link; return *this; } bool operator==(const linkedListIterator<Type>& right) const { return (current == right.current); } bool operator!=(const linkedListIterator<Type>& right) const { return (current != right.current); } private: nodeType<Type> *current; }; template <class Type> class…arrow_forwardComplete the method to perform breadth first traversal (search) here is the method: private static void breadthFirst() { //Todo System.out.println("test"); }here is the complete source code: Graph.java---------------------------------package finlab;import java.util.*;public class Graph { List<Edge>[] list; public Graph(int n){ list = new LinkedList[n]; for(int i=0; i<list.length;i++){ list[i] = new LinkedList<>(); } } void addEdge(int u, int v, int w){ list[u].add(0,new Edge(v,w)); } boolean isConnected(int u, int v){ for(Edge e: list[u]) { if (e.v == v) return true; } return false; } @Override public String toString(){ String result= ""; for(int i=0; i<list.length; i++){ result+= i+": "+list[i]+"\n"; } return result; }}Edge.java--------------------------------------------------------package…arrow_forwardI need a test harness for the following code: LinkedListImpl.java package linkedList; public abstract class LinkedListImpl implements LinkedList { private ListItem firstItem; public LinkedListImpl() { this.firstItem = null; } @Override public Boolean isItemInList(String thisItem) { ListItem currentItem = firstItem; while (currentItem != null) { if (currentItem.data.equals(thisItem)) { return true; } currentItem = currentItem.next; } return false; } @Override public Boolean addItem(String thisItem) { if (isItemInList(thisItem)) { return false; } else { ListItem newItem = new ListItem(thisItem); if (firstItem == null) { firstItem = newItem; } else { ListItem currentItem = firstItem; while (currentItem.next != null) { currentItem = currentItem.next; } currentItem.next = newItem; } return true; } } @Override public Integer itemCount() { Integer count = 0; ListItem currentItem = firstItem; while (currentItem != null) { count++; currentItem = currentItem.next; } return count; }…arrow_forward
- you get setup to work with graphs.Create a Graph class to store nodes and edges or download a Graph librarysuch as JUNG. Use it to implement Breadth First Search and Depth First SearchFollow the video from class if you need a reference.arrow_forwardHere is the code to create a graph in Python: G2 = nx.gnp_random_graph(10, 0.1, seed=1234)nx.draw(G2, with_labels=True)arrow_forwardAdd unit testing to the textanalyzer class. Please perform this task using JUnit. import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; import java.io.*; public class TextAnalyzer { public static void main(String[] args) throws Exception { String Word; URL poem = new URL("https://www.gutenberg.org/files/1065/1065-h/1065-h.htm"); BufferedReader in = new BufferedReader( new InputStreamReader(poem.openStream())); Map map = new HashMap(); while ((Word = in.readLine()) != null) { String[] words = Word.split("[\\s.;,?:!()\"]+"); for (String word : words) { word = word.trim(); if (word.length() > 0) { if (map.containsKey(word)) { map.put(word, map.get(word) + 1); } else { map.put(word, (int) 1L); } } } } // retrieving the map contents Set> set = map.entrySet(); // make an array list List> sortedList = new…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