Two-tone tree

A two-tone tree is a particular type of binary Tree of research, which is a Structure of data used in theoretical Informatique. The two-tone trees were invented in 1972 by Rudolf Bayer which named them " symetric binary B-trees". Their principal interest lies in logarithmic curve complexity of the following operations: insertion, research and suppression. They are however rather complex to implement, because the operations of insertion and suppression call upon many case studies. Lastly, they are isomorphous with the trees 2-3-4.

Use and advantages

The two-tone trees, as well as the trees AVL, offer the best guaranteed over the time of insertion, suppression and research in the unfavourable cases. This not only enables them to be then usable in applications in real-time, but also to be used like base of other structures of data for execution time guaranteed in the unfavourable cases, for example in algorithmic Géométrie.

Properties

A two-tone tree is a binary tree of research in which each node has an attribute supplémentaire : its color, which is either red or black . In addition to the restrictions imposed on the binary trees of research, one adds the rules suivantes :
  1. a node is either red or black.
  2. the root is black.
  3. All the sheets are black (or the Nile ).
  4. If a node is red, its two descendants are black.
  5. the way of each sheet to the root contains the same number of black nodes.

These constraints imply an important property of the two-tone trees: the longest possible way of a root to a sheet can be twice more long only smallest possible. There is thus a tree almost balanced. Like the operations of insertion, of research and suppression require in worst case a time proportional to the size of the tree, the two-tone trees remain effective, contrary to the binary trees of ordinary research.

To include/understand how these constraints guarantee the property above, it is enough to realize that no way can have two consecutive red nodes because of property 4. The smallest theoretical way of the root to a sheet does not contain whereas black nodes while largest alternates between the red and black nodes. And as according to property 5, each one of these ways contain the same number of black nodes, most main road can be twice larger only smallest.

A source of usual confusion with these properties is that they are written on the assumption that each sheet of the tree are “  sheets nil  ”, which does not contain data and which are used to show that the tree stops here. These nodes are often omitted in the drawings, which then seem to be in contradiction with property 3 whereas they are not it.

Operations

Research on a two-tone tree is carried out exactly as in the binary trees of research. However, after an insertion or a suppression, the properties of the two-tone tree can be violated. The restoration of these properties requires a small number ( O (ln N) ) of modifications of the colors (which are very fast in practice) and not more than three rotations (two for insertion). This makes it possible to have an insertion and a suppression in O (ln N) but largely complicates the operations because of the great number of cases to be studied.

Insertion

First stage: to go down starting from the root to research of the sheet where the element should be inserted.

Second phase: on this way, when a node has its two red wires, one reverses the colors of has and his sons. Moreover, if the father of has is itself red, it is necessary to make a rotation on the grandfather of has before continuing the descent.

Third stage: the addition itself is always done on 1 red node because the new element is added as a twin. If the father of the added node is red but does not have red father, it is necessary to carry out a rotation as with the second phase.

Suppression

See too

References

  • an applet Java with trees AVL, Splay and two-tone

Random links:Miranda Richardson | White cochineal | Breton national committee | Gaza (Antiquity) | Thornley | No the withdrawal (sport of combat) | Jymie_Merritt