Question

Well, I'm studying for a test and I'm a little bit confused with the following. The following image is a B-tree with t=3 so each node can have at most 2t-1 keys and at least t-1 keys. I'm being asked to delete key=3. I can't understand why I need to join the root with its sons in this case. I know the delete algorithm is defensive as it starts in the root and checks every node so it will not need to go to any ancestor again. But which rule will be broken if I don't join the root with its son?

Original B-tree B tree with t=3 (Order)

After deleting key 3 enter image description here

As for me I would just delete key 3 and that's it.

Was it helpful?

Solution

It would not broke any of the rules, the algorithm just executes every possible node merge while looking up the given key. This is necessary to ensure that there will be no need to traverse the tree upwards after the deletion. Also, the height of the tree is reduced, which will speed up later lookups.

So this behaviour is an algorithmic decision to implement the B-tree efficiently.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top