Weighted binary search tree

from Wikipedia, the free encyclopedia
A binary search tree with 2 nodes and weight information (red)

In computer science , a weighted binary search tree is an expression of the abstract data structure binary search tree , in which each node is assigned a weight (access probability) in addition to keys and other data . (For the sake of completeness, this is also assigned to its neighboring intervals.)

The weighted path length of the tree is to be optimized .

The weight is linked to the key, so allowing multiple objects ("duplicates") with the same key does not make sense.

If weights are not known at all or if they are practically the same, height-balanced trees are a good choice. One example is the AVL tree , which can be viewed as optimized for the weighted path length with unit weights.

Examples

If the tree is static, i.e. insert or delete operations are irrelevant, then the Bellman algorithm can be used , which constructs an optimal weighted binary search tree. Its efficiency is given even if the weights are only roughly known.

Geometric distribution

In the geometrical weight distribution for with applies . A binary tree is recursively structured as follows: The key that has the greatest remaining weight is made one of the two sons and the root of the next subtree. Since there is no longer a key on his side, the other son remains empty. Such a binary tree has the constant weighted path length , although it corresponds to a linear list. If the arrangement of the keys fits exactly to this binary tree (so that it is a binary search tree), then it is at optimal, because downgrading the root of a subtree worsens the mean value. There are then very rare search queries that are answered in linear time with the optimal weighted binary search tree.

Natural vocabularies

In English, the probability of the -t most common word occurring is approximate

.

The weighted path length of an optimal binary search tree for all English words is approximate .

Dynamic weights

If inserting or removing operations are important, the weights must also be maintained in principle. In the borderline case even when searching, as this at least changes the access statistics.

Mehlhorn describes "almost optimal binary search trees".

In the case of the splay trees , despite a completely different approach, the nodes that are most frequently mentioned are also flushed near the roots.

Access distribution and weighted path length

Fig. 4: (Optimal) binary search tree with weights (red).

Let be a set of keys from a totally (quasi) ordered reservoir of keys, let further be or frequencies with which the element (or equivalence class or interval) is accessed, whereby for resp. for . (Let and additional non- belonging elements with the usual meaning.) The - tuple

means access distribution for the crowd when everyone is. becomes the access probability distribution if is.

Let us now be a search tree for the set with an access distribution , and let the depth of the (inner) node and the depth of the leaf be (see Fig. 4; binary search tree terminology in Fig. 1B). We consider the search for an element . If so , we compare it to elements in the tree. If so , we compare it to elements in the tree. So is

the weighted path length sum of the tree (with the access distribution ) ; is a probability distribution, then is the weighted path length , the weighted search depth, or the mean number of comparisons required. Fig. 4 shows a search tree which , with a value of, is optimal for the access distribution .

literature

  • Kurt Mehlhorn: data structures and efficient algorithms. Teubner, Stuttgart 1988, ISBN 3-519-12255-3 .

Individual evidence

  1. after #Mehlhorn a. a. OS 147