简体   繁体   English

是否可以将所有 AVL 树转换为红黑树?

[英]Is it possible to convert all AVL trees to red-black trees?

While I was studying Search Trees, I found a problem在研究搜索树时,我发现了一个问题

Show that the nodes of any AVL tree T can be colored "red" and "black" so that T becomes a red-black tree.证明任何 AVL 树 T 的节点都可以着色为“红色”和“黑色”,从而使 T 成为红黑树。

And now I wonder whether converting any AVL tree to red black tree is possible.现在我想知道是否可以将任何 AVL 树转换为红黑树。

Yes, it is possible.对的,这是可能的。

General idea is to turn red some of nodes that are roots of subtrees of odd height.一般的想法是将一些作为奇数高度子树根的节点变成红色。 More specifically, we turn red only those whose parents are root of subtrees of even height.更具体地说,我们只将那些父母是偶高子树的根的人变成红色。 You can prove that using recursion.你可以证明使用递归。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM