3

I am searching for a proof that all AVL trees can be colored like a red-black tree? Can anyone give the proof?

Erick Robertson
  • 32,125
  • 13
  • 69
  • 98
  • I don't understand the question. – yfeldblum Jan 10 '09 at 20:48
  • Although we are willing to help, we won't do your homework. So give it a try first and if you are stuck, come back and ask a specific question. – Toon Krijthe Jan 10 '09 at 20:48
  • @Justice, he is looking for a proof that all avl trees can be colored with two colors without two connected nodes having the same color. – Toon Krijthe Jan 10 '09 at 20:54
  • color(node) = if is_even(depth(node)) then "black" else "red" ... is that really the question? Or is he asking whether an AVL tree can be colored such that it obeys all the properties of a red-black tree? – yfeldblum Jan 10 '09 at 20:59
  • @Justice: The latter, I think – jpalecek Jan 13 '09 at 00:39

4 Answers4

1

By definition R/B trees can be slightly less balanced then AVL-s, as |maxPath - minPath| must be <= 1 for AVLs and maxPath <= 2 * minPath for R/Bs so that not every R/B is an AVL but on the other hand there is no need for the AVL-s To have Empty subTrees so

     4
    / \
   3   6
  /\   /\
 1  E 5  8

is a perfectly legal AVL and it is not an R/B because R/B cannot contain Leaves and must be terminated by Empty trees which are coloured always Black - so that you cannot colour the tree above. To make it R/B you are allowed to convert every leaf x into node E x E and then follow these rules: R/B Tree: Must be a BST must contain only nodes and empty trees which are coloured either Black or Red Every Red node has black children All Empty Trees are Black Given a node, all paths to Empty Trees must have same number of Black Nodes Any Leaf can be replaced with Node whose Left & Right subTrees are Empty Max Path T ≤ 2 * Min Path T

Btw just realized it coloured my nodes and leaves in Red - this was not intended. Karol

Karol
  • 53
  • 8
  • Of course you can colour the tree above as Red-Black. Make 3, 4, 6 - black. Make 1,,5, 8 - red. Root node is black. Black Path count is 2 in every direction. And no Parent-Child are both Red. All properties are satisfied. – SJHowe Nov 05 '21 at 22:16
0

The red-black tree adjusts the branch heights by red nodes, so if the height difference is bounded, you can always adjust all the branches, starting from the shortest black branch. But it requires a very large cost, because you have to count all the branch heights.

The maximum local height difffernce bound of red-black tree is 2.

-2

I suspect the answer is no.

AVL trees balance better than RB trees, which means they balance differently, which would rather imply that you could not colour every AVL tree as a valid RB tree.

  • This is incorrect. The only substantial difference is that the AVL tree's balancing is more strict, and no tree can be "too balanced" to be a red-black tree. – Graphics Noob Sep 21 '10 at 05:52
  • Would it not be possible to have an AVL tree, which if you coloured it, would be in a state which is invalid for a RB tree? that is my concern. –  Sep 29 '10 at 09:50
  • user82238: I think Graphics Noob is right. If you colour a AVL tree, you just to place black nodes so that black path count is the same everywhere and AVL's superb balance will help you. That leaves placing the odd red node as "filler" in the event that you cannot quite get the black path count the same. Say that shortest AVL path from root to leaf is 9 with the occasional 10. Then make the black path count 9 and on 10 paths, make the leaf nodes red. It is the other way round. There are Red-Black trees that cannot be AVL trees – SJHowe Nov 05 '21 at 22:11
-2

The answer is yes, every AVL tree can be colored Red-Black, and the converse doesn't hold.

I haven'y exactly figured out HOW to do it tho, and am also seeking the proof.