How do you remove an element from a b-tree?

点点圈 提交于 2019-12-13 17:45:24

问题


I'm trying to learn about b-tree and every source I can find seem to omits the discussion about how to remove an element from the tree while preserving the b-tree properties.

Can someone explain the algorithm or point me to resource that do explain how it's done?


回答1:


There's an explanation of it on the Wikipedia page. B-tree - Deletion




回答2:


If you haven't got it yet, I strongly recommend Carmen & al Introduction to Algorithms 3rd Edition.

It is not described because the operations naturally stem from the B-Tree properties.

Since you have a lower-bound on the number of elements in a node, if removing your elements violates this invariant, then you need to restore it, which generally involves merging with a neighbour (or stealing some of its elements).

If you merge with a neighbour, then you need to remove an element in the parent node, which triggers the same algorithm. And you apply recursively till you get to the top.

B-Tree don't have rebalancing (at least not those I saw) so it's far less complicated that maintaining a red-black tree or an AVL tree which is probably why people didn't feel compelled to write about the removal.




回答3:


About which b-trees are you talking about? With linked leaves or not? Also, there are different ways of removing an item (top-bottom, bottom-top, etc.). This paper might help: B-trees, Shadowing, and Clones (even though there are many file-system specific related stuff).




回答4:


The deletion example from CLRS (2nd edition) is available here: http://ysangkok.github.io/js-clrs-btree/btree.html

Press "Init book" and then push the deletion buttons in order. That will cover all cases. Try and predict the new tree state before pushing each button, and try to recognize how the cases are all unique.



来源:https://stackoverflow.com/questions/5185920/how-do-you-remove-an-element-from-a-b-tree

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