Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell if a binary tree is red-black balanced?

Tags:

binary-tree

In a past exam we were once asked to decide whether a tree was red-black balanced by looking at its shape. I haven't found any information on how to do this, except that one sight claims that a binary tree is red-black balanced if the longest path is no more than twice the shortest, but I'm pretty sure that's the requirement for null path balanced trees, too. Is that correct? Is there any way to tell if a tree is red-black balanced by the shape?

like image 377
Gwen Brewer Avatar asked Oct 20 '22 12:10

Gwen Brewer


1 Answers

I'm not guru, but this is from Cormen's book Introduction to Algorithms:

A red-black tree is a binary tree that satisfies the following red-black properties:

  1. Every node is either red or black.
  2. The root is black.
  3. Every leaf (NIL) is black.
  4. If a node is red, then both its children are black.
  5. For each node, all simple paths from the node to descendant leaves contain the same number of black nodes.
like image 199
Giorgi Nakeuri Avatar answered Jan 04 '23 05:01

Giorgi Nakeuri