1 / 27

Homework, 2-3-4 trees part 2, and red-black trees

This homework assignment requires implementing the remove function and the rule-of-three functions (copy constructor and assignment operator). Deadline: December 1st, 11:59pm.

alisong
Download Presentation

Homework, 2-3-4 trees part 2, and red-black trees

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Homework, 2-3-4 trees part 2, and red-black trees

  2. But first... • Any questions about the exam or material that could be on the exam?

  3. But second... • Any questions about the homework assignment? • Relevant office hours: • Today, 11-12; 2-3 • Tuesday, 12:30-1:30

  4. 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?

  5. 2-3-4 implementation • What's the minimum information we would need in a 2-3-4 node?

  6. How much space is wasted here? 47 31 73 96 29 37 45 50 86 88 100

  7. 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...

  8. How could we represent this tree? 47 31 73 96 29 37 45 50 86 88 100

  9. 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

  10. Looking at a 4-node that is the root Looking at a black root with two red children

  11. 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

  12. 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

  13. 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

  14. 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

  15. e d 6 b 5 c a 1 2 3 4

  16. e d 6 b 5 c a 1 2 3 4

  17. d e b 5 6 c a 1 2 3 4

  18. d b e c a 5 6 1 2 3 4

  19. d b e c a 5 6 1 2 3 4

  20. d b e c a 5 6 1 2 3 4

  21. e d d 6 b b 5 e c c a a 5 6 1 1 2 2 3 3 4 4

More Related