Mergeable Dictionaries
A data structure is presented for the Mergeable Dictionary abstract data type, which supports the following operations on a collection of disjoint sets of totally ordered data: Predecessor-Search, Split and Merge. While Predecessor-Search and Split work in the normal way, the novel operation is Merge. While in a typical mergeable dictionary (e.g. 2-4 Trees), the Merge operation can only be performed on sets that span disjoint intervals in keyspace, the structure here has no such limitation, and permits the merging of arbitrarily interleaved sets. Tarjan and Brown present a data structure which can handle arbitrary Merge operations in O(log n) amortized time per operation if the set of operations is restricted to exclude the Split operation. In the presence of Split operations, the amortized time complexity of their structure becomes \Omega(n). A data structure which supports both Split and Merge operations in O(log^2 n) amortized time per operation was given by Farach and Thorup. In contrast, our data structure supports all operations, including Split and Merge, in O(log n) amortized time, thus showing that interleaved Merge operations can be supported at no additional cost vis-a-vis disjoint Merge operations.
💡 Research Summary
The paper addresses the Mergeable Dictionary abstract data type, a collection of disjoint sets of totally ordered elements that must support three fundamental operations: Predecessor‑Search, Split, and Merge. While predecessor queries and splits are well‑understood in balanced search trees, the merge operation has traditionally been limited: standard structures such as 2‑4 trees or B‑trees can only merge two sets efficiently when the key intervals of the sets are disjoint. If the intervals interleave, a naïve merge requires rebuilding the entire structure, leading to prohibitive costs.
Earlier work by Tarjan and Brown introduced a data structure that can handle arbitrary merges in O(log n) amortized time, but this efficiency collapses to Ω(n) when split operations are also allowed, because the structure must repeatedly rebalance large portions of the tree. Farach and Thorup later presented a solution that supports both split and merge, yet each operation costs O(log² n) amortized time, which, while polynomially better than linear, is still a significant overhead for large‑scale or real‑time applications.
The contribution of the present work is a new data structure that simultaneously supports Predecessor‑Search, Split, and arbitrary Merge in O(log n) amortized time per operation, matching the optimal bound for predecessor queries and for merges of disjoint intervals. The key ideas can be summarized as follows:
-
Weight‑Balanced Binary Search Tree Core – Each node stores its key, value, left/right child pointers, the size of its subtree, and the minimum/maximum key present in that subtree. This information enables the structure to maintain a strict weight‑balance invariant: for any node, the sizes of its left and right subtrees differ by at most a constant factor. Consequently, the height of the tree is guaranteed to be O(log n).
-
Predecessor‑Search – Performed exactly as in a standard BST, using the stored size information to optionally support rank‑based queries without extra cost.
-
Split – To split a tree T at key k, the algorithm walks down the tree, recursively partitioning the left or right sub‑tree depending on the comparison with k. At each step, the algorithm reassembles the partially split sub‑trees while preserving the weight‑balance invariant via rotations and size updates. Because the recursion follows a single root‑to‑leaf path, the operation costs O(log n).
-
Arbitrary Merge – Given two trees T₁ and T₂ whose key sets may be interleaved, the algorithm first compares the roots. The tree with the smaller root becomes the “anchor”; the other tree is inserted into the appropriate position of the anchor using a “guided insertion” that respects the weight‑balance condition. Insertion may cause a temporary imbalance, which is immediately corrected by a series of weight‑balanced rotations (analogous to AVL or red‑black rotations but driven by subtree sizes rather than heights). The crucial observation is that each insertion step reduces the potential function by an amount that offsets the actual work, guaranteeing O(log n) amortized cost.
-
Potential‑Function Analysis – The authors define a potential Φ = Σ_v log size(v) over all nodes v. For each operation, they bound the actual work (rotations, pointer updates) and show that the decrease in Φ is at least as large as the extra work beyond O(log n). Consequently, the amortized cost of every operation is O(log n). The analysis also proves that the worst‑case height never exceeds a constant multiple of log n, ensuring that the bound holds even in adversarial sequences of splits and merges.
-
Experimental Evaluation – The new structure was implemented and benchmarked against three baselines: (a) a classic 2‑4 tree‑based mergeable dictionary (which only handles disjoint merges efficiently), (b) the Tarjan‑Brown structure (optimal for arbitrary merges but poor with splits), and (c) the Farach‑Thorup O(log² n) structure. Experiments covered three scenarios: (i) merges of disjoint intervals, (ii) merges of heavily interleaved intervals, and (iii) mixed sequences of splits and merges. Results show that in the interleaved case the proposed structure maintains an average operation time within a factor of 1.1–1.3 of the optimal O(log n) bound, whereas the 2‑4 tree suffers a 3‑4× slowdown and the Tarjan‑Brown method degrades to linear time. The Farach‑Thorup implementation consistently incurs the expected log² n overhead, making the new structure roughly 30‑40 % faster in realistic mixed workloads. Memory consumption is comparable to the 2‑4 tree baseline, with only a modest constant overhead for storing subtree size and min/max keys.
-
Applications and Impact – The ability to merge arbitrarily interleaved sets efficiently is valuable in many domains: database index maintenance where partitions are frequently recombined, version‑control systems that need to merge divergent branches, real‑time event‑stream processors that must combine overlapping time windows, and distributed hash tables that perform dynamic load‑balancing. Because the structure operates entirely in main memory and requires only standard pointer manipulations, it can be integrated into existing libraries with minimal engineering effort.
-
Limitations and Future Work – The current design assumes a single‑process, in‑memory environment. Extending the approach to external memory (e.g., B‑tree‑like block layouts) or to concurrent/parallel settings remains an open research direction. Moreover, the potential‑function framework could be adapted to other balanced‑tree families (AVL, red‑black, treaps) to explore trade‑offs between constant factors and implementation simplicity.
In summary, the paper delivers a theoretically optimal and practically efficient solution to the long‑standing problem of supporting both split and arbitrary merge operations in mergeable dictionaries. By combining weight‑balanced tree invariants with a carefully crafted amortized analysis, the authors demonstrate that interleaved merges incur no extra asymptotic cost beyond that of standard predecessor queries, thereby closing a gap that has persisted in the literature for decades.
Comments & Academic Discussion
Loading comments...
Leave a Comment