1 / 21

Red - Black Trees

Red - Black Trees. Acknowledgment Many thanks to “ erm ” from Purdue University for this very interesting way of presenting this course material. Red -Black Tree. A red -black tree is a binary search tree with the following properties: • edges are colored red or black

allene
Download Presentation

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. Red-Black Trees Acknowledgment Many thanks to “erm” from Purdue University for this very interesting way of presenting this course material.

  2. Red-Black Tree • A red-black tree is a binary search treewith thefollowing properties: • • edges are colored red or black • • no two consecutive red edgeson any root-leaf path • • same number of black edgeson any root-leaf path • (= black height of the tree) • • edges connecting leaves are black

  3. Correspondence between2-3-4 and Red-Black trees Notice that red-black trees are just a way ofrepresenting 2-3-4 trees!

  4. More Red-Black Tree Properties

  5. Insertion into Red-Black Trees 1.Perform a standard search to find the leaf where the key should be added 2.Replace the leaf with an internal node with the new key 3.Color the incoming edge of the new node red 4. Add two new leaves, and color their incoming edges black 5.If the parent had an incoming red edge, we have two consecutive red edges! We mustreorganize tree to remove that violation. What must be done depends on the sibling of the parent.

  6. Insertion: an example Start by inserting “REDSOX” into an empty tree

More Related