1 / 15

Foundation of Computing Systems

Foundation of Computing Systems. Lecture 9 Trees: Part VI-A. Red Black Binary Trees. Approaches to balance a binary search tree so that the searching time can be reduced Height-balanced tree (AVL tree) Red-Black tree. Definition of Red Black Tree.

tryna
Download Presentation

Foundation of Computing Systems

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. Foundation of Computing Systems Lecture 9 Trees: Part VI-A

  2. Red Black Binary Trees • Approaches to balance a binary search tree so that the searching time can be reduced • Height-balanced tree (AVL tree) • Red-Black tree IT 60101: Lecture #9

  3. Definition of Red Black Tree • A red-black tree is a binary search tree that satisfies the following properties Color property: • Every node is either red or black. Root property: • The root is always colored with black. External property: • Every external node is black. Internal property: • If a node is red then both its children are black. Depth property: • For each node, all paths from that node to descendant external nodes contain the same number of black nodes. IT 60101: Lecture #9

  4. Definition of Red Black Tree It is a binary search tree [Basic property] IT 60101: Lecture #9

  5. Definition of Red Black Tree Every node is either red or black [Color property] IT 60101: Lecture #9

  6. Definition of Red Black Tree The root is colored as black [Root property] IT 60101: Lecture #9

  7. Definition of Red Black Tree All external nodes are colored with black color [External property] IT 60101: Lecture #9

  8. Definition of Red Black Tree Children of every red-colored node are black [Internal property] IT 60101: Lecture #9

  9. Definition of Red Black Tree For every node in the tree and all paths from that node to external nodes, counts of black colored nodes are same [Depth property] IT 60101: Lecture #9

  10. Operations on Red-Black Trees • Major operations are: • Insertion (to insert a new node) • Deletion (to remove an existing node) • Searching (to find an element) • Structure of a node in RBT IT 60101: Lecture #9

  11. Red-Black Trees: Insertion • Suppose the node we are going to insert having value x and x is not present in the tree. • We follow the following preprocessing steps • Allocate a node for red-black tree • Assign the value x into the field DATA • Initially, the color of the node is made RED • The node has two black children as external nodes IT 60101: Lecture #9

  12. Red-Black Trees: Insertion • Cases: • Red-Black tree is empty • The node x is inserted so that its parent is colored with BLACK • The node x is inserted so that its parent is colored with RED • x’ parent is RED and x’ uncle is RED • x is RIGHT child and x’s uncle is BLACK • x is the LEFT child and x’s uncle is BLACK IT 60101: Lecture #9

  13. Insertion : Case 1 • Case 1: Red-Black tree is empty IT 60101: Lecture #9

  14. Insertion : Case 2 • Case 1: The node x is inserted so that its parent is colored with BLACK IT 60101: Lecture #9

  15. To be continued… IT 60101: Lecture #9

More Related