Radix heap

From HandWiki

A radix heap is a data structure for realizing the operations of a monotone priority queue. A set of elements to which a key is assigned can then be managed. The run time of the operations depends on the difference between the largest and smallest key or constant. The data structure consists mainly of a series of buckets, the size of which increases exponentially.

Prerequisites

  1. all keys are natural numbers;
  2. max. key - min. key [math]\displaystyle{ \le }[/math] C for constant C;
  3. the extract-min operation is monotonic; that is, the values returned by successive extract-min calls are monotonically increasing.

Description of data structure

The three most important fields are:

  1. [math]\displaystyle{ b }[/math] of size [math]\displaystyle{ B := \lfloor log(C+1)\rfloor + 1 }[/math], with 0 as the lowest index, stores the buckets;
  2. [math]\displaystyle{ u }[/math] of size [math]\displaystyle{ B+1 }[/math], with 0 as the lowest index, store the (lower) bounds of the buckets;
  3. [math]\displaystyle{ bNum }[/math], holds for each element [math]\displaystyle{ x }[/math] in the heap the bucket in which it is stored.

RadixHeap1.png

The above diagram shows the data structure. The following invariants apply:

  1. [math]\displaystyle{ u[i] \le }[/math] key in [math]\displaystyle{ b[i] \lt u[i+1] }[/math]: the keys in [math]\displaystyle{ b[i] }[/math] are up or down through the value in [math]\displaystyle{ u[i+1] }[/math] or [math]\displaystyle{ u[i] }[/math] limited.
  2. [math]\displaystyle{ u[0] = 0, u[1] = u[0] + 1, u[B] = \infty }[/math] and [math]\displaystyle{ 0 \le u[i+1]-u[i] \le 2^{i-1} }[/math] for [math]\displaystyle{ i = 1, \ldots, B-1 }[/math]: the sizes of the buckets increase exponentially.

It is important to note the exponential growth of the limits (and thus the range that a bucket holds). In this way the logarithmic dependence of the field quantities is of value C, the maximum difference between two key values.

Operations

During initialization, empty buckets are generated and the lower bounds [math]\displaystyle{ u }[/math] are generated (according to invariant 2); running time [math]\displaystyle{ O(B) }[/math].

During insert, a new element [math]\displaystyle{ x }[/math] is linearly moved from right to left through the buckets and the new element with [math]\displaystyle{ k(x) }[/math] is stored in the left bucket to that [math]\displaystyle{ u[i] \ge k(x) }[/math]; running time [math]\displaystyle{ O(B) }[/math].

For decrease-key, first the key value is decreased (checking for compliance with the invariants). Then, the [math]\displaystyle{ bNum }[/math] field is used to locate the element and it is iterated to the left, if necessary, analogously to the insert operation. The running time is [math]\displaystyle{ O(1) }[/math] (amortized).

The extract-min operation removes an element from bucket [math]\displaystyle{ b[0] }[/math] and returns it. If the bucket [math]\displaystyle{ b[0] }[/math] is not yet empty, the operation is terminated. If, however, it is empty, the next larger non-empty bucket is searched, its smallest element [math]\displaystyle{ k }[/math] tracked and [math]\displaystyle{ u[0] }[/math] is set to k (monotonicity is required for this). Then, according to the invariants, the bucket boundaries are redefined and the elements removed [math]\displaystyle{ b[i] }[/math] to the newly formed buckets; running time [math]\displaystyle{ O(1) }[/math] (amortized).

If displayed, the field [math]\displaystyle{ bNum }[/math] is updated.

References