DEV Community

Cover image for Red-Black Tree
Ritik Sharma
Ritik Sharma

Posted on • Edited on

Red-Black Tree

Red-Black Tree

Red-Black tree is a self-balancing binary search tree in which each node contains an extra bit for denoting the color of the node, either red or black. It was created in 1972 by Rudolf Bayer who termed them "symmetric binary B-trees."

Properties of Red-Black Tree:

  • Root element of Red-Black Tree is always black.
  • Every NULL node or Leaf Nodes is black.
  • If a red node has children then, the children or its parent are always black.
  • Number of black Node on Any path from root to leaf is always same.
  • Two consecutive red node should not be in Red-Black Tree.
  • If you are inserting a new node is always a red node.

Maximum height of Red-Black Tree :

log n <= h <= 2log n
Enter fullscreen mode Exit fullscreen mode

Examples of Red-Black Tree:-

image

Top comments (0)

Image of Checkly

Replace beforeEach/afterEach with Automatic Fixtures in Playwright

  • Avoid repetitive setup/teardown in spec file
  • Use Playwright automatic fixtures for true global hooks
  • Monitor JS exceptions with a custom exceptionLogger fixture
  • Keep your test code clean, DRY, and production-grade

Watch video

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay