Master the fundamental concepts of b-trees through this focused micro-challenge.
You have read the whole brief, and the concepts above stay free on every task. Writing and running the code needs a plan.
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
Every task includes starter code, theory, and hidden tests so you can implement and verify locally in the browser.
How it worksDeletion removes a key from a leaf, then fixes underflow if a node drops below minimum occupancy by borrowing from a sibling or merging nodes and pulling a separator from the parent. Rebalancing is the symmetric counterpart to split on insert.
If left or right sibling has extra keys, rotate keys through parent. Otherwise merge with sibling and remove separator from parent, possibly cascading upward.
cLoading…
Keep the relevant documentation open while you implement. When your output disagrees with the reference, trace one failing case by hand before changing random lines.
You will implement delete with borrow and merge rebalancing. This exercise asks you to show a case where merge reduces sibling count and updates the parent.
Delete keys from a B-tree (MAX_KEYS = 3, MIN_KEYS = 1) and keep it balanced. The tree starts as
cLoading…
and stays two levels deep: a root of separator keys over leaves, until a merge empties the root.
Delete K:
Once the tree is a single leaf, deletes just remove keys from it.
delete K commands, one per line.
First the starting tree, tree: [20] / [5,10,15] [25,30,35]. Then for each delete:
delete K: removed from leaf, delete K: internal key, replaced by predecessor P or delete K: missing;borrow from left sibling, borrow from right sibling, merge with left sibling or merge with right sibling, followed by root emptied: tree height shrinks when the root ran out of keys;tree: [root keys] / [leaf] [leaf] ..., or tree: [keys] once it is a single leaf.Finally redistributions=R merges=M min_keys_ok=yes. The last field is yes when every leaf under a root has at least MIN_KEYS keys.