Transcript Slide 1

Databases and games: indexing
Orthogonal range queries & Layered range trees
Nick Gaens
Orthogonal range queries
Queries in a database can be interpreted
geometrically
 by transforming records into points in a
multi-dimensional space
 and than querying that set of points
instead.
Source: "Orthogonal range searching" by Antoine Vigneron, INRA. (link)
Orthogonal range queries
Relation to games?
Orthogonal: determination of a multidimensional position (mostly 2D
3D) of e.g. some unit on a
map.
or
Range:
very frequently used. E.g. “select
all units that are at most 2 positions
away from my current location”.
Processing
Example: “For each friendly unit, count all
enemy units on some 2D map.”
Naïve solution: O(n²) 
Can be improved by introducing indices,
structured in e.g. a tree.
Range tree
2D Range
Tree
Range
Tree to
What? AnMulti-dimensional
ordered
tree data
structure
hold a list of points.
What for? It allows all points within a given
range to be efficiently retrieved
When? Typically used for structuring two- or
higher-dimensional data sets.
Lecture 10 of the course “(Geometric) Data Structures”, ISG,
Source: Homepage
Universität Magdeburg. (link)
Range tree
Building a range tree from a data set
containing n points
space:
time:
O(n log n)
O(n log n)
Querying a multi-dimensional range tree
time:
O((log n)d + k)
Optimizations
Simple:
 ignore categorical data, since it can
be replaced by a hash table with O(1)
 position static and frequently updated
parameters in such a way that
updating the tree has a minimal cost
Less simple:
 fractional cascading
Fractional cascading
Searching in similar lists, especially sublists.
Main idea is to perform queries in the
associated structures in time O(1 + k),
instead of O(log n + k).
Query time:
1. Traverse S1: O(k)
2. Follow pointer: O(1)
3. Traverse S2: O(k)
Source: Lecture 6 of the course “Computational Geometry”, Joachim
Gudmundsson. (link)
Layered range tree
Example:
Range tree
Buildup time: O(n logd n)
Query time: O(k + logd n)
Fractional cascading Gain: log n
Layered range tree
Buildup time: O(n logd-1 n)
Query time: O(k + logd-1 n)
Source: Lecture 6 of the course “Computational Geometry”, Joachim
Gudmundsson. (link)
Conclusions
Example: “For each friendly unit, count all enemy units on
some 2D map.”
1.
Naïvely processing orthogonal range queries causes a
performance disaster.
O(n²)
2.
Relatively simple data structures (range trees) can be
used to query multi-dimensional data sets quite efficiently.
Buildup: O(n logd n) and query: O(n logd n + k)
3.
Such a range tree can even be optimized further by
introducing fractional cascading, resulting in a layered
range tree.
Buildup: O(n logd-1 n) and query: O(n logd-1 n + k)
Q&A
Questions?