B-tree: merge two siblings
General Information
Algorithmic problem: See B-Trees
Prerequisites:
- A node
with a key at position that is not void - The number of keys in
Type of algorithm: loop
Auxiliary data:
- Three pointers
of type "pointer to B-tree node".
Abstract View
Invariant: After
points to the left children of the key of at position and points to the right children of the key of at position . . shows on the index of the copied key in .
Variant:
Break condition:
Induction Basis
Abstract view:
- Assign
the left children of at position and the right children of at position . - Move the key from
at position to at position . - Copy the left children of
to the new key in at position - Change the number of keys in
and .
Implementation:
- Set
and and . - Set
and for (in this order), set - Set
- Set
and set
Proof:
In the induction basic
Induction Step
Abstract view:
- If not all keys (and children) of
are copied, copy the key and children from position of to position of . - Otherwise, terminate the algorithm.
Implementation:
- if
(that is, not all keys of are copied): - Otherwise, terminate the algorithm.
Correctness:
In the induction step we copy a key and a children from
Complexity
Statement: Linear in
Proof: Obvious.