Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deletion in Left Leaning Red Black Trees

I am learning about Left Leaning Red Black Trees.

In the deletion algorithm peresented in the paper, if the key matches for a node and the right subtree is NULL for that node, then that node is deleted. But there may be a left subtree as well which is not considered.

I am not able to understand why would the left subtree be NULL as well. Similar thing is done when deleting the minimum or the maximum as well. Could anyone please guide me on this?

like image 359
prashanthkvs Avatar asked Nov 13 '12 11:11

prashanthkvs


People also ask

What is deletion in red-black tree?

Red Black Tree Insert. Insertion Vs Deletion: Like Insertion, recoloring and rotations are used to maintain the Red-Black properties. In the insert operation, we check the color of the uncle to decide the appropriate case. In the delete operation, we check the color of the sibling to decide the appropriate case.

What is the time complexity of deletion in red-black tree?

What is the time complexity of deletion in Red-Black Tree? It takes O(log N) time, where N is the number of nodes in the red-black tree.

What is left rotation in red-black tree?

In left rotation, we assume that the right child is not null. Similarly, in the right rotation, we assume that the left child is not null. Consider the following tree: After applying left rotation on the node x, the node y will become the new root of the subtree and its left child will be x.


1 Answers

It seems you are speaking about this piece of code:

if (isRed(h.left))
  h = rotateRight(h);
if (key.compareTo(h.key) == 0 && (h.right == null))
  return null;

Here left descendant cannot be "red" because preceding code would rotate it to the right.

Also left descendant cannot be "black" because in this case there is a path to the left of h containing at least one "black" node while no path to the right of it has any "black" nodes. But in RB-tree the number of black nodes on every path must be the same.

This means there is no left descendant at all and node h is a leaf node.

In deleteMin function there is no need to check right sub-tree if left sub-tree is empty because no right sub-tree of LLRB tree can be greater than corresponding left sub-tree.

like image 192
Evgeny Kluev Avatar answered Oct 10 '22 00:10

Evgeny Kluev