(b) Design the largeToSmall method that, when given a HashMap M, returns a LinkedHashSet of String...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
(b) Design the largeToSmall method that, when given a HashMap<String, Integer> M, returns a LinkedHashSet of String values where the words are inserted into the set in order of decreasing count. Words that have the same count do not need to be inserted in any particular order. E.g., "is" may come before "world". You cannot sort M. Hint: create an array of size c (where c is the highest word count) where each element is a LinkedHashSet<String>. For every element e in M, add e to the set at index M[i], where i is the count of e in M. Then, append these sets in reverse order according to their index. We provide some pseudocode below. largeToSmall (M): // M is M.size(). c = Get Highest Count Word in M array [0.. c-1] for i in [0.. c-1]: array [i] = new LinkedHashSet<String>(); = for every key k in M: i M.get (k) array [i-1].add (k) = // Append all linkedhashsets in reverse order. return array [c-1] appended to array [c-2] appended to array [0] largeToSmall (wordCount (s)) -> ("world", "is", "the", "healthy", "hello", "it", "i", "certainly", "agree", "that", "1", "and", "not"} For this question you will work with a LinkedList<Integer> data structure and implement several static. Accordingly, you cannot use any LinkedList methods except .get, .add, and .size. You also cannot use any external methods from Arrays, Collections, or any other helper class. (a) Design the addLast method that, when given a LinkedList<Integer> / and an int v, returns a new LinkedList<Integer> with the same elements plus v added to the end of 1. (b) Design the set method that, when given a LinkedList<Integer> 1, an int v, and an index i, returns a new LinkedList<Integer> with the same elements, except that the element at index i is, instead, the value v. If i is less than zero or exceeds the length of 1, return null. (c) Design the toArray method that, when given a LinkedList<Integer> / of Integer, returns an array containing the values from 1. (d) Design the reverse method that, when given a LinkedList<Integer> 1, returns a new LinkedList<Integer> containing the elements of 1, but reversed. (b) Design the largeToSmall method that, when given a HashMap<String, Integer> M, returns a LinkedHashSet of String values where the words are inserted into the set in order of decreasing count. Words that have the same count do not need to be inserted in any particular order. E.g., "is" may come before "world". You cannot sort M. Hint: create an array of size c (where c is the highest word count) where each element is a LinkedHashSet<String>. For every element e in M, add e to the set at index M[i], where i is the count of e in M. Then, append these sets in reverse order according to their index. We provide some pseudocode below. largeToSmall (M): // M is M.size(). c = Get Highest Count Word in M array [0.. c-1] for i in [0.. c-1]: array [i] = new LinkedHashSet<String>(); = for every key k in M: i M.get (k) array [i-1].add (k) = // Append all linkedhashsets in reverse order. return array [c-1] appended to array [c-2] appended to array [0] largeToSmall (wordCount (s)) -> ("world", "is", "the", "healthy", "hello", "it", "i", "certainly", "agree", "that", "1", "and", "not"} For this question you will work with a LinkedList<Integer> data structure and implement several static. Accordingly, you cannot use any LinkedList methods except .get, .add, and .size. You also cannot use any external methods from Arrays, Collections, or any other helper class. (a) Design the addLast method that, when given a LinkedList<Integer> / and an int v, returns a new LinkedList<Integer> with the same elements plus v added to the end of 1. (b) Design the set method that, when given a LinkedList<Integer> 1, an int v, and an index i, returns a new LinkedList<Integer> with the same elements, except that the element at index i is, instead, the value v. If i is less than zero or exceeds the length of 1, return null. (c) Design the toArray method that, when given a LinkedList<Integer> / of Integer, returns an array containing the values from 1. (d) Design the reverse method that, when given a LinkedList<Integer> 1, returns a new LinkedList<Integer> containing the elements of 1, but reversed.
Expert Answer:
Answer rating: 100% (QA)
Here are the implementations of the methods youve requested a Design the addLast method ... View the full answer
Related Book For
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
Posted Date:
Students also viewed these programming questions
-
Tuja Ltd a book manufacturing company has a debt-to-equity ratio of 0.4. It is considering building a new $58 million manufacturing facility which would generate after-tax cash flow of $6.2 million...
-
List three specific parts of the Case Guide, Objectives and Strategy Section (See below) that you had the most difficulty understanding. Describe your current understanding of these parts. Provide...
-
Case Study: Quick Fix Dental Practice Technology requirements Application must be built using Visual Studio 2019 or Visual Studio 2017, professional or enterprise. The community edition is not...
-
In the previous problem, assume the equity increases by 1,500 solaris due to retained earnings. If the exchange rate at the end of the year is 1.24 solaris per dollar, what does the balance sheet...
-
Determine the surface area and the volume of the ring formed by rotating the square about the vertical axis. Given: = 45 deg (b-4 sino) (b+ sine)
-
Discuss why calculations of financial projections impact the client's future goals.
-
For each of the following sets of numbers, calculate a \(95 \%\) confidence interval for the mean ( \(\sigma\) not known); before going through the steps in calculating the confidence interval, the...
-
The director of a large public library must schedule employees to reshelve books and periodicals checked out of the library. The number of items checked out will determine the labor requirements. The...
-
You are tasked with predicting the occurrence of a binary event E. That is, = EUE, and ENE 0. Let p and 1-p denote your true probabilities for E and E, respectively. Let r and 1-r denote your...
-
Suppose the current USD/euro exchange rate is 1.2000 dollar per euro. The six month forward exchange rate is 1.1950. The six month USD interest rate is 1% per annum continuously compounded? Estimate...
-
Papa-P Company directed its IT team to develop its own website wherein customers can place orders and will facilitate swift response to customer's inquiries as well. The development took four months...
-
Who was the famous whistleblower who penned the memo Has Enron Become a Risky Place to Work?
-
How many shares of stock did Kozlowski and Swartz sell without proper disclosure?
-
What are the core ideas behind these frameworks?
-
Financial statement fraud is often attributed to pressures. These pressures include all of the following except: 1. Investment losses by managers 2. Meeting analysts expectations 3. Deadlines and...
-
What related party legal entity did Enron make famous?
-
Computer Graphics: 1. Prove that two successive 2D rotations are additive: R(a1)R(a2) = R(a1+a2), where R(a) denotes a 2x2 rotation matrix of rotation angle a. (Recall that sin(a1+a2) = sinalcosa2+...
-
Why is it important to understand the macro-environment when making decisions about an international retail venture?
-
Kruskals algorithm can return different spanning trees for the same input graph G, depending on how it breaks ties when the edges are sorted into order. Show that for each minimum spanning tree T of...
-
Define lcm (a 1 , a 2 , . . . ,a n ) to be the least common multiple of the n integers a 1 , a 2 , . . . ,a n , that is, the smallest nonnegative integer that is a multiple of each a i . Show how to...
-
Show that the solution of T(n) = T(n=2) + 1 is O(lg n).
-
Equity balances for Sen Widyaya appearing in the statement of financial positions of Widyayas Window Washing Services as at 30 June 2024, 2023 and 2022 are set out below. During 20222023, Sen...
-
A friend who has established a new Pilates studio, Core Strength, has asked you to give some advice as to the contents of financial statements. Transactions of Core Strength include: (a) contribution...
-
Month-end statement of financial position amounts for the practice of David Wei, an immigration lawyer, for 3 consecutive years are shown below. The information is complete except for the balance in...
Study smarter with the SolutionInn App