Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7973183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:02:36+00:00 2026-06-04T08:02:36+00:00

I was reviewing for my data structures final exam, and I came across a

  • 0

I was reviewing for my data structures final exam, and I came across a question in past year’s final. Having worked on it for the past three hours, I still couldn’t figure out a way to solve it, except by trial and error. Here’s the question:

“Suppose that the size of your hash table is 31, the constant g is also 31, and that you use the following hash code

int hash = 0;
int n = s.length();
for (int i = 0; i < n; i++)
   hash = g * hash + s.charAt(i);

and that you use separate chaining to resolve collisions. List five different names that would hash to the same location in the table.”

I think there must be some kind of tricks, possibly involving the modulo operator, to solve this problem, considering the size of the hash table is 31, which is the same as the constant g. Sorry if I sound like it, but I’m not asking for code or anything, just some thoughts/hints on the question. Any comment is greatly appreciated. Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T08:02:37+00:00Added an answer on June 4, 2026 at 8:02 am

    According to the Wikipedia article on Java’s string hashing algorithm (which is the same as the algorithm you present):

    As with any general hashing function, collisions are possible. For
    example, the strings “FB” and “Ea” have the same hash value. The
    hashCode() implementation of String uses the prime number 31 and the
    difference between ‘a’ and ‘B’ is just 31, so the calculation is 70 ×
    31 + 66 = 69 × 31 + 97.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm reviewing a .NET project, and I came across some pretty heavy usage of
I am reviewing my data structures and algorithm analysis lesson, and I get a
I am reviewing implementations for some basic data structures and the algorithms operating on
I've been reviewing C++ with the book Practical C++ Programming , and came across
I'm reviewing for a test, and I am stumped by this question. Consider the
I'm trying to save an array to Core Data. I've been reviewing the following
An auditor reviewing our system was suggesting that our data should be stored on
My Application is recieving data from external hardware and plots it onto a panel
in my app' i'm recieving data from serial port and save them into two
is there any small working program for recieving from and sending data to client

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.