{"id":130,"date":"2026-11-13T12:32:12","date_gmt":"2026-11-13T04:32:12","guid":{"rendered":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-a-van-emde-boas-tree-searches-in-log-log-universe\/"},"modified":"2026-11-13T21:50:57","modified_gmt":"2026-11-13T13:50:57","slug":"how-a-van-emde-boas-tree-searches-in-log-log-universe","status":"publish","type":"post","link":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-a-van-emde-boas-tree-searches-in-log-log-universe\/","title":{"rendered":"How a van Emde Boas tree searches in log log universe"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Short answer:<\/strong> A <strong>van Emde Boas tree<\/strong> stores a set of integers from a universe 0, 1, \u2026, u\u22121 and supports insert, delete, member, successor, and predecessor in <strong>O(log log u)<\/strong> time. It splits the universe into \u221au clusters of \u221au values, keeps a summary structure on which clusters are nonempty, and stores the minimum of a cluster aside so the cluster itself does not also hold it. The recurrence T(u) = T(\u221au) + O(1) solves to O(log log u). The size is <strong>O(u)<\/strong> in the straightforward layout.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the problem actually asks<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">A balanced search tree on n keys costs O(log n), which depends on how many keys are present and uses only comparisons. When the keys are integers in a bounded universe, a successor query can use the numeric structure. Hashing answers membership in expected constant time and does not answer successor. A bitset answers both in O(u) time or with a word speedup that is still linear in the universe.<\/p>\n\n\n<p class=\"wp-block-paragraph\">The van Emde Boas layout is a recursive bitset. The high half of the key names the cluster and the low half names the index inside it. The summary is the same structure on the cluster ids. Pulling the minimum out of the cluster lets an empty-looking cluster still report a minimum in constant time and keeps the recurrence at one recursive call.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the algorithm guarantees<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">Member, insert, delete, successor, and predecessor are O(log log u). The bound depends on the universe, not on n. Extra memory for the textbook tree is \u0398(u). A hash-based implementation reduces the memory toward the number of occupied clusters and complicates the constant. The universe should be a power of two so the high and low halves are a bit split. Other sizes are rounded up.<\/p>\n\n\n<p class=\"wp-block-paragraph\">The structure is not a priority queue for arbitrary comparable objects. It is a set of integers in a fixed universe. A y-fast tree or a similar structure answers the same ordered-integer queries in expected O(log log u) time with O(n) space. Those are the space-efficient relatives.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>The working steps<\/strong><\/h4>\n\n<ol class=\"wp-block-list\">\n<li>If u is 2, the structure is a pair of bits. Member, insert, delete, and successor are constant-time table lookups.<\/li>\n<li>Otherwise split a key x into high = floor(x \/ \u221au) and low = x mod \u221au.<\/li>\n<li>Store the cluster minimum and maximum outside the recursive cluster. The cluster structure holds the other elements.<\/li>\n<li>Insert updates the minimum in constant time when the cluster was empty, and otherwise inserts low into cluster high and inserts high into the summary if this is the cluster&#8217;s first extra element.<\/li>\n<li>Successor of x looks inside cluster high for a successor of low. If none exists, the summary&#8217;s successor names the next nonempty cluster, and that cluster&#8217;s minimum is the answer.<\/li>\n<\/ol>\n\n\n<p class=\"wp-block-paragraph\">The time bound is logarithmic in the universe, which is a win only when u is much larger than any polynomial in n would suggest for a comparison tree, or when the worst-case integer bound itself is the point. Memory linear in u is unacceptable for a 64-bit universe. A practical ordered integer dictionary then uses a B-tree, a radix tree, or a y-fast tree.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Approaches that look simpler and fail<\/strong><\/h4>\n\n<figure class=\"wp-block-table\">\n<table>\n<thead>\n<tr>\n<th>Approach<\/th>\n<th>Why it fails when the cluster also stores its own minimum<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Store every element, including the minimum, in the recursive cluster<\/td>\n<td>Insert and successor then make more than one recursive call on some paths, and the clean log log recurrence is lost.<\/td>\n<\/tr>\n<tr>\n<td>Allocate the structure for a 64-bit universe up front<\/td>\n<td>\u0398(u) memory is 2^64 cells. The textbook layout assumes a moderate u, or a sparse representation has to replace it.<\/td>\n<\/tr>\n<tr>\n<td>Use it for floating-point keys<\/td>\n<td>The high and low split is an integer radix. Floats need a different order-preserving encoding before any integer structure sees them.<\/td>\n<\/tr>\n<tr>\n<td>Expect O(log log n) rather than O(log log u)<\/td>\n<td>The recurrence splits the universe. A universe of size n\u00b2 already costs about twice a universe of size n, regardless of how few keys are inserted.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n<p class=\"wp-block-paragraph\">Comparison-based ordered sets belong to red-black trees and B-trees. Expected constant membership without successor belongs to a hash table. A space-efficient integer successor structure is a y-fast tree or a similar hashed van Emde Boas variant.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>A working example<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">This Python fragment splits a key into high and low halves of a universe of 16. The cluster minimum stays outside the recursive cluster. Successor of 3 is 7, and successor of 7 is 15. It prints <code>7 15<\/code>.<\/p>\n\n<pre><code class=\"language-python\">class VEB:\n    def __init__(self, universe):\n        self.u = universe\n        self.min = None\n        self.max = None\n        if universe &gt; 2:\n            half = int(universe ** 0.5 + 0.5)\n            self.half = half\n            self.summary = VEB(half)\n            self.cluster = [VEB(half) for _ in range(half)]\n\n    def high(self, key):\n        return key \/\/ self.half\n\n    def low(self, key):\n        return key % self.half\n\n    def index(self, high, low):\n        return high * self.half + low\n\n    def insert(self, key):\n        if self.min is None:\n            self.min = self.max = key\n            return\n        if key &lt; self.min:\n            key, self.min = self.min, key\n        if self.u &gt; 2:\n            high, low = self.high(key), self.low(key)\n            if self.cluster[high].min is None:\n                self.summary.insert(high)\n                self.cluster[high].min = self.cluster[high].max = low\n            else:\n                self.cluster[high].insert(low)\n        if key &gt; self.max:\n            self.max = key\n\n    def successor(self, key):\n        if self.u == 2:\n            if key == 0 and self.max == 1:\n                return 1\n            return None\n        if self.min is not None and key &lt; self.min:\n            return self.min\n        high, low = self.high(key), self.low(key)\n        if self.cluster[high].max is not None and low &lt; self.cluster[high].max:\n            return self.index(high, self.cluster[high].successor(low))\n        succ = self.summary.successor(high)\n        if succ is None:\n            return None\n        return self.index(succ, self.cluster[succ].min)\n\ntree = VEB(16)\nfor key in (2, 3, 7, 15):\n    tree.insert(key)\nassert tree.successor(3) == 7 and tree.successor(7) == 15 and tree.successor(15) is None\nprint(tree.successor(3), tree.successor(7))\n<\/code><\/pre>\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Where it is used<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">A van Emde Boas tree is the theoretical integer priority queue with a log-log search. Running systems with integer priorities use a radix heap or buckets. The related idea that does show up is the van Emde Boas memory layout of a tree, which keeps recursive pieces in nearby cache lines.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>When you can drop this algorithm<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">Drop a dense van Emde Boas tree when u is large. The memory dominates. Keep the structure when the universe is moderate, successor and predecessor must be worst-case O(log log u), and a linear-in-u table is an acceptable size.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Why this stays published<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">We publish this so a search for a van Emde Boas tree returns the cluster split, the minimum stored aside, and the O(log log u) recurrence. <strong>A van Emde Boas tree supports ordered-set operations on a universe of size u in O(log log u) time by recursing on a \u221au cluster summary.<\/strong><\/p>\n\n\n<p class=\"wp-block-paragraph\">\u672c\u6587\u7531 HoHo \u8207 AI \u5354\u4f5c\u6574\u7406\uff0c\u6700\u5f8c\u66f4\u65b0\u65bc 2026 \u5e74 11 \u6708 13 \u65e5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Short answer: A van Emde Boas tree stores a set of integers from a universe 0, 1, \u2026, u\u22121 and supports insert, delete, member, successor, and predecessor in O(log log u) time. It splits the universe into \u221au clusters of \u221au values, keeps a summary structure on which clusters&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30,34],"tags":[],"class_list":["post-130","post","type-post","status-publish","format-standard","hentry","category-algorithms","category-trees"],"_links":{"self":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/130","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/comments?post=130"}],"version-history":[{"count":2,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/130\/revisions"}],"predecessor-version":[{"id":529,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/130\/revisions\/529"}],"wp:attachment":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/media?parent=130"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/categories?post=130"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/tags?post=130"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}