---
title: Priority Search Trees for Orthogonal Queries
url: https://www.emergentmind.com/topics/priority-search-trees
type: topic
---

# Priority Search Trees for Orthogonal Queries

A priority search tree (PST) is a binary data structure that organizes a set of planar points $P = \{p_1, \dotsc, p_n\}$, each $p = (x(p), y(p))$, to efficiently support three-dimensional orthogonal range queries of the form: “report (or optimize) over all points $p$ such that $x \in [a, b]$ and $y \geq c$.” PSTs are characterized by simultaneously maintaining a heap-order property with respect to the $y$-coordinate and an in-order property with respect to the $x$-coordinate. PSTs are foundational in computational geometry and pivotal for applications such as the efficient computation of maximal empty rectangles in two dimensions [1104.3076].

## 1. Definition and Invariants

A PST is recursively defined as follows. Given a non-empty point set $P$:

- Let $p^* = \operatorname*{arg\,max}_{p \in P} y(p)$. Make $p^*$ the root of the tree.
- Remove $p^*$ from $P$ to form $P' = P \setminus \{p^*\}$.
- Compute the median $x_{\mathrm{med}}$ of the $x$-coordinates in $P'$. Partition $P'$ into $P_\ell = \{p \in P' : x(p) \leq x_{\mathrm{med}}\}$ and $P_r = \{p \in P' : x(p) > x_{\mathrm{med}}\}$.
- Recursively build the left and right subtrees on $P_\ell$ and $P_r$.

The following invariants uniquely characterize a PST [1104.3076]:

- **Heap-order in $y$**: For every node $v$ and each child $w$ of $v$, $y(v) \geq y(w)$.
- **In-order in $x$**: An in-order traversal yields the points in non-decreasing order of $x$.

Each node maintains only the coordinates of its point; child-pointers or equivalent indices determine the structure.

## 2. Construction Algorithms and Complexity Analysis

The classical recursive build process involves, at each node, finding the max-$y$ element, computing the median $x$-coordinate, and partitioning accordingly. Each of these requires $O(n)$ time at each level, yielding the recurrence
$$
T(n) = T(n_\ell) + T(n_r) + \Theta(n)
$$
with $n_\ell \approx n_r \approx n/2$. Via the Master Theorem, this gives $T(n) = \Theta(n \log n)$ for total construction time.

Space consumption is $O(n)$ words for the nodes and pointers.

An in-place BFS-level construction is also possible. This layout stores the tree in the input array $P[1..n]$ in heap-like BFS order and uses a $2$-bit array $\mathrm{TAG}[1..k]$ $(k = \lceil \log_2(n+1)\rceil)$ to encode child-nulling at each level. The process, `BuildInPlacePST`, operates as follows:

- For each level $\ell$ from highest to lowest:
  - Nodes of level $\ell$ occupy $P[L_{\ell}+1..\ M_\ell]$ with $L_\ell = 2^{\ell-1}-1,\ M_\ell = \min(n, 2^{\ell}-1)$.
  - In this subarray, the root is extracted as the max-$y$ element, the remaining entries are in-place median-partitioned by $x$, and children/grouping is determined with assistance from $\mathrm{TAG}$.
- Only $O(\log n)$ bits are used for the $\mathrm{TAG}$ array and indexing, and the entire structure is stored in-place within $P[1..n]$.

Total construction time remains $O(n \log n)$; extra workspace is confined to $O(\log n)$ bits [1104.3076].

## 3. Array Layout and Indexing Formulas

After in-place construction, the layout has these properties:

- **BFS Shape**: Level $\ell$ nodes occupy $P[L_\ell+1..M_\ell]$.
- **Heap-order in $y$** and **In-order in $x$**: As in the pointer-based PST, maintained via construction.
- **Child indexing**: For a node $v$ at index $i$ in level $\ell$, the left and right children are located as:
$$
\text{left child}: 2i - \sum_{t=\ell+1}^k \mathrm{TAG}[t]
$$
$$
\text{right child}: 2i + 1 - \sum_{t=\ell+1}^k \mathrm{TAG}[t]
$$
This implicit formalism avoids explicit pointers and additional memory overhead.

## 4. Query Algorithms and Time Complexity

PSTs support classical three-dimensional orthogonal queries—e.g., find the minimum $x$ among $\{p \mid a \leq x(p) \leq b,\, y(p) \geq c\}$—in $O(\log^2 n)$ time using only $O(1)$ additional workspace. The algorithm proceeds as:

1. Descend from the root to the discriminant node $\pi$ where $[a, b]$ “splits.”
2. At each node, determine traversal direction by comparing $x$-predecessor and $x$-successor found by subtree walks (each $O(\log n)$).
3. At $\pi$, check $y(\pi) \geq c$; if so, recurse in the left/right subtrees, pruning any where root $y$ drops below $c$ or $x$-range is invalid.
4. The recursion for a subtree of height $h$ satisfies $Q(h) = 2Q(h-1) + O(\log n)$, yielding $Q(h) = O(h\log n) = O(\log^2 n)$.

Similar analysis holds for `MaxXInRectangle` and `MaxYInXRange`. Enumerative queries add an $O(\text{output})$ term [1104.3076].

_Table: Time/Space Complexity of Priority Search Trees_

| Operation          | Complexity                | Extra Workspace      |
|--------------------|--------------------------|---------------------|
| Build              | $O(n\log n)$             | $O(\log n)$ bits    |
| Query              | $O(\log^2 n)$            | $O(1)$              |
| Application (MERs) | $O(m+n\log^2 n)$         | $O(\log n)$ bits    |

## 5. Applications: Largest Empty Axis-Parallel Rectangle

A principal application of PSTs is in enumerating all maximal empty rectangles (MERs) within a bounding box $R$ given $n$ planar points. This is fundamental in VLSI design and spatial analysis.

The solution proceeds as:

- **Build the In-Place PST**.
- **Top–down and Bottom–up Sweeps**: For each pass (fixing the top/bottom on current PST maxima), two double-ended queues of size $O(\log n)$ maintain side candidates.
- At each step, the action is:
  - Pop the highest from $Q_\ell$ or $Q_r$.
  - Report the found MER.
  - Use PST queries (e.g., `MinXInRectangle` on lower $y$) to discover next side point.
- After each pass, re-heapify in $O(\log n)$ deletes the root.
- The total per pass is $O(\mu+\log n)$, where $\mu$ is the number of MERs found in that pass.
- Total complexity sums to $O(m + n\log^2 n)$, where $m$ is the number of MERs, and workspace remains $O(\log n)$ bits [1104.3076].

This establishes the PST as a space-efficient core structure for optimal enumeration of maximal empty axis-parallel rectangles.

## 6. Summary and Significance

Priority search trees implement an efficient mechanism for three-dimensional orthogonal range searching in planar point sets. Key contributions include:

- A recursive/data-driven structure balancing $y$-heap and $x$-order for optimal query resolution.
- In-place BFS-level construction in $O(n\log n)$ time and $O(\log n)$ extra bits, maintaining all invariants and enabling pointerless layouts.
- $O(\log^2 n)$ query time with $O(1)$ workspace.
- Immediate applications in computational geometry, notably the $O(m+n\log^2 n)$ complexity for maximal empty axis-parallel rectangle enumeration, with in-place spatial efficiency.

A plausible implication is that PSTs, due to their low workspace requirements and optimal query times, are well suited for embedded, memory-constrained, and high-performance spatial analytics workflows. These results are foundational for both theory and practice in computational geometry [1104.3076].

Source: https://www.emergentmind.com/topics/priority-search-trees