270 likes | 289 Views
This homework assignment requires implementing the remove function and the rule-of-three functions (copy constructor and assignment operator). Deadline: December 1st, 11:59pm.
E N D
But first... • Any questions about the exam or material that could be on the exam?
But second... • Any questions about the homework assignment? • Relevant office hours: • Today, 11-12; 2-3 • Tuesday, 12:30-1:30
Homework 5 • For your next homework assignment, you will be implementing the remove function and the rule-of-three functions (copy constructor and assignment operator) • This assignment is due by 11:59pm on December 1 • Any questions?
2-3-4 implementation • What's the minimum information we would need in a 2-3-4 node?
How much space is wasted here? 47 31 73 96 29 37 45 50 86 88 100
Red-black trees • Red-black trees are a method of implementing something like a 2-3-4 tree without the problem of mostly-empty nodes • Red-black trees are binary search tree with a color (red or black) assigned to each node • A black node represents a node in the corresponding 2-3-4 tree • A red node indicates a value that was stored inside the same node as its parent • A red node's parent MUST be black • Let's look at representing some 2-3-4 trees...
How could we represent this tree? 47 31 73 96 29 37 45 50 86 88 100
Red-Black insertion • When inserting into a red-black tree, use the 2-3-4 insertion algorithm that splits 4-nodes as we go • We need to consider the following cases: • Looking at a 4-node that is the root • Looking at a 4-node with a 3-node parent • Looking at a 4-node with a 2-node parent
Looking at a 4-node that is the root Looking at a black root with two red children
Looking at a 4-node that has a 2-node parent Looking at a black node with two red children, a black parent, and a black sibling
Looking at a 4-node that has a 3-node parent Looking at a black node with two red children and either: a) a red parent and black grandparent b) a black parent and red sibling
Looking at a 4-node that has a 3-node parent Looking at a black node with two red children and either: a) a red parent and black grandparent b) a black parent and red sibling
Looking at a 4-node that has a 3-node parent Looking at a black node with two red children and either: a) a red parent and black grandparent b) a black parent and red sibling
e d 6 b 5 c a 1 2 3 4
e d 6 b 5 c a 1 2 3 4
d e b 5 6 c a 1 2 3 4
d b e c a 5 6 1 2 3 4
d b e c a 5 6 1 2 3 4
d b e c a 5 6 1 2 3 4
e d d 6 b b 5 e c c a a 5 6 1 1 2 2 3 3 4 4