In a B-tree index, what mechanism ensures that the tree remains balanced after insertions and deletions?
Think about how B-trees keep their height minimal and uniform.
B-trees keep all leaf nodes at the same depth by splitting nodes when they get too full and merging nodes when they get too empty. This keeps the tree balanced and search efficient.
Consider a B-tree of order 4 (each node can have at most 4 children). What is the maximum number of keys a single node can hold?
Remember, a node with n children has n-1 keys.
In a B-tree, the number of keys in a node is always one less than the number of its children. For order 4, max children is 4, so max keys is 3.
Which SQL-like pseudocode correctly describes the step to split a full B-tree node during insertion?
IF node.isFull() THEN median = node.keys[middle_index] leftNode = node.keys[0 to middle_index-1] rightNode = node.keys[middle_index+1 to end] parent.insertKey(median) parent.insertChild(leftNode) parent.insertChild(rightNode) END IF
Think about how B-tree insertion handles full nodes.
When a node is full, it splits into two nodes around the median key. The median key moves up to the parent node to maintain order.
Why is a higher order (more children per node) preferred for B-trees used in disk-based databases?
Consider how disk access speed affects search performance.
Higher order means more keys per node, which reduces tree height. This lowers the number of disk reads needed to find a key, improving performance.
A B-tree search for key 42 returns no result, but the key exists in the tree. Which issue below most likely causes this problem?
Think about what happens if pointers between nodes are incorrect.
If nodes are not linked correctly after splitting, the search path can miss keys even if they exist, causing search failures.