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

Algorithms [Sedgewick, Robert]

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

CHAPTER 2

matrices represented in this way is similar to our implementation for sparse polynomials, but is complicated by the fact that each node appears on two lists.

Data Structures

Even if there are no terms with zero coefficients in a polynomial or no zero elements in a matrix, an advantage of the linked list representation is that we don’t need to know in advance how big the objects that we’ll be processing are. This is a significant advantage that makes linked structures preferable in many situations. On the other hand, the links themselves can consume a significant part of the available space, a disadvantage in some situations. Also, access to individual elements in linked structures is much more restricted than in arrays.

We’ll see examples of the use of these data structures in various algorithms, and we’ll see more complicated data structures that involve more constraints on the elements in an array or more pointers in a linked representation. For example, multidimensional arrays can be defined which use multiple indices to access individual items. Similarly, we’ll encounter many “multidimensional” linked structures with more than one pointer per node. The tradeoffs between competing structures are usually complicated, and different structures turn out to be appropriate for different situations.

When possible it is wise to think of the data and the specific operations to be performed on it as an abstract data structure which can be realized in several ways. For example, the abstract data structure for polynomials in the examples above is the set of coefficients: a user providing input to one of the programs above need not know whether a linked list or an array is being used. Modern programming systems have sophisticated mechanisms which make it possible to change representations easily, even in large, tightly integrated systems.

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