Van Emde Boas Tree - Problem
The Van Emde Boas Tree (vEB Tree) is an advanced data structure that supports predecessor and successor queries on integers in O(log log U) time complexity, where U is the universe size.
Your task is to implement a Van Emde Boas Tree that supports the following operations:
insert(x): Insert integer x into the treedelete(x): Remove integer x from the treepredecessor(x): Find the largest integer less than x in the tree (-1 if none exists)successor(x): Find the smallest integer greater than x in the tree (-1 if none exists)contains(x): Check if integer x exists in the tree
Given a list of operations, execute them and return the results of all query operations (predecessor, successor, contains).
The universe size U is fixed at 2^16 = 65536, so all integers are in range [0, 65535].
Input & Output
Example 1 — Basic Operations
$
Input:
operations = [["insert",5],["insert",10],["insert",15],["predecessor",12],["successor",12]]
›
Output:
[10,15]
💡 Note:
Insert 5, 10, 15 into the tree. Predecessor of 12 is 10 (largest element < 12). Successor of 12 is 15 (smallest element > 12).
Example 2 — Contains Query
$
Input:
operations = [["insert",8],["contains",8],["contains",9]]
›
Output:
[true,false]
💡 Note:
Insert 8 into tree. Query contains(8) returns true, contains(9) returns false since 9 was never inserted.
Example 3 — No Predecessor
$
Input:
operations = [["insert",20],["insert",30],["predecessor",15]]
›
Output:
[-1]
💡 Note:
Tree contains 20 and 30. Predecessor of 15 doesn't exist since all elements are ≥ 15, so return -1.
Constraints
- 1 ≤ operations.length ≤ 1000
- Each operation is one of: ["insert", x], ["delete", x], ["contains", x], ["predecessor", x], ["successor", x]
- 0 ≤ x ≤ 65535 (fits in 16 bits)
- All query operations (contains, predecessor, successor) return results
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code