Red Black Tree Insertion Algorithm



Introduction

Red Black Tree insertion is an algorithm that adds new nodes
using standard Binary Search tree operations. Once the node has been added,
the tree must be checked for RBT property violations.

for more info about Red Black Tree properties, please visit RBT properties


Insertion into a Red Black Tree:

  1. insert a new value using BST insertion algorithm

  2. color the newly inserted node red

  3. check the RBT properties and restore the tree if necessary
  4. properties that need to be checked:


If there is a RBT property violation



Example Insertions


Insert 10

Insert 5, 20

Insert 2

Insert 3

Insert 7

Insert 8

Final Red Black Tree