Homework problem J

Problem J

Assigned Oct 9, due Oct 23.

B-trees (based on CLR 18.2-3 and 18.2-4).

  1. (5 points) Explain how to find the predecessor of a given key at a given node in a B-tree. Assume the given key is not the minimum of the whole tree.
    [statement correction Oct 13: "the key" → "a given key".]

    Suggestion: Among other things, use B_tree_max.

    key B_tree_max(node* x) 
    {   while ( 0 != x->C.size() ) // x is internal. 
            x = x->C.back();       // go to last child.
        return x->K.back()         // x now a leaf so take last key.
    }
    
    key B_tree_predecessor(node* x, key k)
    {...}
    

  2. (3 points) Suppose that the keys 1, 2, 3, ..., n are inserted, in that order, into an empty B-tree with minimum degree t = 2. Show that the final B-tree has at least n - 2lg(n) - 2 nodes.
    [formula correction Oct 20: from "n - 2lg(n+1)".]

    Food for thought (You don't have to answer this): Can you give a greater lower bound for the number of nodes? For instance, is the pre-correction formula actually valid?

  3. (2 points) Argue that for any height h and any minimum degree t ≥ 2, a sequence of key insertions exists taking an empty B-tree (with minimum degree t) from empty to having height h and having exactly 2t - 2 keys in every node.

    Hint: Call a B-tree that got to it's current state without deletions, only insertions, and which has no full nodes a nowhere-full B-tree. Argue that for a given height h, a maximal nowhere-full B-tree has 2t - 2 keys in each node. If a node has fewer nodes, something can be done about it...

    You may assume maximal nowhere-full B-trees do actually exist for each height h. It follows from this observation: There are more than zero but finitely many nowhere-full B-trees of height h. One way to get a nowhere-full B-tree of height h: Construct the first B-tree of height h that comes from inserting 1, 2, ... in order as in the part above. Tweak it with a few, possibly zero, extra insertions (of possibly non-integer reals) to be nowhere-full.