ArticleslgStudy

computer science

PH-tree

PH-tree is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand PH-tree rather than just read about it. In short: The PH-tree is a tree data structure used for spatial indexing of multi-dimensional data (keys) such as geographical coordinates, points, feature vectors, rectangles or bounding boxes. The PH-tree is space partitioning index with a structure similar to that of a quadtree or octree.

PH-tree — main illustration
PH-tree — illustration

Key takeaways

  • PH-tree belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect PH-tree to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of PH-tree from memory before moving on to harder problems.

Reference excerpt

The PH-tree is a tree data structure used for spatial indexing of multi-dimensional data (keys) such as geographical coordinates, points, feature vectors, rectangles or bounding boxes. The PH-tree is space partitioning index with a structure similar to that of a quadtree or octree. However, unlike quadtrees, it uses a splitting policy based on tries and similar to Crit bit trees that is based on the bit-representation of the keys. The bit-based splitting policy, when combined with the use of different internal representations for nodes, provides scalability with high-dimensional data. The bit-representation splitting policy also imposes a maximum depth, thus avoiding degenerated trees and the need for rebalancing.

Overview The basic PH-tree is a spatial index that maps keys, which are d-dimensional vectors with integers, to user defined values. The PH-tree is a multi-dimensional generalization of a Crit bit tree in the sense that a Crit bit tree is equivalent to a PH-tree with 1-dimensional keys. Like the Crit bit tree, and unlike most other spatial indexes, the PH-tree is a map rather than a multimap. A d-dimensional PH-tree is a tree of nodes where each node partitions space by subdividing it into 2d quadrants (see below for how potentially large nodes scales with high dimensional data). Each quadrant contains at most one entry, either a key-value pair (leaf quadrant) or a key-subnode pair. For a key-subnode pair, the key represents the center of the subnode. The key is also the common prefix (bit-representation) of all keys in the subnode and its child subnodes. Each node has at least two entries, otherwise it is merged with the parent node. Some other structural properties of PH-trees are:

They are 2n-ary trees. They are inherently unbalanced but imbalance is limited due to their depth being limited to the bit width of the keys, e.g. to 32 for a d-dimensional key with 32-bit integers. Insertion or removal operations cause exactly one node to be modified and potentially a second node to be added or removed. This can be useful for concurrent implementations. This also means little variation in modification cost. Their structure is independent from insertion/removal order.

Splitting strategy Similar to most quadtrees, the PH-tree is a hierarchy of nodes where every node splits the space in all d dimensions. Thus, a node can have up to 2d subnodes, one for each quadrant.

Quadrant numbering The PH-tree uses the bits of the multi-dimensional keys to determine their position in the tree. All keys that have the same leading bits are stored in the same branch of the tree. For example, in a node at level L, to determine the quadrant where a key should be inserted (or removed or looked up), it looks at the L's bit of each dimension of the key. For a 3D node with 8 quadrants (forming a cube) the L's bit of the first dimension of the key determines whether the target quadrant is on the left or the right of the cube, the L's bit of the second dimension determines whether it is at the front or the back, and the L's bit of the third dimension determines bottom vs top, see picture.

1D example Example with three 1D keys with 8-bit values: k0={1}base 10={00000001}base 2, k1={4}10={00000100}2 and k2={35}10={00100011}2. Adding k0 and k1 to an empty tree results in a single node. The two keys first differ in their 6th bit so the node has a level L=5 (starting with 0). The node has a 5-bit prefix representing the common 5 bits of both keys. The node has two quadrants, each key is stored in one quadrant. Adding a third key k3 results in one additional node at L=2 with one quadrant containing the original node as subnode and the other quadrant containing the new key k2.

2D example With 2D keys every node has 2d=4 quadrants. The position of the quadrant where a key is stored is extracted from the respective bits of the keys, one bit from each dimension. The four quadrants of the node form a 2D hypercube (quadrants may be empty). The bits that are extracted from the keys form the hypercube address h, for k0→h={00}2 and for k1→h={01}2. h is effectively the position of the quadrant in the node's hypercube.

Node structure The ordering of the entries in a node always follows Z-ordering. Entries in a node can, for example, be stored in fixed size arrays of size 2d. h is then effectively the array index of a quadrant. This allows lookup, insert and remove with O(1) and there is no need to store h. Space complexity is however O(2d) per node, so it is less suitable for high dimensional data. Another solution is to store entries in a sorted collection, such as dynamic arrays and/or B-trees. This slows down lookup operations to O(log⁡nnode_entries) but reduces memory consumption to O(nnode_entries). The original implementation aimed for minimal memory consumption by switching between fixed and dynamic array representation depending on which uses less memory. Other implementations [1][2] do not switch dynamically but use fixed arrays for d≲4, dynamic arrays for d≲8 and B-trees for high dimensional data.

Operations Lookup, insertion and removal operations all work very similar: find the correct node, then perform the operation on the node. Window queries and k-nearest-neighbor searches are more complex.

Lookup The Lookup operation determines whether a key exists in the tree. It walks down the tree and checks every node whether it contains a candidate subnode or a user value that matches the key.

function lookup(key) is entry ← get_root_entry() // if the tree is not empty the root entry contains a root node while entry != NIL && entry.is_subnode() do node ← entry.get_node() entry ← node.get_entry(key) repeat return entry // entry can be NIL

function get_entry(key) is node ← current node h ← extract_bits_at_depth(key, node.get_depth()} entry ← node.get_entry_at(h) return entry // entry can be NIL

Insert The Insert operation inserts a new key-value pair into the tree unless they key already exists. The operation traverses the tree like the Lookup function and then inserts the key into the node. There are several cases to consider:

… excerpt ends here. Continue reading the full article.

Illustrations

PH-tree: Example of a PH-tree with three keys added, resulting in two nodes. A root node (red) and a subnode (blue).
Example of a PH-tree with three keys added, resulting in two nodes. A root node (red) and a subnode (blue).
PH-tree: Example of a PH-tree with two 2D keys in one node
Example of a PH-tree with two 2D keys in one node

Worked examples

Example 1 — a first encounter with PH-tree

Start with the simplest possible case. Write down what PH-tree claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to PH-tree before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about PH-tree ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of PH-tree

In research
PH-tree appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses PH-tree in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
PH-tree is common in secondary-school and first-year university syllabi. It links to neighbouring topics Database index techniques, Geometric data structures, Trees (data structures), so understanding it makes those chapters shorter.
In everyday life
Look for PH-tree outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “PH-tree” →

How to study PH-tree in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what PH-tree means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain PH-tree out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is PH-tree in simple terms?

The PH-tree is a tree data structure used for spatial indexing of multi-dimensional data (keys) such as geographical coordinates, points, feature vectors, rectangles or bounding boxes. The PH-tree is space partitioning index with a structure similar to that of a quadtree or octree.

Why does PH-tree matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study PH-tree?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on PH-tree.

Tags

  • Database index techniques
  • Geometric data structures
  • Trees (data structures)

Keep exploring