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

  • SEARCH
  • Home
  • 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 6600753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:39:56+00:00 2026-05-25T18:39:56+00:00

My hashcode function for string is as follows hashVal=(127*hashVal+key.charAt(i))%16908799 I am following cs61 b

  • 0

My hashcode function for string is as follows

hashVal=(127*hashVal+key.charAt(i))%16908799

I am following cs61 b lectures online and I dont quite follow when Prof.Jonathan on what would happen if instead of 1690877 we would use a value that is no relatively prime with 127. I understand the simple case where he uses 127 instead of 16908799 but what if it was a simple multiple of 127 ? How would it “bias” the hashvalue ? How does the bias depend on the common factor “x” ? Can anyone suggest me the reason ?

  • 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-05-25T18:39:57+00:00Added an answer on May 25, 2026 at 6:39 pm

    Use smaller numbers and think it out. Say you’re working in a modulus 10 space (instead of 16908799). Your hashVal can then only contain the numbers 0-9.

    If you multiply by 7, for instance, you should see that you can get out all numbers 0-9:

    (7*0)%10 = 0
    (7*1)%10 = 7
    (7*2)%10 = 4
    (7*3)%10 = 1
    (7*4)%10 = 8
    (7*5)%10 = 5
    (7*6)%10 = 2
    (7*7)%10 = 9
    (7*8)%10 = 6
    (7*9)%10 = 3
    

    However if you multiply by 6 (which is not relatively prime with 10 because they have the common factor 2), then you will not get all numbers 0-9 out, thus there is bias:

    (6*0)%10 = 0
    (6*1)%10 = 6
    (6*2)%10 = 2
    (6*3)%10 = 8
    (6*4)%10 = 4
    (6*5)%10 = 0
    (6*6)%10 = 6
    (6*7)%10 = 2
    (6*8)%10 = 8
    (6*9)%10 = 4
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am converting the incoming string into hash code by doing the following function
I am trying to create a quick hashcode function for a complex number class
The JDK documentation for java.lang.String.hashCode() famously says: The hash code for a String object
Following java code returns hash code of a string. String uri = Some URI
Typically the default implementation of Object.hashCode() is some function of the allocated address of
The hashCode value of a Java String is computed as ( String.hashCode() ): s[0]*31^(n-1)
Please clarify my doubt in Hashset. Consider the following code, class Person { String
How likely is it to get a HashCode collision with the function below in
I have this hashCode function that I have been trying to implement with Eclipse
// The worst possible legal hash function - never use! @Override public int hashCode()

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.