ArticleslgStudy

mathematics

Balls into bins problem

Balls into bins problem is a mathematics topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Balls into bins problem rather than just read about it. In short: The balls into bins (or balanced allocations) problem is a classic problem in probability theory that has many applications in computer science. The problem involves m balls and n boxes (or "bins").

Key takeaways

  • Balls into bins problem belongs to mathematics; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Balls into bins problem to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Balls into bins problem from memory before moving on to harder problems.

Reference excerpt

The balls into bins (or balanced allocations) problem is a classic problem in probability theory that has many applications in computer science. The problem involves m balls and n boxes (or "bins"). Each time, a single ball is placed into one of the bins. After all balls are in the bins, we look at the number of balls in each bin; we call this number the load on the bin. The problem can be modelled using a Multinomial distribution, and may involve asking a question such as: What is the expected number of bins with a ball in them? Obviously, it is possible to make the maximum load as small as m/n by putting each ball into the least loaded bin. The interesting case is when the bin is selected at random, or at least partially at random. A powerful balls-into-bins paradigm is the "power of two random choices" where each ball chooses two (or more) random bins and is placed in the lesser-loaded bin. This paradigm has found wide practical applications in shared-memory emulations, efficient hashing schemes, randomized load balancing of tasks on servers, and routing of packets within parallel networks and data centers.

Random allocation When the bin for each ball is selected at random, independent of other choices, the maximum load might be as large as m. However, it is possible to calculate a tighter bound that holds with high probability. A "high probability" is a probability 1−o(1), i.e. the probability tends to 1 when n grows to infinity. For the case m=n, with probability 1−o(1) the maximum load is:

log⁡nlog⁡log⁡n⋅(1+o(1)). Gonnet gave a tight bound for the expected value of the maximum load, which for m=n is Γ−1(n)−32+o(1), where Γ−1 is the inverse of the gamma function, and it is known that Γ−1(n)=log⁡nlog⁡log⁡n⋅(1+o(1)). The maximum load can also be calculated for m≠n, and for example, for m>nlog⁡n it is mn+Θ(mlog⁡nn), and for m<n/log⁡n it is Θ(log⁡nlog⁡(n/m)), with high probability. Exact probabilities for small m=n can be computed as a(n)/nn for a(n) defined in OEIS A208250.

Partially random allocation Instead of just selecting a random bin for each ball, it is possible to select two or more bins for each ball and then put the ball in the least loaded bin. This is a compromise between a deterministic allocation, in which all bins are checked and the least loaded bin is selected, and a totally random allocation, in which a single bin is selected without checking other bins. This paradigm often called the "power of two random choices" has been studied in a number of settings below. In the simplest case, if one allocates m balls into n bins (with m=n) sequentially one by one, and for each ball one chooses d≥2 random bins at each step and then allocates the ball into the least loaded of the selected bins (ties broken arbitrarily), then with high probability the maximum load is:

log⁡log⁡nlog⁡d+Θ(1) which is almost exponentially less than with totally random allocation. This result can be generalized to the case m≥n (with d≥2), when with high probability the maximum load is:

mn+log⁡log⁡nlog⁡d+Θ(1) which is tight up to an additive constant. (All the bounds hold with probability at least 1−1/nc for any constant c>0.) Note that for m>nlog⁡n, the random allocation process gives only the maximum load of mn+O(log⁡log⁡n) with high probability, so the improvement between these two processes is especially visible for large values of m. Other key variants of the paradigm are "parallel balls-into-bins" where n balls choose d random bins in parallel, "weighted balls-into-bins" where balls have non-unit weights, and "balls-into-bins with deletions" where balls can be added as well as deleted.

Infinite stream of balls Instead of just putting m balls, it is possible to consider an infinite process in which, at each time step, a single ball is added and a single ball is taken, such that the number of balls remains constant. For m=n, after a sufficiently long time, with high probability the maximum load is similar to the finite version, both with random allocation and with partially random allocation.

Repeated balls-into-bins In a repeated variant of the process, m balls are initially distributed in n bins in an arbitrary way and then, in every subsequent step of a discrete-time process, one ball is chosen from each non-empty bin and re-assigned to one of the n bins uniformly at random. When m=n, it has been shown that with high probability the process converges to a configuration with maximum load 𝒪(log⁡(n)) after 𝒪(n) steps.

Applications Online Load Balancing: consider a set of n identical computers. There are n users who need computing services. The users are not coordinated - each users comes on his own and selects which computer to use. Each user would of course like to select the least loaded computer, but this requires to check the load on each computer, which might take a long time. Another option is to select a computer at random; this leads, with high probability, to a maximum load of log⁡nlog⁡log⁡n⋅(1+o(1)). A possible compromise is that the user will check only two computers, and use the lesser loaded of the two. This leads, with high probability, to a much smaller maximum load of log2log⁡n+Θ(1). Hashing: consider a hash table in which all keys mapped to the same location are stored in a linked list. The efficiency of accessing a key depends on the length of its list. If we use a single hash function which selects locations with uniform probability, with high probability the longest chain has O(log⁡nlog⁡log⁡n) keys. A possible improvement is to use two hash functions, and put each new key in the shorter of the two lists. In this case, with high probability the longest chain has only O(log⁡log⁡n) elements. Fair cake-cutting: consider the problem of creating a partially proportional division of a heterogeneous resource among n people, such that each person receives a part of the resource which that person values as at least 1/an of the total, where a is some sufficiently large constant. The Edmonds–Pruhs protocol is a randomized algorithm whose analysis make use of balls-into-bins arguments.

References

Worked examples

Example 1 — a first encounter with Balls into bins problem

Start with the simplest possible case. Write down what Balls into bins problem claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In mathematics, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Balls into bins problem before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Balls into bins problem ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Balls into bins problem

In research
Balls into bins problem appears in mathematics research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Balls into bins problem in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Balls into bins problem is common in secondary-school and first-year university syllabi. It links to neighbouring topics Probability problems, so understanding it makes those chapters shorter.
In everyday life
Look for Balls into bins problem outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Balls into bins problem” →

How to study Balls into bins problem in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Balls into bins problem means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Balls into bins problem out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Balls into bins problem in simple terms?

The balls into bins (or balanced allocations) problem is a classic problem in probability theory that has many applications in computer science. The problem involves m balls and n boxes (or "bins").

Why does Balls into bins problem matter?

Because it connects several mathematics ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Balls into bins problem?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Balls into bins problem.

Tags

  • Probability problems

Keep exploring