Z-Order Curve

Source: Internet
Author: User
Document directory
  • Z-Order Curve

Http://en.wikipedia.org/wiki/Z-order_curve

Z-Order Curve

From Wikipedia, the free encyclopedia

Jump to: navigation, search

Not to be confused with Z curve or Z-order.

Four iterations of the Z-order curve.

Z-Order Curve iterations extended to three dimensions.

In mathematical analysis and computer science,Z-order,Morton order, OrMorton codeIs a space-filling curve which maps multidimen1_data to one dimension while preserving locality of the data points. it was introduced in 1966 by G. m. morton. [1] The Z-value of a point in multidimensions is simply calculated by interleaving the binary representations of its coordinate values. once the data are sorted into this ordering, any one-dimen1_data structure can be used such as binary search trees, B-trees, skip lists or (with low signiicant bits truncated) hash Tables. the resulting ordering can equivalently be described as the order one wocould get from a depth-first traversal of A Quadtree; because of its close connection with quadtrees, the Z-ordering can be used to efficiently construct quadtrees and related higher dimen1_data structures. [2]

Contents

[Hide]

  • 1 coordinate values
  • 2 efficiently building quadtrees
  • 3 Use with one-dimen1_data structures for range searching
  • 4 Related Structures
  • 5 applications in Linear Algebra
  • 6 See also
  • 7 References
  • 8 External links
Coordinate values

The figure below shows the Z-values for the two dimen=case with integer coordinates 0 ≤X≤ 7, 0 ≤Y≤ 7 (shown both in decimal and binary). interleaving the binary coordinate values yields binaryZ-Values as shown. ConnectingZ-Values in their numerical order produces the recursively Z-shaped curve.

Efficiently building quadtrees

As mentioned, the Z-ordering can be used to Efficiently build A Quadtree for a set of points. the basic idea is to sort the input set according to Z-order. once sorted, the points can either be stored in a binary search tree and used directly, which is called a linear quadtree, [3] or they can be used to build a pointer based quadtree.

The input points are usually scaled in each dimension to be positive integers, either as a fixed point representation over the unit range [0, 1] or corresponding to the machine word size. both representations are equivalent and allow for the highest order non-zero bit to be found in constant time. each square in the quadtree has a side length which is a power of two, and corner coordinates which are multiples of the side length. given any two points,Derived SquareFor the two points is the smallest square covering both points. The interleaving of bits from the X and Y components of each point is calledShuffleOf X and Y, and can be extended to higher dimensions. [2]

Points can be sorted according to their Shuffle without explicitly interleaving the bits. to do this, for each dimension, the most significant bit of the exclusive or of the coordinates of the two points for that dimension is examined. the dimension for which the most significant bit is largest is then used to compare the two points to determine their shuffle order.

The exclusive or operation masks off the higher order bits for which the two coordinates are identical. since the shuffle interleaves bits from higher order to lower order, identifying the coordinate with the largest most significant bit, identifies the first bit in the shuffle order which differs, and that coordinate can be used to compare the two points. [4] This is shown in the following Python code:

    def cmp_zorder(a, b):        j = 0        k = 0        x = 0        for k in range(dim):            y = a[k] ^ b[k]            if less_msb(x, y):                j = k                x = y        return a[j] - b[j]

One way to determine whether the most significant Smaller is to compare the floor of the base-2 logarithm of each point. it turns out the following operation is equivalent, and only requires exclusive or operations [4]:

    def less_msb(x, y):        return x < y and x < (x ^ y)

It is also possible to compare floating point numbers using the same technique.Less_msbFunction is modified to first compare the exponents. Only when they are equal is the standardLess_msbFunction used on the mantissas. [5]

Once the points are in sorted order, two properties make it easy to build a quadtree: the first is that the points contained in a square of the quadtree form a contiguous interval in the sorted order. the second is that if more than one child of a square contains an input point, the square isDerived SquareFor two adjacent points in the sorted order.

For each adjacent pair of points, the derived square is computed and its side length determined. for each derived Square, the interval containing it is bounded by the first larger square to the right and to the left in sorted order. [2] each such interval corresponds to a square in the quadtree. the result of this is a compressed quadtree, where only nodes containing input points or two or more children are present. A non-compressed quadtree can be built by restoring the missing nodes, if desired.

Rather than building a pointer based quadtree, the points can be maintained in sorted order in a data structure such as a binary search tree. this allows points to be added and deleted in O (log n) time. two quadtrees can be merged by merging the two sorted sets of points, and removing duplicates. point location can be done by searching for the points preceding and following the query point in the sorted order. if the quadtree is compressed, the predecessor node found may be an arbitrary leaf inside the compressed node of interest. in this case, it is necessary to find the predecessor of the least common ancestor of the query point and the leaf found. [6]

Use with one-dimen1_data structures for range searching

Although preserving locality well, for efficient range searches an algorithm is necessary for calculating, from a point encountered in the data structure, the next Z-value which is in the multidimensponsearch range:

In this example, the range being queried (X= 2,..., 3,Y= 2,..., 6) is indicated by the dotted rectangle. Its highest Z-value (max) is 45. In this example, the valueF= 19 is encountered when searching a Data Structure in increasing Z-value ction, So we wowould have to search in the interval between F and max (hatched area ). to speed up the search, one wocould calculate the next Z-value which is in the search range, called bigmin (36 in the example) and only search in the interval between bigmin and max (Bold values), thus skipping most of the hatched area. searching in decreasing direction is analogous with litmax which is the highest Z-value in the query range lower than F. the bigmin problem has first been stated and Its Solution shown in tropf and Herzog. [7] This solution is also used in UB-trees ("getnextz-address "). as the approach does not depend on the one dimen1_data structure chosen, there is still free choice of structuring the data, so well known methods such as balanced trees can be used to associate with dynamic data (in contrast for example to R-trees where special considerations are necessary ). similarly, this independence makes it easier to independate the method into existing databases.

Applying the method handle (according to the data structure at hand), optionally in both increasing and decreasing direction, too highly implements multidimensponrange search which is important in both implements cial and technical applications, e.g. as a procedure underlying nearest neighbor searches. z-order is one of the few multidimen1_access methods that has found its way into relational cial database systems (Oracle Database 1995, [8] transbase 2000 [9]).

As long ago as 1966, G. m. morton proposed Z-order for file sequencing of a static two dimen1_geographical database. areal data units are contained in one or a few quadratic frames represented by their sizes and lower right corner Z-values, the sizes complying with the Z-order hierarchy at the corner position. with high probability, changing to an adjacent frame is done with one or a few relatively small scanning steps.

[Edit] Related Structures

As an alternative, the Hilbert curve has been suggested as it has a better order-preserving behaviour, but here the calculations are much more complicated, leading to significant processor overhead. bigmin source code for both Z-curve and Hilbert-curve were described in a patent by H. tropf. [10]

For a recent overview on multidimen1_data processing, including e.g. Nearest Neighbor searches, see Hanan Samet's textbook. [11]

[Edit] applications in Linear Algebra

The strassen Algorithm for matrix multiplication is based on splitting the matrices in four blocks, and then recursively each of these blocks in four smaller blocks, until the blocks are single elements (or more prtically: until reaching matrices so small that the trivial algorithm is faster ). arranging the Matrix Elements in Z-order then improves locality, and has the additional advantage (compared to row-or column-Major ordering) that the subroutine for multiplying two blocks does not need to know the total size of the matrix, but only the size of the blocks and their location in memory. valid use of strassen multiplication with Z-order has been demonstrated, see valsalam and skjellum's 2002 paper [12].

See also
  • UB-tree
  • Hilbert Curve
  • Hilbert R-tree
  • Spatial Index
  • Locality preserving hashing
  • Matrix Representation
  • Linear Algebra
References
  1. ^Morton, g.m. (1966 ),A computer oriented geodetic data base; and a new technique in file sequencing, Technical Report, Ottawa, Canada: IBM Ltd.
  2. ^A B CBern, M.; eppstein, D.; Teng, S.-H. (1999), "parallel construction of quadtrees and quality triangulations ",Int. J. Comp. Geom. & Appl. 9(6): 517-532, doi: 10.1142/s0218195999000303.
  3. ^Garganini, I. (1982), "an alternative tive way to represent quadtrees ",Communications of the ACM 25(12): 905-910.
  4. ^A BChan, T. (2002), "closest-Point Problems simplified on The Ram ",ACM-SIAM Symposium on discrete AlgorithmsHttp://www.cs.uwaterloo.ca /~ Tmchan/ram_soda.ps.gz.
  5. ^Connor, M.; Kumar, P (2009), "Fast Construction of K-Nearest Neighbor graphs for Point Clouds ",IEEE Transactions on visualization and computer graphicsHttp://compgeom.com /~ Piyush/papers/tvcg_stann.pdf
  6. ^Har-Peled, S. (2010 ),Data Structures for geometric ApproximationHttp://www.madalgo.au.dk/img/SS2010/Course%20Material/Data-Structures%20for%20Geometric%20Approximation%20by%20Sariel%20Har-Peled.pdf
  7. ^Tropf, H.; Herzog, H. (1981), "multidimen1_range search in dynamically balanced trees ",Angewandte Informatik 2Http://www.vision-tools.com/h-tropf/multidimensionalrangequery.pdf: 71-77.
  8. ^Gaede, Volker; Guenther, Oliver (1998), "multidimen1_access methods ",ACM computing surveys 30(2): 170-231, doi: 10.1145/280277.280279, http://www-static.cc.gatech.edu/computing/Database/readinggroup/articles/p170-gaede.pdf.
  9. ^Ramsak, Frank; Markl, Volker; fenk, Robert; zirkel, Martin; elhardt, Klaus; Bayer, Rudolf (2000), "Integrating the UB-tree into a database system kernel ",Int. conf. on very large databases (vldb), Pp. 263-272, http://www.mistral.in.tum.de/results/publications/RMF+00.pdf.
  10. ^US 7321890, tropf, H., "database system and method for organizing data elements according to a Hilbert curve", issued January 22,200 8.
  11. ^Samet, H.264 ),Foundations of multidimenures and metric data structures, San Francisco: Morgan-Kaufmann.
  12. ^Vinod valsalam, Anthony skjellum: A Framework for high-performance matrix multiplication based on hierarchical semantic actions, algorithms and optimized low-level kernels. concurrency and computation: practice and experience 14 (10): 805-839 (2002)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.