Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

RED-BLACK TREE

NAME – CHIRAG RATHI REG. NO – 21BCE10255

1. DERIVE ITS PROPERTIES.


A red-black tree is a kind of self-balancing binary search tree where each node has an extra bit, and that
bit is often interpreted as the color (red or black). These colors are used to ensure that the tree remains
balanced during insertions and deletions. Although the balance of the tree is not perfect, it is good enough
to reduce the searching time and maintain it around O (log n) time, where n is the total number of
elements in the tree.
 The root node should always be black in color.
 Every null child of a node is black in red black tree.
 The children of a red node are black.
 All the leaves have the same black depth.
 Every simple path from the root node to the (downward) leaf node contains the same number
of black nodes.

2. EXPLAIN ANY 3 CASES, WHEN PROPERTY VIOLATED.


 DURING DELETION - In delete, the main violated property is, change of black height in
subtrees as deletion of a black node may cause reduced black height in one root to leaf path.

 RED PROPERTY –-The search-tree operations TREE-INSERT and TREE-DELETE, when


run on a red black tree with n keys, take O (log n)/ time. Because they modify the tree, the
result may violate the red-black properties. To restore these properties, we must change the
colors of some of the nodes in the tree and also change the pointer structure. We change the
pointer structure through rotation.

 DURING INSERTION - We can insert a node into an n-node red-black tree in O (logn)/
time. To do so, we use a slightly modified version of the TREE-INSERT procedure to insert
node z into the tree T as if it were an ordinary binary search tree, and then we color z red. To
guarantee that the red-black properties are preserved, we then call an auxiliary procedure RB-
INSERT-FIXUP to recolor nodes and perform rotations. They call RB-INSERT (T, z) inserts
node z, whose key is assumed to have already been filled in, into the red-black tree T.

You might also like