Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assume you are hashing a set (unknown length) of randomly generated Strings, into a HashTable with a a size of 50 (this means your

Assume you are hashing a set (unknown length) of randomly generated Strings, into a HashTable with a a size

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 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 ().

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Managerial Economics

Authors: Paul Keat, Philip K Young, Steve Erfle

7th edition

0133020266, 978-0133020267

More Books

Students also viewed these Programming questions

Question

What are the purposes for closing the books?

Answered: 1 week ago

Question

Explain the operation of the dividends received deduction.

Answered: 1 week ago

Question

How is the weighted average cost of capital determined?

Answered: 1 week ago