1 / 18

Red Black Tree

Red Black Tree. Prof Amir Geva Netzer Eitan. Properties . Every node is either red or black Every son of a leaf is black (A.K.A null is black) Son of a red node cant be red (A.K.A no two reds in a row)

knox
Télécharger la présentation

Red Black Tree

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 Tree Prof Amir Geva NetzerEitan

  2. Properties • Every node is either red or black • Every son of a leaf is black (A.K.A null is black) • Son of a red node cant be red (A.K.A no two reds in a row) • For every track from the root to a leaf contains the same number of black node on the way

  3. Rotates

  4. Insert • Add new like normal binary search tree • Paint new node as red • If new node father is black then red black tree properties are held • See options ahead

  5. Notation • X: new node • F: father(X) • G: father(F) (if exist) • U: son(G) s.t U~=F (if exist) F color is red G color is black

  6. A) F is root F F X X

  7. B) U is red F F G G X X U U

  8. C) X is right son of F and U is right of G(mirror) F X G G X U U F

  9. F D) X is left son of F and U is right son of F(mirror) X F G U X G U

  10. Insert summary • If After inserting if is G painted Red continue processes up the tree • Else Done • Time complexity

  11. Delete • If delete node has both sons replace delete node with minimum node in right sub-tree (new delete node has only one son if any) • If delete node is red then red black tree properties are held • If delete node is black and its son is red, paint its son black and delete node • Both delete nod and its are black

  12. Notation • Y: node to delete • X: son(Y) • W: brother of X AFTER we delete Y • F: father of X and W AFTER we delete Y • A,B have sub trees (the have sons) X and Y are black

  13. A) W is red F W W B X F B A A X

  14. B) W is black and F is red F F W W X X B B A A

  15. C) W, F and the sons of W are black F F W W X X B B A A

  16. D) W is black and it’s a right child of its father and has left red son F F A X W X W B A B

  17. E) W is black and has v red son(solution for D) F W W A X F A B B X

  18. Delete summary • If After deletion processes continue up or down the tree *circled node is the new “X” in other cases • Else Done • Time complexity

More Related