orthogonal range trees
orthogonal range trees
Orthogonal range trees are a hierarchical data structure that enables efficient range
searching in multi-dimensional space.
They use recursive decomposition, with each tree node containing a secondary
range tree for the remaining dimensions.
Query time: O((logn)d+k) (output-sensitive).
Space complexity: O(n(logn)d−1).
This method is widely used for database indexing, geometric applications, and
multidimensional data queries.
Step 1: Understanding the Input
We are given a set of 9 points in 2D space.
Each point has two coordinates (x,y)(x, y)(x,y).
For example, from the image, the points appear to be:
(1,1),(1,5),(2,8),(3,3),(3,5),(4,6),(6,4),(7,6),(8,7),(7,9)
Our goal is to build a 2D orthogonal range tree, which consists of:
1. Primary Search Tree on X-coordinate (1D Range Tree)
2. Secondary Search Trees (Y-trees) for Each Node
(6)
/ \
(3) (8)
/ \ /
(1) (5) (7)
/\ / \
(0) (2) (4) (7)
Each node in this tree stores all points in its subtree.
Final Summary
1. Sort points by X-coordinates.
2. Build a balanced BST on X-values (Primary Tree).
3. For each node in the X-tree, build a Y-tree (Secondary Search Structure).
4. Perform range queries efficiently using both X and Y trees.
First, we sort them by their X-coordinates:
(1,1),(1,5),(2,8),(3,3),(3,5),(4,6),(6,4),(7,6),(7,9),(8,7)(1,1), (1,5), (2,8), (3,3), (3,5), (4,6),
(6,4), (7,6), (7,9), (8,7)(1,1),(1,5),(2,8),(3,3),(3,5),(4,6),(6,4),(7,6),(7,9),(8,7)
Step 2: Choose the Median as the Root
To ensure the tree remains balanced, we select the median of the sorted list as the root node.
The sorted list has 10 points (even count).
The median is the 6th element in the sorted list (0-based index 5).
The median X-coordinate is 6, so 6 is chosen as the root.
markdown
CopyEdit
(6)
Step 3: Recursively Build the Left and Right Subtrees
Now, we divide the remaining points into two halves:
Left subtree: Points with X<6X < 6X<6
Right subtree: Points with X>6X > 6X>6
Left Subtree Construction
Points with X<6X < 6X<6:
(1,1),(1,5),(2,8),(3,3),(3,5),(4,6)(1,1), (1,5), (2,8), (3,3), (3,5), (4,6)(1,1),(1,5),(2,8),(3,3),(3,5),
(4,6)
Median = 3 (middle of the sorted left half)
Root of left subtree = 3
markdown
CopyEdit
(6)
/
(3)
Now, split again:
Left of 3: (1,1),(1,5),(2,8)(1,1), (1,5), (2,8)(1,1),(1,5),(2,8) → Median = 1 (Root)
Right of 3: (3,5),(4,6)(3,5), (4,6)(3,5),(4,6) → Median = 5 (Root)
markdown
CopyEdit
(6)
/
(3)
/ \
(1) (5)
Right Subtree Construction
Points with X>6X > 6X>6:
(7,6),(7,9),(8,7)(7,6), (7,9), (8,7)(7,6),(7,9),(8,7)
Median = 7 (middle of the sorted right half)
Root of right subtree = 7
markdown
CopyEdit
(6)
/ \
(3) (7)
Now, split again:
Left of 7: (7,6)(7,6)(7,6) → No split needed.
Right of 7: (8,7)(8,7)(8,7) → No split needed.