ArticleslgStudy

computer science

Quadratic probing

Quadratic probing is a computer science 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 Quadratic probing rather than just read about it. In short: Quadratic probing is an open addressing scheme in computer programming for resolving hash collisions in hash tables. Quadratic probing operates by taking the original hash index and adding successive values of an arbitrary quadratic polynomial until an open slot is found.

Key takeaways

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

Reference excerpt

Quadratic probing is an open addressing scheme in computer programming for resolving hash collisions in hash tables. Quadratic probing operates by taking the original hash index and adding successive values of an arbitrary quadratic polynomial until an open slot is found. An example sequence using quadratic probing is:

H + 1 2 , H + 2 2 , H + 3 2 , H + 4 2 , . . . , H + k 2 {\displaystyle H+1^{2},H+2^{2},H+3^{2},H+4^{2},...,H+k^{2}}

Quadratic probing is often recommended as an alternative to linear probing because it incurs less clustering. Quadratic probing exhibits better locality of reference than many other hash table such as chaining; however, for queries, quadratic probing does not have as good locality as linear probing, causing the latter to be faster in some settings.

History Quadratic probing was first introduced by Ward Douglas Maurer in 1968. Several subsequent variations of the data structure were proposed in the 1970s in order to guarantee that the probe sequence hits every slot without cycling prematurely. Quadratic probing is widely believed to avoid the clustering effects that make linear probing slow at high load factors. It serves as the basis for many widely used high-performance hash-tables, including Google's open-source Abseil hash table. It is conjectured that quadratic probing, when filled to 1 − ϵ {\displaystyle 1-\epsilon } full, supports insertions in expected time O ( ϵ − 1 ) {\displaystyle O(\epsilon ^{-1})} . Proving this, or even proving any non-trivial time bound for quadratic probing remains open. The closest result, due to Kuszmaul and Xi, shows that, at load factors of less than ≈ 0.089 {\displaystyle \approx 0.089} , insertions take O ( 1 ) {\displaystyle O(1)} expected time.

Quadratic function Let h(k) be a hash function that maps an element k to an integer in [0, m−1], where m is the size of the table. Let the ith probe position for a value k be given by the function

h ( k , i ) = h ( k ) + c 1 i + c 2 i 2 ( mod m ) {\displaystyle h(k,i)=h(k)+c_{1}i+c_{2}i^{2}{\pmod {m}}}

where c2 ≠ 0 (If c2 = 0, then h(k,i) degrades to a linear probe). For a given hash table, the values of c1 and c2 remain constant. Examples:

If h ( k , i ) = ( h ( k ) + i + i 2 ) ( mod m ) {\displaystyle h(k,i)=(h(k)+i+i^{2}){\pmod {m}}} , then the probe sequence will be h ( k ) , h ( k ) + 2 , h ( k ) + 6 , . . . {\displaystyle h(k),h(k)+2,h(k)+6,...}

For m = 2n, a good choice for the constants are c1 = c2 = 1/2, as the values of h(k,i) for i in [0, m−1] are all distinct (in fact, it is a permutation on [0, m−1]). This leads to a probe sequence of h ( k ) , h ( k ) + 1 , h ( k ) + 3 , h ( k ) + 6 , . . . {\displaystyle h(k),h(k)+1,h(k)+3,h(k)+6,...} (the triangular numbers) where the values increase by 1, 2, 3, ... For prime m > 2, most choices of c1 and c2 will make h(k,i) distinct for i in [0, (m−1)/2]. Such choices include c1 = c2 = 1/2, c1 = c2 = 1, and c1 = 0, c2 = 1. However, there are only m/2 distinct probes for a given element, requiring other techniques to guarantee that insertions will succeed when the load factor exceeds 1/2. For m = n p {\displaystyle m=n^{p}} , where m, n, and p are integer greater or equal 2 (degrades to linear probe when p = 1), then h ( k , i ) = ( h ( k ) + i + n i 2 ) ( mod m ) {\displaystyle h(k,i)=(h(k)+i+ni^{2}){\pmod {m}}} gives cycle of all distinct probes. It can be computed in loop as: h ( k , 0 ) = h ( k ) {\displaystyle h(k,0)=h(k)} , and h ( k , i + 1 ) = ( h ( k , i ) + 2 i n + n + 1 ) ( mod m ) {\displaystyle h(k,i+1)=(h(k,i)+2in+n+1){\pmod {m}}}

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Quadratic probing

Start with the simplest possible case. Write down what Quadratic probing claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, 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 Quadratic probing 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 Quadratic probing 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 Quadratic probing

In research
Quadratic probing appears in computer science 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 Quadratic probing 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
Quadratic probing is common in secondary-school and first-year university syllabi. It links to neighbouring topics Hashing, Search algorithms, so understanding it makes those chapters shorter.
In everyday life
Look for Quadratic probing 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.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Quadratic probing in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Quadratic probing 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 Quadratic probing out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Quadratic probing in simple terms?

Quadratic probing is an open addressing scheme in computer programming for resolving hash collisions in hash tables. Quadratic probing operates by taking the original hash index and adding successive values of an arbitrary quadratic polynomial until an open slot is found.

Why does Quadratic probing matter?

Because it connects several computer science 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 Quadratic probing?

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 Quadratic probing.

Tags

  • Hashing
  • Search algorithms

Keep exploring