110 likes | 118 Views
Learn how to interpret queries geometrically, process data efficiently, and optimize search structures for multi-dimensional datasets. Discover the power of range trees and layered range trees.
E N D
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 multi- dimensional position (mostly 2D or 3D) of e.g. some unit on a map. 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 Multi-dimensional Range Tree 2D Range Tree What? An ordered tree data structure to 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. Source: Lecture 10 of the course “(Geometric) Data Structures”, ISG, Universität Magdeburg. (link) Source: Homepage of the course “(Geometric) Data Structures”, ISG, Universität Magdeburg. (link)
Range tree Building a range tree from a data set containing n points space: O(n log n) time: 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: Traverse S1: O(k) Follow pointer: O(1) Traverse S2: O(k) Source: Lecture 6 of the course “Computational Geometry”, Joachim Gudmundsson. (link)
Layered range tree Range tree Fractional cascading Layered range tree Example: Buildup time: O(n logd n) Query time: O(k + logd n) Gain: log n 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.” • Naïvely processing orthogonal range queries causes a performance disaster.O(n²) • 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) • 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?