What makes this Red/Black tree left heavy and is it correct?

59 Views Asked by At

So I was messing around with a Red/Black Tree visualiser (https://www.cs.usfca.edu/~galles/visualization/RedBlack.html), and came across the following tree (inserted in the order of 10, 40, 25, 35, 30, 45). I understand an AVL tree cannot have a height difference between the shorted and longest path of two but I'm confused if the same applies to a Red/Black tree. Would someone be able to point the specific properties that make this tree valid so I can deepen my understanding of this data structure?

enter image description here

1

There are 1 best solutions below

0
On

The properties of a red-black tree are very simple:

  1. Every node has either exactly two children or has no children. Nodes with no children are leaf nodes, and are not usually actually stored since they have no label. (In your diagram, they are not even shown.)
  2. The root is black.
  3. All leaf nodes are black.
  4. A red node's children are black.
  5. The black-depth of every leaf is the same. (By black depth, we mean the number of black nodes in the path to the leaf.)

These properties are sufficient to guarantee that the deepest leaf is no more than twice as deep as the shallowest leaf. That's a much looser guarantee than that of AVL trees (in which the difference in depth between two leaves is at most one) but it is sufficient to guarantee that the maximum depth is logarithmic is the size of the tree. And it is an invariant that is cheaper to maintain.