Title: Segment-Based Dynamic Programming for Optimal Binary Search Trees: A Sub-Cubic Algorithm with Hierarchical Weight Partitioning
Primary area: optimization
Keywords: Optimal binary search trees, Dynamic programming, Hierarchical partitioning, Algorithmic complexity, Efficient search.

Abstract: Constructing optimal binary search trees under two-way comparisons is significantly more challenging than in the classical three-way model: two-way comparisons induce complex “punctured intervals” in the Dynamic Programming (DP) state space, potentially resulting in exponential sub-problem growth. In particular, the state-of-the-art algorithm for two-way comparisons runs in O\left(n^4\right) time, which becomes infeasible for large datasets with millions of keys. The proposed work presents a novel O\left(n^2\log{n^2}\right) time algorithm for constructing optimal search trees with two-way comparisons, improving on the current best O\left(n^4\right) complexity. The approach introduces Hierarchical Weight Partitioning (HWP), a segment-based dynamic programming framework that partitions the weight space into hierarchical segments, enabling efficient pruning of equivalent sub-problems while preserving optimality. The algorithm leverages a multi-level segment tree data structure with adaptive threshold selection to achieve logarithmic improvements in both time and space complexity for practical instances. Experimental evaluation on synthetic and real-world datasets demonstrates 3 to 8 times speedups with up to 60% memory reduction compared to existing methods. Our work provides the first sub-cubic solution for this fundamental problem. These results impact new possibilities for efficient inference in AI systems that rely on search structures (e.g., decision-tree models or data indexes).

TL;DR: We present the first sub-cubic algorithm for optimal two-way binary search trees, using hierarchical weight partitioning to cut complexity from O(n⁴) to O(n² log² n) while achieving major speed and memory gains for large-scale AI and data systems.