Two-Four-Tree Remove (given a key k) Find the node r that contains the data element (dp) with the given k; if (r is not a leaf node) { swap with its direct predecessor in node p r = p; // r is guaranteed to be a leaf node now } remove from leaf node r r->size--; while (r->size == 0 && r->parent != 0) { p = r->parent; if (r's left sibling's size >= 2) { r->child[1] = r->child[0] move p's pair before pointer r to node r r->child[0] = r's sibling's last subtree move r's siblings last pair to parent's emptied spot decrease r's sibling's size by 1 // and it won't be 0 // note that p's size is unchanged } else { // r's sibling only has one data item // and two subtrees // r has just one subtree // all three subtree could be empty if r is leaf node // but that's OK merge p's pair before pointer r and r's one subtree into r's left sibling node increase r's sibling's size by 1 // it should be 2 adjust p's entries so that there is no hole in the arrays p->size--; // p's size could be 0 now delete r; } r = p; // go one level up to the parent node; } if (r->size == 0) { // root node becomes empty // r still only has at most one subtree root = r->child[0]; delete r; } }