简体   繁体   中英

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.

And now I wonder whether converting any AVL tree to red black tree is possible.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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