Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Graph data structure use. Assume you have a data structure, SimpleGraphen>, that implements a simple undirected araon interface and an implementation of the Vertex
Graph data structure use. Assume you have a data structure, SimpleGraphen>, that implements a simple undirected araon interface and an implementation of the Vertex interface (Vertex ), both shown public interface GraphInterface { public boolean adVertex (T vertexLabel); public boolean addEdge (I begin, Public boolean addEdge (T begin, end; public boolean hasEdge (T begin, T end); public boolean isEmpty (): public in getNumberOfVertices0): Public int getNumberOfEdges (); Public vola clear): public VertexInterface I end. double edge weight); getVertex (T label): public public interface VertexInterface getNieghborIterator0): (a) Draw the state of the graph here, after the code below has finished running. Clearly indicate the vertex labels on each vertex and edges between vertices. GraphInterface simpletraph = new SimpleGraph(); Strinall vertices = ("A" "RI, "C", "D", "E"1: for (String S:vertices) { simpleGraph.add Vertex(s); } simpleGraph.addEdge("A", "B"): simpleGraph, addEdge ("B", "C"): simpleGraph. addEdge ("B", simpleGraph, addEdge ("D"."E"); simpleGraph. addEdge ("D","C")i (b)) Write code that will compute the degree (number of edges) of the vertex labeled "B". You do not need to have a method signature, just the code that answers this question. 3. Dictionary application. (20 points) Write a method called printLetterFrequencies that will take as input a String array with words of uniform length (e.g. all 5-letter words) and print out the most commonly occurring letter at each position, and how many times it appeared at that position across all words in the array. For example, for this array: [ "the" "ton" "ten" ] The printed output should be: Pos 0: t, 3 Pos 1: h, 1 Pos 2: n, 2 In positions where there are ties, any of the letters with the maximum frequency can be printed. For example, in the case above, "h", "o", or "e" would all be valid outputs for Pos 1. Your code can assume the input is valid (e.g. all strings in the input array have the same length and the input is not empty). To receive full credit, you must use a Dictionary to solve this problem. Recall that one of the implementations of Dictionaries (also called "Maps") in Java is HashMap, which implements the Map interface. As a reminder, the Map interface provides the following methods that may be useful for you. Note that K and v below represent the types of your keys and values. public interface Map V put (K key, V value) This associates the given value with the given key. If the key is already in the map, then its old value will be replaced and returned. boolean contains Key (K key) - This determines whether or not the given key is in the map. - V get (K key) - If the key is in the map, then it returns its associated value. If the key is not in the map, then it returns null. Set keySet () Returns a Set of the keys contained in the map void clear () - Removes all key-value pairs from the map As a reminder, you may also find these Java String methods useful: length ()- Returns the number of characters in the string charAt(int index) Returns the char value at the specified index Your method signature should be: public static void print Letter Frequencies (String[] inputWords)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started