Graph data structure use. Assume you have a data structure, SimpleGraphen>, that implements a simple undirected...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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) 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)
Expert Answer:
Related Book For
Computer Architecture A Quantitative Approach
ISBN: 978-0123704900
4th edition
Authors: John L. Hennessy, David A. Patterson
Posted Date:
Students also viewed these programming questions
-
In this question assume that p and q are atomic formulae. (a) Compare and contrast path formulae and state formulae in temporal logic. [4 marks] (b) Describe and contrast the meanings of F(G p) and...
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
What minimum force f , applied horizontally to the wheel axis, is needed to bring the wheel up to the height step h ? Tomer as the wheel radius and w as its weight. Tip: apply the equilibrium...
-
A stratified simple random sample was taken with the following results. a. Develop an estimate of the population mean for each stratum. b. Develop an approximate 95% confidence interval for the...
-
What are the key considerations for mortgage lenders in assessing borrower creditworthiness and determining optimal loan-to-value (LTV) ratios, debt-to-income (DTI) ratios, and other risk factors in...
-
Information from Goddard Picture Frames cash account as well as the January bank statement is presented next. Requirements 1. Prepare the bank reconciliation on January 31. 2. Prepare all necessary...
-
Use the information from the Crystal Cruiseline Data Set to compute the number of dinner cruise tickets it must sell to breakeven and the sales dollars needed to breakeven. Crystal Cruiseline Data...
-
In its first year of operations as a retailer, Sheridan Ltd. reported the following information: Gross profit $180800 Purchases 224200 Sales returns and allowances 23900 Ending inventory 88900 What...
-
The irreversible, first-order reaction of gaseous A B occurs in spherical catalyst pellets with a radius of 2 mm. For this problem, the molecular diffusivity of A is 1.2 X 10 1 cm 2 /s and the...
-
Customer based inventory management strategies allow for the use of different availability levels for specific customers. What is the rationales for this approach?
-
The following three data points are given: Xo = 1 x = 2 x = 3 These three data points are interpolated by using f(x) = x over the range 1 x 3. Find P(x=0) by using Lagrange interpolating method....
-
This question has three parts (2 points per part). Gavin Corporation has two divisions (A & B), whose managers are evaluated independently based, in part, upon their own division's net operating...
-
Deterministic optimal growth model. Let 1- 7 A representative individual solves subject to f(k) max c Jo 1-e-ak x fe-Pu(ci)dt k = f(ke) - ce (a) Write the appropriate Hamiltonian (b) State the...
-
Child Labor Laws in American History YouTube: https://www.youtube.com/watch?v=CTYkW5K2mn4&t=35s History of Labor in the US https://www.youtube.com/watch?v=MH6aPJucdV4 1. Watch and take notes during...
-
You work for ESKOM in South Africa as a manager. Critically discuss the action that managers must take when their organisation experiences failure. Use relevant examples to support your answer.
-
3. Poly(hexamethylene adipamide)or nylon 6,6"is a high mechanical strength polymer commonly used to make fibers for a range of applications, including textiles, carpeting, and molded parts. While...
-
Velshi Printers has contracts to complete weekly supplements required by fortysix customers. For the year 2018, manufacturing overhead cost estimates total $600,000 for an annual production capacity...
-
On August 24, 2005, three Web sites managed by the Gap-Gap.com, OldNavy.com, and BananaRepublic.com-were taken down for improvements [AP 2005]. These sites were virtually inaccessible for the next...
-
We will start by configuring a system to complete a sort in the least possible time, with no limits on how much we can spend. To get peak bandwidth from the sort, we have to make sure all the paths...
-
Assume that you will use simple parity protection in Exercises 6.24 through 6.27. Specifically, assume that you will be computing one parity block for each file in the file system. Further, assume...
-
The unadjusted trial balance of Innovative Computers Pty Ltd on 30 June 2025 is presented below. The following additional information is available. 1. The inventories as of 30 June 2025 were as...
-
The Z-spread of Bond A is 1.05% and the Z-spread of Bond B is 1.53%. All else equal, which statement best describes the relationship between the two bonds? A. Bond B is safer and will sell at a lower...
-
A four-year corporate bond with a 7% coupon has a Z-spread of 200 bps. Assume a flat yield curve with an interest rate for all maturities of 5% and annual compounding. The bond will most likely sell:...
Study smarter with the SolutionInn App