Assume you are hashing a set (unknown length) of randomly generated Strings, into a HashTable with...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Assume you are hashing a set (unknown length) of randomly generated Strings, into a HashTable with a a size of 50 (this means your HashTable has 50 buckets). You can also assume that strings are iterable and characters utilize the Java native hash function. Examine the two hashCode() implementations below. In general, which hashCode () option will result in a greater number of collisions for all strings? Justify your answer in 1-2 sentences describing how each hashCode may generate a range of possible hashCode values. Assume that when we call this in our hash functions, we are referring to each string object we are hashing. Option 1: This code utilizes Java's implementation of hashCode () for Characters which returns the unique int value associated with each character based on its assigned ASCII value. Ex: 'a' returns 97, 'A' returns 65. public int hashCodel () { Iterator<Character> iterator= this.iterator (); int result = 0; int i = 0; while literator.hasNext ()) { result += iterator.next().hashCode (); i++; } return result; Option 2: This code utilizes Java's implementation of hashCode () for Strings which is the following (value is an array of the characters within the array): //Java's String hashCode implementation public static int hashCode (byte [ value) { int h = 0; int length = value.length; for (int i = 0; i< length; i++) { h = 31 h + getChar (value, i); } return h; public int hashCode2() { return this.hashCode (). Assume you are hashing a set (unknown length) of randomly generated Strings, into a HashTable with a a size of 50 (this means your HashTable has 50 buckets). You can also assume that strings are iterable and characters utilize the Java native hash function. Examine the two hashCode() implementations below. In general, which hashCode () option will result in a greater number of collisions for all strings? Justify your answer in 1-2 sentences describing how each hashCode may generate a range of possible hashCode values. Assume that when we call this in our hash functions, we are referring to each string object we are hashing. Option 1: This code utilizes Java's implementation of hashCode () for Characters which returns the unique int value associated with each character based on its assigned ASCII value. Ex: 'a' returns 97, 'A' returns 65. public int hashCodel () { Iterator<Character> iterator= this.iterator (); int result = 0; int i = 0; while literator.hasNext ()) { result += iterator.next().hashCode (); i++; } return result; Option 2: This code utilizes Java's implementation of hashCode () for Strings which is the following (value is an array of the characters within the array): //Java's String hashCode implementation public static int hashCode (byte [ value) { int h = 0; int length = value.length; for (int i = 0; i< length; i++) { h = 31 h + getChar (value, i); } return h; public int hashCode2() { return this.hashCode ().
Expert Answer:
Answer rating: 100% (QA)
The two options presented are Using Javas implementation of hashCode for Characters This approach assigns a unique integer value to each character based on its ASCII value For instance a returns 97 an... View the full answer
Related Book For
Managerial Economics
ISBN: 978-0133020267
7th edition
Authors: Paul Keat, Philip K Young, Steve Erfle
Posted Date:
Students also viewed these programming questions
-
pre tax cost weight bonds 0.02 0.1 notes 0.04 0.15 ext equity 0.13 0.25 int equity 0.11 0.3 preferred 0.08 0.2 what is the WACC using all elemtns if the corporate tax rate is 40%
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Assignment 5: Hash Table implementation andconcordance There are three parts to this assignment. In the first two parts,you will complete the implementation of a hash map and aconcordance program. In...
-
When my niece Michelle told me she had learned to read, she was bursting with pride. How might reflecting on this accomplishment affect how Michelle thinks about herself?
-
In 2018, Adonis Industries changed its method of valuing inventory from the average cost method to the FIFO method. At December 31, 2017, Adonis's inventories were $47.6 million (average cost)....
-
Selected information from the payroll register of Ebeling's Dairy for the week ended July 7, 20--, is shown below. The SUTA tax rate is 5.4%, and the FUTA tax rate is 0.6%, both on the first $7,000...
-
In analyzing a transaction, can a transaction only affect one side of the basic accounting equation? If so, give an example. LO12
-
The Coca-Cola Company (Coca-Cola), like PepsiCo, manufactures and markets a variety of beverages. Exhibit 3.22 presents a statement of cash flows for Coca-Cola for 2006 to 2008. Required Discuss the...
-
The magnitude (M) of an earthquake on the Richter scale is given by log E=1.5 M+K , where E is the energy released as seismic waves (in Joules) from the earthquake and K is a constant. (a) The energy...
-
Copy Fast Services was opened by Jarenz on January 1, 2008 with a cash investment of P 10,000. Additional transactions for the month are as follows: Jan 245678 6 7 8 9 14 15 19 20 25 6456 33333 30 31...
-
How do compare the m etaphor of organizations is water: Generating new images for environmental sustainability to other metaphors "Machine, Brain, Culture, Organism, Political, and Prison"? explain...
-
Which of the following do states typically NOT tax? A. Social security benefits B. Illegal income C. Gambling winnings D. Capital gains E. None of the above
-
True or false: most states taxable income calculations start with federal taxable income.
-
For your state, list whether inventory is subject to property tax, and if so, describe the valuation method used and the assessment date.
-
Your client, who owns several factories, has for years paid the property tax assessed without question. What sort of information might you request from the client in an attempt to reduce the clients...
-
How many states have no personal income tax? A. Five B. Four C. Three D. Two E. One
-
Aluminum Bahrain B.S.C., or simply Alba, is one of the largest industrial companies in the Middle East and is one of the largest aluminum producers in the world. The company is based in Bahrain and...
-
Which of the followingcarbocations is the least stable? CH3CH2 . CH3CHCH3 CH3 I . CH3C0 T CH3 IV. V. CH3 CH3CCH2 CH3
-
Discuss the meaning of the term principal-agent problem. Why does this problem exist?
-
You are the manager of a large automobile dealership who wants to learn more about the effectiveness of various discounts offered to customers over the past 14 months. Following are the average...
-
How is the weighted average cost of capital determined?
-
Describe how businesses account for and report cash.} - A cash account is debited when cash is received and credited when cash is paid out. - Cash is reported on the statement of financial position...
-
Motormusic Ltd makes a standard model of car radio, which it sells to car manufacturers for 60 each. Next year the business plans to make and sell 20,000 radios. The businesss costs are as follows:...
-
Describe the operating cycle and explain the principles of cash management. - The operating cycle of the business starts when the business uses cash to purchase inventory. - When a business sells...
Study smarter with the SolutionInn App