# RB trees from any balanced BST?

Given any perfectly balanced binary search tree, is it always possible to assign a coloring to the nodes so that it becomes a Red-Black tree? If so, how do you prove this, and if false, what would be a counterexample?

Recall the following definitions.

Perfectly balanced node: A node of a binary tree is said to be perfectly balanced if the absolute difference in the number of vertices in its left subtree and its right subtree is atmost 1.

Perfectly Balanced Tree: A binary tree is called perfectly balanced if all its nodes are perfectly balanced.

Trivial Fact: The height of a perfectly balanced tree is $$\Theta (\log n)$$ where $$n$$ is the number of nodes in the tree.

• You mean really perfectly balanced, where all levels of the tree are filled? Then you can colour all nodes black. – Hendrik Jan Aug 30 '19 at 0:24
• @HendrikJan I've added the definition of perfectly balanced tree in the question. – Kaind Aug 30 '19 at 12:17
• Any AVL-tree can be coloured Red-Black (the wikipedia page on Red-Black trees states this, without references). As your perfect balance is more strict than AVL-trees, that answers your question. I find it hard to locate explicit algorithms that do the colouring. One suggestion was given by Karolis here. – Hendrik Jan Aug 31 '19 at 11:28