Balanced BST Study Guide
Author: Josh Hug

## Overview

2-3 and 2-3-4 trees. Understand how to search and insert. Understand why insertion technique leads to perfect balance.

Terminology. Know that a 2-3 tree is also called a B-Tree of order 3 and that a 2-3-4 tree is a B-Tree of order 4. Know that an M-node is a node with M children, e.g. a 4-node is a node containing 3 items and thus with 4 children.

Performance of trees. Tree height is between log_M N and log_2 N. All paths are of the same height.

1-1 correspondence between LLRBs and 2-3 trees. Understand how to map a 2-3 tree to an LLRB and vice versa. You do not need to know how to perform tree operations ‘natively’ on an LLRB.

LLRBs. BST such that no node has two red links touching it; perfect black balance; red links lean left.

LLRB get. Exactly the same as regular BST get.

LLRB performance. Perfect black balance ensures worst case performance for get and insert is ~ 2 log_2 N.

LLRB insert. You are not responsible for knowing how to insert into an LLRB using rotations and color flipping. However, you should know how to convert back and forth between 2-3 trees and LLRBs, and you should also know how to insert into 2-3 trees. Thus, you should know effectively how one can insert into an LLRB.

## Example Implementations

LLRB (Simple)

LLRB (Complete)

### C level

1. Draw the 2-3 tree that results when you insert the keys A B C D E F G in order.
2. Draw a 2-3 tree with all 3 nodes. Why is the height log_3(N)? Draw the corresponding left-leaning red black tree (LLRB).
3. How many compares does it take in the worst case to decide whether to go left, middle, or right from a 3 node?

### B level

1. Draw the LLRB tree that results when you insert the keys A B C D E F G in order.
2. Given an LLRB, is there exactly one corresponding 2-3 tree? Given a 2-3 tree, is there exactly one corresponding red-black tree?
3. What is the worst case height of a 2-3-4-5 tree? Best case? Give your answers in tilde notation. Edit: An earlier
4. For a 2-3 tree of height N, what is the best case number of compares to find a key? The worst case?
5. What is the worst case height of an LLRB? Give your answer in tilde notation. Draw an example of a worst case tree.
6. Problem 2 of my Spring 2013 midterm, part b only.
7. Problem 5 of the Fall 2014 midterm.

### A level

1. Derive a simple procedure for deleting from a 2-3 tree. Your procedure must take $O(\log N)$ time.
2. In class, we always chose the left-middle object when splitting a 4 node. Suppose we used the right-middle object instead. Would the idea of a 2-3-4 tree still make sense? Are there any advantages or disdvantages?
3. In class, we always chose the left-middle object when splitting a 4 node. Suppose we used the left-most object instead. Would the idea of a 2-3-4 tree still make sense? Are there any advantages or disdvantages?
4. Show that in the worst case, we need to perform at most log N LLRB operations (color flips and rotates) after an insert. Give an example of a tree and an item X such that insertion of X requires log N LLRB operations.