All About Red-Black Trees!

Introduction

A Red-Black tree is a type of binary search tree with red and black colored nodes. Unlike regular binary search trees, Red-Black trees are self-balancing, making them useful to store data.

Requirements

Binary search trees must fulfill a few requirements in order to be classified as a valid Red-Black tree. These requirements are:

  1. All nodes must be either colored red or black.
  2. The root node of the tree must be colored black.
  3. Red nodes cannot have red child nodes.
  4. The black height of the tree is consistent: i.e. every path from the root node to a null child of a leaf node uses the same number of black nodes.
  5. Null children are considered black.

Example of a valid and invalid Red-Black tree.

More Info

For more information about Red-Black trees, their applications, and Red-Black tree operations such as insertion and deletion, consider the below article:

Red-Black tree: Wikipedia

Thanks for reading!