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

Algorithms [Sedgewick, Robert]

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

ELEMENTARY SEARCHING METHODS

185

way of implementing binary search trees to aid in searching large arrays of records is preferred for many applications, since it avoids the extra expense of copying keys as in the previous paragraph, and it avoids the overhead of the storage allocation mechanism implied by new. The disadvantage is that space is reserved with the record array for links which may not be in use, which could lead to problems with large arrays in a dynamic situation.

190

This ensures that we could handle the situation at the bottom even if E were to go into a 4-node (for example, if we were inserting another A instead). Now, the insertion of E, X, A, M, P, L, and E finally leads to the tree:

The above example shows that we can easily insert new nodes into 2-3- 4 trees by doing a search and splitting 4-nodes on the way down the tree. Specifically, every time we encounter a 2-node connected to a 4-node, we should transform it into a 3-node connected to two 2-nodes:

and every time we encounter a 3-node connected to a 4-node, we should transform it into a 4-node connected to two 2-nodes:

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