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 7561237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:06:45+00:00 2026-05-30T13:06:45+00:00

This is my first question on stackflow. As you can tell, I am new

  • 0

This is my first question on stackflow. As you can tell, I am new to learning algorithms and data structure.

When using the division method for create a hash function (i.e. h(k) = k mod m), one is advised (e.g. by CLRS) to use a prime number not too close to a power of 2 for the divisor m. Could someone kindly explain to me why a choice of m to be a composite number is bad?

  • 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-30T13:06:47+00:00Added an answer on May 30, 2026 at 1:06 pm

    Consider the case if m is even and all the k values are all even. Then, the hash values will also all be even.

    For example, consider the case m=6 hashing even values:

    Input values:  0, 2, 4, 6, 8, 10, 12, 14, 16, ...
    Hash values:   0, 2, 4, 0, 2,  4,  0,  2,  4, ...
    

    If you use these hash values as indices into a table, then half of the table will be unused. On the other hand, if m is a prime, you will get an even distribution of the hash values, even if the input values all have a common factor.

    Consider the same input values, but with m=7:

    Input values:  0, 2, 4, 6, 8, 10, 12, 14, 16, ...
    Hash values:   0, 2, 4, 6, 1,  3,  5,  0,  2, ...
    

    Despite the fact that the input values are all even, the hash values are still uniformly distributed over [0..6].

    So to summarize, if m is prime, then you’ll still get an even distribution of hash values even if all input values are divisible a common prime factor (other than m).

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

Sidebar

Related Questions

this is my first question here so I hope I can articulate it well
this my first question on here. I hope someone can help. It is to
This is my first question, i would be very pleased if you can help
This is my first question so please be gentle. :-) I know AspectJ can
This is my first question on this site. I'm new to php but i've
this is my first question to stackoverflow so here it goes... I use cruise
This is my first question so please be patient :) Background: I'm implementing an
this is my first question.. so, here we go. i have a site, 100%
This is my first question :). Im writing a little twitter app in PHP
This is my first question. Thanks to everyone who contributes to this site, it's

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.