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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:44:39+00:00 2026-06-07T07:44:39+00:00

Here is a problem: I have random integers say count = M and they

  • 0

Here is a problem: I have random integers say count = M and they need to be divided equally (or roughly equally) in N buckets.

If I were to assign a range to M and N, N would be around 10000 and M could be from 100 to 5 million.

So far this looks like a small hashing problem. But here is what complicates it further. So these numbers are M in count but they are to be considered incrementally so say initially you have X no. of integers, you distribute them equally and then Y no. of integers are available more so you distribute them again, then Z no. of integers are available (X+Y+Z = M).

Also a particular no. should be distributed in such a fashion that their bucket no. can be searched efficiently.

So far here I thought couple of approaches but none of them could even come close to having equal distribution.

1) Have bucket no. high so max of N is 5 million. Equal distribution means 500 buckets so start out by creating 500 buckets. They would be eventually full equally. But this too has end cases which can be dirty to handle.
2) Have bucket size according to size available currently (X then later on X+Y then M) and if it is full rehash to increase no. of buckets. This may be a costly exercise in my use case and would want to avoid it.
3) Somehow trying to fit Bin Packing problem. But it doesn’t readily tell me what is the bin in which an integer will go.
One obvious thing to keep in mind is that since these are random nos, if the count is say 100,000 one of the nos. could as well be 500,000.

What approach do you recommend? I can provide the use case later if needed.

  • 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-07T07:44:40+00:00Added an answer on June 7, 2026 at 7:44 am

    You are way over complicating this. The integers are random, so no thinking is required. If the integers were not random, then we might have to come up with a hash algorithm.

    So long as the range of the integers is reasonably greater than the number of buckets, just assign them to their bucket by the modulo of the number of buckets.

    Like this:

    void assignToBucket( int r )
    {
        bucket[ r % NUM_BUCKETS ].add( r );
    }
    

    It doesn’t matter how many you try to insert – or if they come in all at once, or in several passes. So long as the stream is random, then the modulo will ensure they are roughly evenly distributed in the buckets.

    This won’t work if the range of each r is close to the number of buckets. That is if each r is from 0-7 and there are 6 buckets it won’t distribute evenly. And it won’t work with a non-random stream.

    For a stream with a non-random distribution, you would need to know something about the distribution to create a proper hash function.

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

Sidebar

Related Questions

Here is my problem: I have an array of model class(Let's say, 'addressModel' with
I have problem adding arraylist to list view, will explain about my problem here..
First, sorry for my bad english, I'm French. Here the problem : I have
Here is the problem: I have two columns in a table that, for each
Here's the problem: I have a data-bound list of items, basically a way for
Here is my problem : I have a list of messages which I can
Here's my problem: I have do create a menu/list of actions (which would be
Here's the problem: I have couple of pages which gets its content from a
Here's the problem -- I have a few thousand small text snippets, anywhere from
Here's my problem: I have an unmanaged dll that I made.I'm calling one of

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.