1 / 11

COMP 6/4030 ALGORITHMS

COMP 6/4030 ALGORITHMS. RED-BLACK TREES. What is RBT?. Binary Tree Each node is colored Red or Black Black edge goes to Black node No Red node has Red child All external paths from a given node have the same Black length Root node is Black. Almost RBT (ARBT): Conditions 1-5 satisfied

silvio
Download Presentation

COMP 6/4030 ALGORITHMS

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. COMP 6/4030 ALGORITHMS RED-BLACK TREES

  2. What is RBT? • Binary Tree • Each node is colored Red or Black • Black edge goes to Black node • No Red node has Red child • All external paths from a given node have the same Black length • Root node is Black • Almost RBT (ARBT): • Conditions 1-5 satisfied • Root is Red

  3. Advantages of RBT • Efficient way to implement Binary Search • Algorithms for Insertion & Deletion of nodes are established • Well balanced • Height is at most 2log(n+1) • ~ 2 * most balanced binary tree

  4. RBT Examples

  5. Red-Black Trees (contd.) • RBT has 4 instance fields • Root, Left Subtree, Right Subtree, Color of root • Every node has one and only one color – either Black or Red

  6. Red-Black Trees (contd.) • Defn. of RBT (recursive): RBh and ARBh Binary trees with colored nodes (B or R) • External nodes are Black: RB0 tree • h>0: an ARBh: Red root, left & right subtrees are RBh-1 trees • h>0: an RBh : Black root, left & right subtrees are RBh-1 or ARBh trees

  7. RBT with black-depth convention • Red children at the level of parents • Black Depth = Geometric Depth • Advantages • Transparent • Bounds can be derived

  8. RBT with black-depth convention (contd)

  9. RBT Operations • Search, Insert node, Delete node • Insertion: • Select location of new key: ‘K’ • Insert a tree containing ‘K’ (Red) • Fix up color violations (Color Flip; Rebalancing) • Deletion: • Do standard BST search to determine the node to be deleted • Identify the node structure to be changed • Carry out structural deletion and repair imbalance in Black height

  10. RBT Insertion: Example

  11. Properties of RBTs • Theorem 1 Given that T is RBh tree (h is Black height) then • T has at least 2h – 1 internal Black nodes • T has at most 4h – 1 internal nodes • The depth (general) of any Black node is at most twice its Black depth • Theorem 2 Given that A is ARBh tree, then • A has at least 2h –2 internal Black nodes • A has at most ½ (4h) – 1 interval nodes • The depth of any Black node is at most twice its Black depth • Theorem 3 Given that T is an RBT with n internal nodes, then no node has depth larger than 2log(n+1) i.e., the height of T (general) is at most 2log(n+1)  the desired upper limit for the depth of a RBT

More Related