Question

Consider the following 2-3-4 tree (i.e., B-tree with a minimum degree of two) in which each data item is a letter. The usual alphabetical ordering of letters is used in constructing the tree.

enter image description here

What is the result of inserting G in the above tree?

I am getting the answer as

enter image description here

But the answer in solution key is

enter image description here

Can anyone explain how to get the answer provided by the solution key?

Était-ce utile?

La solution

As long the invariants are not violated, the operation is technically valid. The insertion algorithm in CLRS splits on the way down, so it would split the root like you did.

However, another implementation might observe that the second child is empty and the first is full. That means the "rotation" can be done and the root node count is unaffected. The rotation involves pushing L down into the second child (prepending) and pulling up I up into L's previous place in the root. Now the first child has only two entries and you can insert into it.

Animated insertion using the CLRS method you used

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top