The 2–4 Trees
Explore the structure and properties of 2-4 trees, including their height and degree rules, and learn how adding and removing leaves maintains balance. Understand how red-black trees use colors to simulate 2-4 trees, ensuring efficient search operations with guaranteed logarithmic height.
We'll cover the following...
General red-black tree
Here, we present red-black trees, a version of binary search trees with logarithmic height. Red-black trees are one of the most widely used data structures. They appear as the primary search structure in many library implementations, including the Java Collections Framework and several implementations of the C++ Standard Template Library. They are also used within the Linux operating system kernel. There are several reasons for the popularity of red-black trees:
- A red-black tree storing
nvalues has height at most - The
add(x)andremove(x)operations on a red-black tree run in worst-case time. - The amortized number of rotations performed during an
add(x)orremove(x)operation is constant.
The first two of these properties already put red-black trees ahead of
skiplists, treaps, and scapegoat trees. Skiplists and treaps rely on randomization and their running times are only expected. Scapegoat trees have a guaranteed bound on their height, but add(x) and remove(x) only run in amortized time. The third property is just icing on the cake. It tells us that that the time needed to add or remove an element ...