In red-black trees is top-down deletion faster and more space efficient than bottom-up deletion?

∥☆過路亽.° 提交于 2019-12-03 02:09:25

From what I gather: "top-down deletion" avoids traversing the same node in a path more than once during the operation. So, given the simple path from the root to a given node, if you're going to do some thing to a node that's in that path anyway, why not just do it on the way down? It avoids having to traverse over parts of the path more than once. Therefore, this saves time.

A similar principle is employed for multiple operations (including insert) in 2-3-4 trees (a special sub-case of a,b-trees)

Does top-down deletion minimize the number of re-balancing operations?

Think that, in the average case, it does. Because you make it potentially easier to insert something afterward with few re-balancing operations.

Could it be possible that top-down deletion pro-actively does too many re-colorings and re-balancings on the way down?

Maybe, but that depends on the data set. However, as mentioned above. This may reduce the number of re-colorings and re-balancings overall.

Is top-down more space efficient than bottom-up?

In a word, yes. The top-down algorithm presented at eternally confuzzled does not need parent pointers on the nodes. Bottom-up algorithms are presented with a tradeoff between time and space: parent pointers allow for some short-circuiting when re-balancing after insertion and deletion.

For example, OpenJdk-7's implementation of Red-black trees has parent pointers, which allows it to choose whether or not a re-balance is necessary after a deletion (such as in your scenario).

Is top-down more time efficient than bottom-up?

In general, yes: The top-down approach must only traverse the once tree per operation, while the bottom approach must traverse the tree twice per operation. As I mentioned earlier, bottom up approaches can shave off some time by using parent-pointers. But definitely not a whole tree-traversal every time.

Both implementations may also choose to utilize threading to improve the time or space required to iterate through the entire tree. This requires the overhead of a flag or two per node. This can also be achieved using parent pointers, but not as efficiently. NB: the threading link says threading is not as efficient as parent pointers, but this only applies to bottom-up trees (which the book covers).

Anecdotal evidence

Back in college, we implemented eternally confuzzled's top-down red-black tree in C++ and did a comparison with our STL's (bottom-up) implementation of std::map. Our top-down approach was definitely faster—I want to say it was easily 2x faster on all mutating operations. Searching was faster, too, but I cannot say if it was due to a more balanced tree or less complex code.

Sadly, I no longer have the code, nor the writeup.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!