Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Algorithms [Sedgewick, Robert]

.pdf
Скачиваний:
143
Добавлен:
02.05.2014
Размер:
4.8 Mб
Скачать

26. Range Searching

Given a set of points in the plane, it is natural to ask which of those points fall within some specified area. “List all cities within 50 miles of Providence” is a question of this type which could reasonably be asked if a

set of points corresponding to the cities of the U.S. were available. When the geometric shape is restricted to be a rectangle, the issue readily extends to non-geometric problems. For example, “list all those people between 21 and 25 with incomes between $60,000 and $100,000” asks which “points” from a file of data on people’s names, ages, and incomes fall within a certain rectangle in the age-income plane.

Extension to more than two dimensions is immediate. If we want to list all stars within 50 light years of the sun, we have a three-dimensional problem, and if we want the rich young people of the second example in the paragraph above to be tall and female as well, we have a four-dimensional problem. In fact, the dimension can get very high for such problems.

In general, we assume that we have a set of records with certain attributes that take on values from some ordered set. (This is sometimes called a database, though more precise and complete definitions have been developed for this important term.) The problem of finding all records in a database which satisfy specified range restrictions on a specified set of attributes is called range searching. For practical applications, this is a difficult and important problem. In this chapter, we’ll concentrate on the two-dimensional geometric problem in which records are points and attributes are their coordinates, then we’ll discuss appropriate generalizations.

The methods that we’ll look at are direct generalizations of methods that we have seen for searching on single keys (in one dimension). We presume that many queries will be made on the same set of points, so the problem splits into two parts: we need a preprocessing algorithm, which builds the given points into a structure supporting efficient range searching, and a range-searching

335

Соседние файлы в предмете Алгоритмы