SlideShare a Scribd company logo
1 of 14
Data Structure & Files
Unit 5: Advance Tree
Red Black Binary Tree
Ms. Vrushali Dhanokar (M.Tech CSE)
Assistant Professor
IT Department
dhanokarvrushali@gmail.com
Why & What is mean by Red-Black Tree?
• Red-Black Tree is a self-balancing Binary Search Tree (BST).
• Every node is colored with Red or Black.
Why Red Black Tree?
• Most of the BST operations (e.g., search, max, min, insert, delete.. etc) take O(h) time where h
is the height of the BST. The cost of these operations is high.
• The height of a Red-Black tree is always O(Log n) where n is the number of nodes in the tree.
Properties of Red Black Tree
1. Every node has a color either Red or Black.
2. Root of tree is always Black.
3. Leaf node or NULL node always Red.
4. Children's of Red Node are Black, Parent of Red Node is Black.
5. Every path from a node (including root) to any of its descendant NULL node has the same
number of Black nodes.
Every Red Black Tree is a binary search tree but every Binary Search Tree need not be Red
Black tree.
Insertion in Red-Black Tree: (Conditions)
1. Tree is empty – Add root node with color Black.
2. Tree is not empty – Add new node with color Red.
3. If parent of newnode is Black then exit.
4. If parent of newnode is Red then check the color of parent’s siblings of new node-
a. If parent of sibling is Black or NULL then perform suitable Rotation & Recolor.
b. If parent of sibling is Red then Recolor and also check if parents parent of newnode
is not root node then Recolor it and Check it
Rotation Means?
Rotations: L-Left & R-Right
• It occurs on only newnode and There Parent’s Node.
1. LR Relationship – 1. Left Rotation 2. Right Rotation
2. RL Relationship – 1. Right Rotation 2. Left Rotation
It occurs on newnode , there Parent’s Node and also there Parent’s node.
1. LL Relationship – 1. Right Rotation
2. RR Relationship – 1. Left Rotation
Insertion Examples (Add data according BST property)
1. Tree is empty – Add root node with color
Black.
2. Tree is not empty – Add new node with color
Red.
3. If parent of newnode is Black then exit.
4. If parent of newnode is Red then check the
color of parent’s siblings of new node-
a. If parent of sibling is Black or NULL then
perform suitable rotation & Recolor.
b. If parent of sibling is Red then Recolor and
also check if parents parent of newnode is not root
node then Recolor it and Check it
Create Red-Black Tree for
8,18,5,15,17,25,40 ,80.
Continue..
1. Tree is empty – Add root node with color
Black.
2. Tree is not empty – Add new node with
color Red.
3. If parent of newnode is Black then exit.
4. If parent of newnode is Red then check
the color of parent’s siblings of new
node-
a. If parent of sibling is Black or NULL
then perform suitable rotation & Recolor.
b. If parent of sibling is Red then Recolor
and also check if parents parent of newnode is
not root node then Recolor it and Check it
Continue..
1. Tree is empty – Add root node with color
Black.
2. Tree is not empty – Add new node with
color Red.
3. If parent of newnode is Black then exit.
4. If parent of newnode is Red then check
the color of parent’s siblings of new node-
a. If parent of sibling is Black or NULL
then perform suitable rotation & Recolor.
b. If parent of sibling is Red then Recolor
and also check if parents parent of newnode is
not root node then Recolor it and Check it
Continue..!
1. Tree is empty – Add root node with color
Black.
2. Tree is not empty – Add new node with
color Red.
3. If parent of newnode is Black then exit.
4. If parent of newnode is Red then check the
color of parent’s siblings of new node-
a. If parent of sibling is Black or NULL
then perform suitable rotation & Recolor.
b. If parent of sibling is Red then Recolor
and also check if parents parent of newnode is
not root node then Recolor it and Check it
Continue..!
1. Tree is empty – Add root node with color
Black.
2. Tree is not empty – Add new node with
color Red.
3. If parent of newnode is Black then exit.
4. If parent of newnode is Red then check the
color of parent’s siblings of new node-
a. If parent of sibling is Black or NULL
then perform suitable rotation & Recolor.
b. If parent of sibling is Red then Recolor
and also check if parents parent of newnode is
not root node then Recolor it and Check it
Continue..!
1. Tree is empty – Add root node with color
Black.
2. Tree is not empty – Add new node with
color Red.
3. If parent of newnode is Black then exit.
4. If parent of newnode is Red then check the
color of parent’s siblings of new node-
a. If parent of sibling is Black or NULL
then perform suitable rotation & Recolor.
b. If parent of sibling is Red then Recolor
and also check if parents parent of newnode is
not root node then Recolor it and Check it
Applications of Red-Black Tree
1. Linux Kernal, For process scheduler or for keeping track of virtual
memory segmentation segments for a process.
2. Used in map, multimap, multiset from C++ STL and java.util.TreeMap ,
java.util.TreeSet from Java.
3. They are use in K-mean clustering algorithm for reducing time complexity.
4. MySQL uses Red-Black Trees for indexes on tables.
5. Fast searching can be occur.
Important Questions
1. Write a short note on Red-Black Tree? 6M
2. Explain Red-Black Tree in detail. 6M
3. Write properties of Red-Black Tree. 3M
4. Construct Red-Black Tree for given numbers:
10,18,7,15,16,20,25,40,60,21,70. 8M
Thank You…!

More Related Content

What's hot (20)

B and B+ tree
B and B+ treeB and B+ tree
B and B+ tree
 
Red black tree
Red black treeRed black tree
Red black tree
 
Red Black Trees
Red Black TreesRed Black Trees
Red Black Trees
 
Avl trees
Avl treesAvl trees
Avl trees
 
Tree traversal techniques
Tree traversal techniquesTree traversal techniques
Tree traversal techniques
 
Red black trees presentation
Red black trees presentationRed black trees presentation
Red black trees presentation
 
Avl trees final
Avl trees finalAvl trees final
Avl trees final
 
1.7 avl tree
1.7 avl tree 1.7 avl tree
1.7 avl tree
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
 
Trees data structure
Trees data structureTrees data structure
Trees data structure
 
Lecture notes data structures tree
Lecture notes data structures   treeLecture notes data structures   tree
Lecture notes data structures tree
 
AVL Tree
AVL TreeAVL Tree
AVL Tree
 
AVL Tree in Data Structure
AVL Tree in Data Structure AVL Tree in Data Structure
AVL Tree in Data Structure
 
Chapter 5 Syntax Directed Translation
Chapter 5   Syntax Directed TranslationChapter 5   Syntax Directed Translation
Chapter 5 Syntax Directed Translation
 
Linked list implementation of Queue
Linked list implementation of QueueLinked list implementation of Queue
Linked list implementation of Queue
 
Data Structure (Tree)
Data Structure (Tree)Data Structure (Tree)
Data Structure (Tree)
 
Huffman's algorithm in Data Structure
 Huffman's algorithm in Data Structure Huffman's algorithm in Data Structure
Huffman's algorithm in Data Structure
 
Tree in data structure
Tree in data structureTree in data structure
Tree in data structure
 
Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures
 

Similar to Red black tree in data structure

redblacktreeindatastructure-200409083949.pptx
redblacktreeindatastructure-200409083949.pptxredblacktreeindatastructure-200409083949.pptx
redblacktreeindatastructure-200409083949.pptxRAtna29
 
Red black tree insertion
Red black tree insertionRed black tree insertion
Red black tree insertionKousalya M
 
lecture 14
lecture 14lecture 14
lecture 14sajinsc
 
Red Black Tree,Red black tree, Cases-insertion, Deletion
Red Black Tree,Red black tree, Cases-insertion, DeletionRed Black Tree,Red black tree, Cases-insertion, Deletion
Red Black Tree,Red black tree, Cases-insertion, Deletiona123007
 
Unit 2 ADvanced Data Sturctures and Algorithms Red-black_trees.ppt
Unit 2 ADvanced Data Sturctures and Algorithms Red-black_trees.pptUnit 2 ADvanced Data Sturctures and Algorithms Red-black_trees.ppt
Unit 2 ADvanced Data Sturctures and Algorithms Red-black_trees.pptSheba41
 
Red black trees and their properties
Red black trees and their propertiesRed black trees and their properties
Red black trees and their propertiesKousalya M
 
Red black tree
Red black treeRed black tree
Red black treevinitha96
 
Trees in data structure
Trees in data structureTrees in data structure
Trees in data structureAnusruti Mitra
 
anastasio-red-black-trees-1-1-091222204455-phpapp02.pdf
anastasio-red-black-trees-1-1-091222204455-phpapp02.pdfanastasio-red-black-trees-1-1-091222204455-phpapp02.pdf
anastasio-red-black-trees-1-1-091222204455-phpapp02.pdfAayushAdhikari27
 

Similar to Red black tree in data structure (20)

redblacktreeindatastructure-200409083949.pptx
redblacktreeindatastructure-200409083949.pptxredblacktreeindatastructure-200409083949.pptx
redblacktreeindatastructure-200409083949.pptx
 
Red black tree
Red black treeRed black tree
Red black tree
 
Red black tree insertion
Red black tree insertionRed black tree insertion
Red black tree insertion
 
lecture 14
lecture 14lecture 14
lecture 14
 
Red Black Tree,Red black tree, Cases-insertion, Deletion
Red Black Tree,Red black tree, Cases-insertion, DeletionRed Black Tree,Red black tree, Cases-insertion, Deletion
Red Black Tree,Red black tree, Cases-insertion, Deletion
 
Unit 2 ADvanced Data Sturctures and Algorithms Red-black_trees.ppt
Unit 2 ADvanced Data Sturctures and Algorithms Red-black_trees.pptUnit 2 ADvanced Data Sturctures and Algorithms Red-black_trees.ppt
Unit 2 ADvanced Data Sturctures and Algorithms Red-black_trees.ppt
 
6_1 (1).ppt
6_1 (1).ppt6_1 (1).ppt
6_1 (1).ppt
 
Red black trees1109
Red black trees1109Red black trees1109
Red black trees1109
 
Red black trees and their properties
Red black trees and their propertiesRed black trees and their properties
Red black trees and their properties
 
Red black trees
Red black treesRed black trees
Red black trees
 
Lec14
Lec14Lec14
Lec14
 
Red black tree
Red black treeRed black tree
Red black tree
 
LEC 5-DS ALGO(updated).pdf
LEC 5-DS  ALGO(updated).pdfLEC 5-DS  ALGO(updated).pdf
LEC 5-DS ALGO(updated).pdf
 
Trees in data structure
Trees in data structureTrees in data structure
Trees in data structure
 
Red Black Trees
Red Black TreesRed Black Trees
Red Black Trees
 
Trees
TreesTrees
Trees
 
Tree
TreeTree
Tree
 
anastasio-red-black-trees-1-1-091222204455-phpapp02.pdf
anastasio-red-black-trees-1-1-091222204455-phpapp02.pdfanastasio-red-black-trees-1-1-091222204455-phpapp02.pdf
anastasio-red-black-trees-1-1-091222204455-phpapp02.pdf
 
Red black tree
Red black treeRed black tree
Red black tree
 
Red blacktrees
Red blacktreesRed blacktrees
Red blacktrees
 

Recently uploaded

ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 

Recently uploaded (20)

★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 

Red black tree in data structure

  • 1. Data Structure & Files Unit 5: Advance Tree Red Black Binary Tree Ms. Vrushali Dhanokar (M.Tech CSE) Assistant Professor IT Department dhanokarvrushali@gmail.com
  • 2. Why & What is mean by Red-Black Tree? • Red-Black Tree is a self-balancing Binary Search Tree (BST). • Every node is colored with Red or Black. Why Red Black Tree? • Most of the BST operations (e.g., search, max, min, insert, delete.. etc) take O(h) time where h is the height of the BST. The cost of these operations is high. • The height of a Red-Black tree is always O(Log n) where n is the number of nodes in the tree.
  • 3. Properties of Red Black Tree 1. Every node has a color either Red or Black. 2. Root of tree is always Black. 3. Leaf node or NULL node always Red. 4. Children's of Red Node are Black, Parent of Red Node is Black. 5. Every path from a node (including root) to any of its descendant NULL node has the same number of Black nodes. Every Red Black Tree is a binary search tree but every Binary Search Tree need not be Red Black tree.
  • 4. Insertion in Red-Black Tree: (Conditions) 1. Tree is empty – Add root node with color Black. 2. Tree is not empty – Add new node with color Red. 3. If parent of newnode is Black then exit. 4. If parent of newnode is Red then check the color of parent’s siblings of new node- a. If parent of sibling is Black or NULL then perform suitable Rotation & Recolor. b. If parent of sibling is Red then Recolor and also check if parents parent of newnode is not root node then Recolor it and Check it
  • 5. Rotation Means? Rotations: L-Left & R-Right • It occurs on only newnode and There Parent’s Node. 1. LR Relationship – 1. Left Rotation 2. Right Rotation 2. RL Relationship – 1. Right Rotation 2. Left Rotation It occurs on newnode , there Parent’s Node and also there Parent’s node. 1. LL Relationship – 1. Right Rotation 2. RR Relationship – 1. Left Rotation
  • 6. Insertion Examples (Add data according BST property) 1. Tree is empty – Add root node with color Black. 2. Tree is not empty – Add new node with color Red. 3. If parent of newnode is Black then exit. 4. If parent of newnode is Red then check the color of parent’s siblings of new node- a. If parent of sibling is Black or NULL then perform suitable rotation & Recolor. b. If parent of sibling is Red then Recolor and also check if parents parent of newnode is not root node then Recolor it and Check it Create Red-Black Tree for 8,18,5,15,17,25,40 ,80.
  • 7. Continue.. 1. Tree is empty – Add root node with color Black. 2. Tree is not empty – Add new node with color Red. 3. If parent of newnode is Black then exit. 4. If parent of newnode is Red then check the color of parent’s siblings of new node- a. If parent of sibling is Black or NULL then perform suitable rotation & Recolor. b. If parent of sibling is Red then Recolor and also check if parents parent of newnode is not root node then Recolor it and Check it
  • 8. Continue.. 1. Tree is empty – Add root node with color Black. 2. Tree is not empty – Add new node with color Red. 3. If parent of newnode is Black then exit. 4. If parent of newnode is Red then check the color of parent’s siblings of new node- a. If parent of sibling is Black or NULL then perform suitable rotation & Recolor. b. If parent of sibling is Red then Recolor and also check if parents parent of newnode is not root node then Recolor it and Check it
  • 9. Continue..! 1. Tree is empty – Add root node with color Black. 2. Tree is not empty – Add new node with color Red. 3. If parent of newnode is Black then exit. 4. If parent of newnode is Red then check the color of parent’s siblings of new node- a. If parent of sibling is Black or NULL then perform suitable rotation & Recolor. b. If parent of sibling is Red then Recolor and also check if parents parent of newnode is not root node then Recolor it and Check it
  • 10. Continue..! 1. Tree is empty – Add root node with color Black. 2. Tree is not empty – Add new node with color Red. 3. If parent of newnode is Black then exit. 4. If parent of newnode is Red then check the color of parent’s siblings of new node- a. If parent of sibling is Black or NULL then perform suitable rotation & Recolor. b. If parent of sibling is Red then Recolor and also check if parents parent of newnode is not root node then Recolor it and Check it
  • 11. Continue..! 1. Tree is empty – Add root node with color Black. 2. Tree is not empty – Add new node with color Red. 3. If parent of newnode is Black then exit. 4. If parent of newnode is Red then check the color of parent’s siblings of new node- a. If parent of sibling is Black or NULL then perform suitable rotation & Recolor. b. If parent of sibling is Red then Recolor and also check if parents parent of newnode is not root node then Recolor it and Check it
  • 12. Applications of Red-Black Tree 1. Linux Kernal, For process scheduler or for keeping track of virtual memory segmentation segments for a process. 2. Used in map, multimap, multiset from C++ STL and java.util.TreeMap , java.util.TreeSet from Java. 3. They are use in K-mean clustering algorithm for reducing time complexity. 4. MySQL uses Red-Black Trees for indexes on tables. 5. Fast searching can be occur.
  • 13. Important Questions 1. Write a short note on Red-Black Tree? 6M 2. Explain Red-Black Tree in detail. 6M 3. Write properties of Red-Black Tree. 3M 4. Construct Red-Black Tree for given numbers: 10,18,7,15,16,20,25,40,60,21,70. 8M