开发者

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

开发者 https://www.devze.com 2023-02-15 03:52 出处:网络
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.

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 al开发者_StackOverflow中文版gorithm or point me to resource that do explain how it's done?


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


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.


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).


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号