Reputation: 55479
The B-tree is of order 4, meaning that a node can hold 4 pointers, and 3 keys.
The following is inserted: A G I Y
Since they can't all fit in one node, I know that the node will split. So I know there's going to be a root node with 2 child nodes after these things are inserted, but I don't know exactly what they'll look like.
Upvotes: 3
Views: 386
Reputation: 21270
Here's an animation of the operations:
The second parameter to "initTree" is the order, but using another defintion. The maximum number of keys in this program is 2*order-1. So I set the order to 2 and it matches your example.
Upvotes: 1
Reputation: 3205
A
A is inserted
AG
G is inserted
AGI
I is inserted
G
/ \
A I
While inserting Y the node is full, split into 2 nodes and pass up the middle, G
G
/ \
A IY
Y is inserted
Upvotes: 3