11.07.2015 Views

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

440 Chap. 13 Advanced Tree <strong>Structures</strong>Example 13.4 Consider a search for value 89 in the splay tree of Figure13.10(a). The splay tree’s search oper<strong>at</strong>ion is identical to searching ina BST. However, once the value has been found, it is splayed to the root.Three rot<strong>at</strong>ions are required in this example. The first is a zigzig rot<strong>at</strong>ion,whose result is shown in Figure 13.10(b). The second is a zigzag rot<strong>at</strong>ion,whose result is shown in Figure 13.10(c). The final step is a single rot<strong>at</strong>ionresulting in the tree of Figure 13.10(d). Notice th<strong>at</strong> the splaying process hasmade the tree shallower.13.3 Sp<strong>at</strong>ial <strong>D<strong>at</strong>a</strong> <strong>Structures</strong>All of the search trees discussed so far — BSTs, AVL trees, splay trees, 2-3 trees,B-trees, <strong>and</strong> tries — are designed for searching on a one-dimensional key. A typicalexample is an integer key, whose one-dimensional range can be visualized as anumber line. These various tree structures can be viewed as dividing this onedimensionalnumber line into pieces.Some d<strong>at</strong>abases require support for multiple keys. In other words, records canbe searched for using any one of several key fields, such as name or ID number.Typically, each such key has its own one-dimensional index, <strong>and</strong> any given searchquery searches one of these independent indices as appropri<strong>at</strong>e.A multidimensional search key presents a r<strong>at</strong>her different concept. Imagineth<strong>at</strong> we have a d<strong>at</strong>abase of city records, where each city has a name <strong>and</strong> an xycoordin<strong>at</strong>e.A BST or splay tree provides good performance for searches on cityname, which is a one-dimensional key. Separ<strong>at</strong>e BSTs could be used to index the x-<strong>and</strong> y-coordin<strong>at</strong>es. This would allow us to insert <strong>and</strong> delete cities, <strong>and</strong> loc<strong>at</strong>e themby name or by one coordin<strong>at</strong>e. However, search on one of the two coordin<strong>at</strong>es isnot a n<strong>at</strong>ural way to view search in a two-dimensional space. Another option is tocombine the xy-coordin<strong>at</strong>es into a single key, say by conc<strong>at</strong>en<strong>at</strong>ing the two coordin<strong>at</strong>es,<strong>and</strong> index cities by the resulting key in a BST. Th<strong>at</strong> would allow search bycoordin<strong>at</strong>e, but would not allow for efficient two-dimensional range queries suchas searching for all cities within a given distance of a specified point. The problemis th<strong>at</strong> the BST only works well for one-dimensional keys, while a coordin<strong>at</strong>e is <strong>at</strong>wo-dimensional key where neither dimension is more important than the other.Multidimensional range queries are the defining fe<strong>at</strong>ure of a sp<strong>at</strong>ial applic<strong>at</strong>ion.Because a coordin<strong>at</strong>e gives a position in space, it is called a sp<strong>at</strong>ial <strong>at</strong>tribute.To implement sp<strong>at</strong>ial applic<strong>at</strong>ions efficiently requires the use of sp<strong>at</strong>ial d<strong>at</strong>a structures.Sp<strong>at</strong>ial d<strong>at</strong>a structures store d<strong>at</strong>a objects organized by position <strong>and</strong> are animportant class of d<strong>at</strong>a structures used in geographic inform<strong>at</strong>ion systems, computergraphics, robotics, <strong>and</strong> many other fields.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!